From b88439e2e00cf2dd22f3da635c080a7e1239ffbf Mon Sep 17 00:00:00 2001 From: Chris Toph Date: Mon, 9 Nov 2026 19:47:37 -0500 Subject: [PATCH] Reflect every location in vertex and fragment interface arrays. --- docs/maxwell.md | 7 +++++-- runtime/gfx_shader.c | 36 +++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/docs/maxwell.md b/docs/maxwell.md index 830770e5..ba9f1814 100644 --- a/docs/maxwell.md +++ b/docs/maxwell.md @@ -115,8 +115,11 @@ Grep-level look on 2026-10-22, statuses updated 2026-10-26; "saw" is what the gr `provokingVertexLast` and chains `VkPipelineRasterizationProvokingVertexStateCreateInfoEXT{LAST_VERTEX}` in `create_graphics`; without the feature it logs that flat outputs come from the first vertex. **Fixed.** 2. **Unwritten vertex outputs.** `spirv_add_outputs` (`vk_pipeline.c`) adds outputs initialised to (0, 0, 0, 1) for - FS inputs the VS lacks. Our translator never links stages, so its `InitializeVertexOutputs` would initialise - no user output; translator patch 0006 initialises the unlinked outputs. **Fixed.** + FS inputs the VS lacks. `gfx_shader.c` reflects the full declared location span of VS output and FS input arrays, + not just their base location: an FS `vec4[16]` requires all 16 locations even when it only accesses some elements. + The same reflected mask feeds recorded-pipeline prewarm, independent stage-library unions and direct pipeline builds. + Our translator never links stages, so its `InitializeVertexOutputs` would initialise no user output; + translator patch 0006 initialises the unlinked outputs. **Implemented; array-span runtime validation pending.** 3. **Masked clears.** `vk_exec.c` skips colour clears with a partial channel mask (`W_CLEAR_MASK`); `clear_ds` skips stencil clears with a partial mask (`W_STENCIL_MASK`). NX2navi issues such clears. Check the log for `colour clear with channel mask` and `stencil clear with mask`. The hardware recipe (1.3) shows what the replay must do: colour clear = scissor 0 + channel mask, stencil clear = `value & mask` merged under the front write mask; so a draw with `colorWriteMask` / `stencilWriteMask` set to the clear mask is the exact equivalent. **Missing.** diff --git a/runtime/gfx_shader.c b/runtime/gfx_shader.c index a0356a92..4eda40b8 100644 --- a/runtime/gfx_shader.c +++ b/runtime/gfx_shader.c @@ -952,7 +952,7 @@ static void add_res(GfxShader *s, int kind, const char *o, const char *e) { // SPIR-V opcodes and enumerants used below (SPIR-V 1.6 specification, section 3). enum { OP_ENTRY_POINT = 15, OP_EXECUTION_MODE = 16, OP_TYPE_INT = 21, OP_TYPE_FLOAT = 22, OP_TYPE_VECTOR = 23, - OP_TYPE_ARRAY = 28, OP_TYPE_POINTER = 32, OP_VARIABLE = 59, OP_DECORATE = 71, + OP_TYPE_ARRAY = 28, OP_TYPE_POINTER = 32, OP_CONSTANT = 43, OP_VARIABLE = 59, OP_DECORATE = 71, DEC_BUILTIN = 11, DEC_LOCATION = 30, DEC_COMPONENT = 31, SC_INPUT = 1, SC_OUTPUT = 3, EM_LOCAL_SIZE = 17 }; // Interface Locations and the compute workgroup size from the module. Ids beyond 2^20 are ignored (translated modules stay @@ -963,11 +963,11 @@ static void reflect_spirv(GfxShader *s) { s->local[0] = s->local[1] = s->local[2] = 1; if (n < 5) return; uint32_t bound = w[3] < (1u << 20) ? w[3] : (1u << 20); - // per id: location + 1 (0 = none), component flag, scalar/vector description of types, pointee of pointers + // per id: location + 1 (0 = none), component flag, scalar/vector type and array span, pointer target, constant value int32_t *loc = calloc(bound, sizeof *loc); - uint8_t *packed = calloc(bound, 1), *ttype = calloc(bound, 1), *tcomps = calloc(bound, 1); - uint32_t *pointee = calloc(bound, sizeof *pointee); - if (!loc || !packed || !ttype || !tcomps || !pointee) goto out; + uint8_t *packed = calloc(bound, 1), *ttype = calloc(bound, 1), *tcomps = calloc(bound, 1), *tlocs = calloc(bound, 1); + uint32_t *pointee = calloc(bound, sizeof *pointee), *value = calloc(bound, sizeof *value); + if (!loc || !packed || !ttype || !tcomps || !tlocs || !pointee || !value) goto out; for (uint64_t i = 5; i < n;) { uint32_t op = w[i] & 0xffff, len = w[i] >> 16; if (!len || i + len > n) break; @@ -979,13 +979,17 @@ static void reflect_spirv(GfxShader *s) { if (a[1] == DEC_LOCATION) loc[id] = (int32_t)a[2] + 1; else if (a[1] == DEC_COMPONENT) packed[id] = 1; } else if (op == OP_TYPE_INT && len >= 4 && id < bound) { - ttype[id] = a[2] ? GFX_TYPE_SINT : GFX_TYPE_UINT, tcomps[id] = 1; + ttype[id] = a[2] ? GFX_TYPE_SINT : GFX_TYPE_UINT, tcomps[id] = 1, tlocs[id] = 1; } else if (op == OP_TYPE_FLOAT && len >= 3 && id < bound) { - ttype[id] = GFX_TYPE_FLOAT, tcomps[id] = 1; + ttype[id] = GFX_TYPE_FLOAT, tcomps[id] = 1, tlocs[id] = 1; } else if (op == OP_TYPE_VECTOR && len >= 4 && id < bound && a[1] < bound) { - ttype[id] = ttype[a[1]], tcomps[id] = (uint8_t)a[2]; - } else if (op == OP_TYPE_ARRAY && len >= 4 && id < bound && a[1] < bound) { - ttype[id] = ttype[a[1]], tcomps[id] = tcomps[a[1]]; // element type (arrayed interface blocks) + ttype[id] = ttype[a[1]], tcomps[id] = (uint8_t)a[2], tlocs[id] = 1; + } else if (op == OP_CONSTANT && len == 4 && a[1] < bound) { + value[a[1]] = a[2]; + } else if (op == OP_TYPE_ARRAY && len >= 4 && id < bound && a[1] < bound && a[2] < bound) { + ttype[id] = ttype[a[1]], tcomps[id] = tcomps[a[1]]; + uint64_t slots = (uint64_t)tlocs[a[1]] * value[a[2]]; + tlocs[id] = (uint8_t)(slots < 32 ? slots : 32); // the interface masks cover 32 locations } else if (op == OP_TYPE_POINTER && len >= 4 && id < bound) { pointee[id] = a[2]; } else if (op == OP_VARIABLE && len >= 4) { @@ -994,14 +998,20 @@ static void reflect_spirv(GfxShader *s) { int l = loc[var] - 1; uint32_t t = pointee[type] < bound ? pointee[type] : 0; GfxShaderIo io = {ttype[t], tcomps[t] ? tcomps[t] : 4, packed[var]}; - if (sc == SC_INPUT) s->in_mask |= 1u << l, s->in[l] = io; - else s->out_mask |= 1u << l, s->out[l] = io; + // VS -> FS arrays occupy every element's locations, even if only some elements are accessed. + // Other stages retain their existing reflection: mesh outputs have an outer per-vertex array. + uint32_t slots = ((s->stage == GFX_STAGE_VS && sc == SC_OUTPUT) || + (s->stage == GFX_STAGE_FS && sc == SC_INPUT)) && tlocs[t] ? tlocs[t] : 1; + for (uint32_t j = 0; j < slots && l + j < 32; j++) { + if (sc == SC_INPUT) s->in_mask |= 1u << (l + j), s->in[l + j] = io; + else s->out_mask |= 1u << (l + j), s->out[l + j] = io; + } } } i += len; } out: - free(loc), free(packed), free(ttype), free(tcomps), free(pointee); + free(loc), free(packed), free(ttype), free(tcomps), free(tlocs), free(pointee), free(value); } // Every gradient sample (OpImageSampleExplicitLod with Grad) whose two gradients are each built from two components gets