Completes the PGXP_DEPTH cbuffer-routing arc on the Vulkan
side. The batch VS used to declare PGXP_DEPTH as a
specialisation constant at constant_id = 3, switched via
vs_spec.AddBool(3, m_pgxp_depth_buffer) at pipeline build,
with the body using a `PGXP_DEPTH ? a_pos.w : a_pos.z` static
ternary on the spec const value. The C++ shadergen VS was
already routed in 49c0f82 and the Vulkan FS in the preceding
commit; this aligns the Vulkan VS with both.
Spec constants are not SPIR-V structural axes - one VS blob,
two VkPipelines per PGXP value (the spec const value is baked
in at vkCreateGraphicsPipelines time, producing two
specialised executables from the same module). So the
pre-routing footprint was small: zero extra .inc files, but
two PSO objects per VS variant rather than one, and a PSO
rebuild on m_pgxp_depth_buffer flip to swap them. Post-
routing, the VS becomes a single PSO across the flip (just a
4-byte UBO read picked up at next FlushRender).
What changes:
data/shaders/vulkan/batch.vert.glsl
- Drops `layout(constant_id = 3) const bool PGXP_DEPTH = false;`
- Adds a Batch UBO declaration at set=0 binding=0 with a
single `layout(offset = 52) uint u_pgxp_depth;` field.
Matches the std140 offset of the C++ BatchUBOData
member (gpu_hw.h:111). The pipeline layout
m_batch_pipeline_layout already exposes the UBO for
the FS - the VS just reads from the same descriptor.
- Body: `pos_z = PGXP_DEPTH ? a_pos.w : a_pos.z` ->
`pos_z = (u_pgxp_depth != 0u) ? a_pos.w : a_pos.z`
- Header docstring: drops the constant_id=3 section,
describes the routing.
src/common/vulkan/embedded_spirv/
- 12 batch_vs_*.inc files regenerated with the UBO read
+ uniform branch in place of the spec const ternary.
Each .inc grows ~100 SPIR-V words (UBO declaration,
load, branch). Total VS SPIR-V footprint grows by
~5 KiB across 12 blobs.
src/core/gpu_hw_vulkan.cpp
- Drops `vs_spec.AddBool(3, m_pgxp_depth_buffer);` from
the batch-pipeline build site. RESOLUTION_SCALE
(id=0) remains as a VS spec const.
What this completes:
PGXP_DEPTH is now fully routed end-to-end on both
pipeline-emission paths across all four backends:
D3D11 / D3D12 / OpenGL (C++ shadergen):
VS routed in 49c0f82 (u_pgxp_depth runtime ternary)
FS routed in 116a70e (always-emit SV_Depth + runtime
ternary in the consolidated end-of-main write)
Vulkan (pre-baked SPIR-V):
VS routed in this commit (u_pgxp_depth runtime
ternary, replacing the spec const)
FS routed in dae19ff (always-write gl_FragDepth +
runtime ternary; 120 -> 60 SPIR-V blobs across the
5 FS templates)
Cost matrix on PGXP toggle across the four backends is
now governed by the PSO depth comparison func dependency
only:
D3D11 / D3D12 / OpenGL: PSO depth-comp built in to the
PSO immutable state (gpu_hw_d3d12.cpp:1317-1319 picks
LESS_EQUAL vs GREATER_EQUAL on m_pgxp_depth_buffer at
PSO build time). Flipping PGXP still triggers a PSO
rebuild, but FS bytecode is cache-served (invariant
across the flip).
Vulkan: depth comparison func is selected per-draw via
the depth_test PSO matrix dim (depth_test=1 ->
GREATER_OR_EQUAL, depth_test=2 -> LESS_OR_EQUAL, see
gpu_hw_vulkan.cpp:2233). The C++ side chooses the
depth_test index based on m_pgxp_depth_buffer at draw
time without rebuild. Vulkan no longer needs ANY
shader / PSO rebuild on PGXP toggle.
m_pgxp_depth_buffer stays in shader_source_changed for
the C++ shadergen path's PSO rebuild requirement. A
Vulkan-aware cleanup that decouples Vulkan from this
trigger (since it no longer needs it) is a separate
follow-up; the current state is correct but wastes a
Vulkan pipeline cache lookup on flip.
Test:
- Build: tools/regen_vulkan_spirv.py runs cleanly. The
new VS reads the UBO; SPIR-V validation passes.
- Boot any title on Vulkan, PGXP-depth off: u_pgxp_depth
= 0, VS picks a_pos.z (mask-bit Z) path. Output
identical to pre-commit.
- Toggle PGXP-depth on: u_pgxp_depth flips to 1; VS
picks a_pos.w (PGXP-replayed depth) path on next draw.
No pipeline rebuild on the VS side, no PSO rebuild
overall on Vulkan (the depth_test index also switches
via the matrix). Output identical to pre-commit PGXP-
on state.
- PGXP-corrected geometry sanity (Tekken 3, Tomb Raider
1/2, Soul Blade): the runtime branch should produce
byte-identical depth values to the pre-routing spec-
const-baked variant.
Next:
- per_sample / dcp collapse decisions (forced-always
settings or keep as variant axes - these are
interpolation qualifiers that can't be cbuffer-routed,
only collapsed via settings).
- Pre-bake the resulting D3D12 FS matrix.
Follow-up to 8b43518 (UV_LIMITS routing for the C++ shadergen,
D3D11 / D3D12 / OpenGL only). Vulkan has its own pre-baked
SPIR-V pipeline rooted in data/shaders/vulkan/*.glsl, compiled
via tools/regen_vulkan_spirv.py, and indexed by per-axis blob
tables in src/common/vulkan/embedded_shaders.cpp. This commit
parallels the C++ shadergen routing on the VS side: collapses
the UV_LIMITS attribute-layout variant from the batch VS so
that "textured" always means "textured with v_uv_limits", and
the C++ Vulkan input layout binds ATTR4 unconditionally when
textured.
The FS-side UV_LIMITS axis (the Nearest filter's two-variant
nouv / uv expansion) is NOT in this commit. Routing it
through a UBO field requires extending the Vulkan batch FS
UBO declaration with u_uv_limits, body-level runtime
branches, and regenerating the 48 Nearest FS .inc blobs. That
is the natural next commit; this one limits the blast radius
to the VS side, which is a simpler structural change with
fewer downstream touch points.
What changes:
data/shaders/vulkan/batch.vert.glsl
- Drops the #if defined(UV_LIMITS) guards in three sites
(a_uv_limits input declaration, v_uv_limits varying
output declaration, v_uv_limits assignment in main()).
When TEXTURED, a_uv_limits / v_uv_limits are always
declared and v_uv_limits is always written.
- Header comment updated from "3 attribute layouts" to
"2 attribute layouts" and the total variant count from
18 to 12.
tools/regen_vulkan_spirv.py
- _batch_vs_variants(): drops the third attr_axes entry
("textured_uvlim", ["TEXTURED", "UV_LIMITS"]). The
remaining "textured" entry's GLSL output now always
includes the a_uv_limits / v_uv_limits declarations
because the source-side #if guards are gone, so the
single "textured" variant produces the same SPIR-V that
"textured_uvlim" used to. Variant count drops from 18
to 12.
- The Nearest FS variants table is unchanged (still has
the UV_LIMITS axis); collapsing that side is the
follow-up.
src/common/vulkan/embedded_spirv/
- Six batch_vs_textured_uvlim_*.inc files DELETED (no
longer in the regen output set).
- Six batch_vs_textured_*.inc files REGENERATED with the
new GLSL that always emits a_uv_limits / v_uv_limits.
Content shape: same length / structure as the old
"textured_uvlim" .inc files (since both correspond to
the "textured + UV_LIMITS" build); the OLD plain
"textured" .inc files (the smaller no-UV variant) are
effectively replaced.
- Other 169 blobs untouched. Total goes 181 -> 175.
src/common/vulkan/embedded_shaders.{h,cpp}
- k_batch_vs_blobs[18] -> k_batch_vs_blobs[12]. The
table loses the "attr = 1 (textured, no UV limits)"
block; the surviving "attr = 1" block is what used to
be "attr = 2 (textured + UV limits)", just renamed for
cleaner end state.
- GetBatchVertexShaderBlob() drops the bool uv_limits
parameter. Index encoding becomes
attr = textured ? 1 : 0 (was: !textured ? 0 :
(uv_limits ? 2 : 1))
Same interp / persp arithmetic.
- Header docstring and #include block updated to match
(six fewer #includes; the six uvlim ones).
src/core/gpu_hw_vulkan.cpp
- The single GetBatchVertexShaderBlob() call site at the
CompilePipelines VS-fill loop drops its second
argument (m_using_uv_limits) so the new four-arg
signature is satisfied.
- The input-layout builder at the per-pipeline
gpbuilder.AddVertexAttribute(4, ...) site drops its
`if (m_using_uv_limits)` guard. ATTR4 / a_uv_limits is
now bound unconditionally when textured, matching the
always-emitted shader input. BatchVertex carries the
uv_limits field unconditionally (gpu_hw.h:47), so the
binding always points at valid memory; the FS-side
u_uv_limits scalar still decides whether the value is
meaningful.
What does NOT change in this commit:
- The Vulkan batch FS Nearest variants still have
UV_LIMITS as a build axis. m_using_uv_limits is still
threaded to the FS blob lookup at
gpu_hw_vulkan.cpp:2139 (now line ~2140 after the diff).
The Nearest FS GLSL still has #if defined(UV_LIMITS)
guards. The 48 nearest_uv / nearest_nouv blobs remain.
Routing that side is the natural next commit; the
delta there is much larger (48 blobs, FS UBO grows,
runtime branch in the Nearest body).
- m_using_uv_limits STAYS in shader_source_changed across
backends. Vulkan still needs it to pick the right
Nearest FS blob, so the rebuild trigger has to stay
until the Nearest FS routing also lands.
- m_using_uv_limits STAYS as a member field. Still
drives the per-vertex ComputePolygonUVLimits decision
(gpu_hw.cpp:740) and still passed into the FS variant
lookup. The VS lookup no longer takes it.
- Bilinear / JINC2 / xBR FS templates: untouched. They
already assumed UV_LIMITS via the settings-layer
ShouldUseUVLimits() coupling (TEXTURE_FILTERING !=
Nearest implies m_using_uv_limits = true), so they
never had a UV_LIMITS variant axis to collapse.
Variant-count delta:
Batch VS: 18 -> 12 SPIR-V blobs. Pipeline cache footprint
drops by 6 VS pipelines per (filter, render, texture)
cell pair (filter side is per-FS so doesn't multiply VS
directly, but the VkPipeline cache key combines them and
6 fewer VS blobs mean 6 fewer paths through the
pipeline-create call).
Disk SPIR-V footprint:
Before: 181 .inc files, 13 MiB total.
After: 175 .inc files, 13 MiB - ~120 KiB = ~12.9 MiB.
(Six VS blobs at ~120 KiB each, ~2-2.5 KiB SPIR-V plus
the C-array boilerplate.)
Cost matrix delta (Vulkan):
UV_LIMITS flip mid-session (in practice triggered by PGXP
toggle or filter cross-Nearest transition, both of which
separately trigger m_using_uv_limits flips):
Pre-commit: VS pipeline-cache lookup picks a different
blob from the 18-entry table on flip.
Pipeline creation cost on cold cache:
~2 vkCreateGraphicsPipelines for the two
new (textured, textured_uvlim) VS variants
if both end up needed.
Post-commit: VS pipeline-cache lookup is invariant
under m_using_uv_limits at the VS axis;
the FS axis still flips. Saves ~2 cold VS
pipeline creates on the toggle. Symbolic
(small absolute cost) but it unlocks the
next Nearest-FS routing commit, which is
the actual large win on the Vulkan side.
Cold launch (precompile pass): 6 fewer VS pipelines to
enumerate / create. Probably tens of ms on cold cache.
Steady-state runtime cost: unchanged. The VS uniform
always-emits-v_uv_limits adds one MUL per vertex and one
vec4 of interpolant bandwidth, both sub-noise.
Test:
- Build: tools/regen_vulkan_spirv.py runs cleanly with
glslangValidator from the Vulkan SDK / glslang-tools
package, producing 175 blobs. The Vulkan backend builds
and links against the smaller blob table.
- Boot any PSX title with PGXP off + filter Nearest:
untextured / textured paths render identically. The
"textured" VS variant is now the always-UV blob;
BatchVertex.uv_limits is zero on these vertices (no
ComputePolygonUVLimits ran), v_uv_limits is propagated
as zero, and the Nearest FS (still UV_LIMITS-keyed in
this commit) picks its "nouv" variant.
- Toggle PGXP on or filter to Bilinear:
m_using_uv_limits flips to true, the Nearest FS picks
its "uv" variant, the VS variant is still the same
(post-commit there's only one textured VS variant).
Output identical to pre-commit equivalent state.
- Spec const flips (PGXP_DEPTH, RESOLUTION_SCALE) at
pipeline-create time: still produce the right pipeline
via the smaller blob table.
Next:
- Vulkan Nearest FS UV_LIMITS routing: extend Vulkan FS
UBO with u_uv_limits, drop the #if defined(UV_LIMITS)
guards from batch_textured_nearest.frag.glsl, runtime
branch in the body, regen 48 -> 24 Nearest FS blobs,
drop m_using_uv_limits from the FS lookup +
shader_source_changed. After that, all backends have
UV_LIMITS fully routed.
- PGXP_DEPTH for the FS (always-emit SV_Depth / FragDepth
perf measurement first).
- Pre-bake commits once remaining axes are decided.
Patch 12 in the glslang-elimination series, and the first step into
Bucket B (batch shaders). The batch VS state space has three SPIR-V-
structurally-distinct axes that specialisation constants cannot fold:
1. Vertex attribute layout. 2 inputs (untextured), 4 (textured
without UV limits) or 5 (textured with UV limits). The 'in <type>
<name>' declarations are part of the SPIR-V module interface.
2. Output interpolation qualifier on the v_col0 / v_tex0 outputs.
None / centroid / sample, selected per session by UsingMSAA() /
UsingPerSampleShading(). These compile to OpMemberDecorate
Centroid / Sample on the VertexData output block, which is not
a spec-constant-controllable property of the SPIR-V module.
3. Color output perspective. m_disable_color_perspective toggles a
'noperspective' qualifier on v_col0, compiling to
OpMemberDecorate NoPerspective.
3 x 3 x 2 = 18 structurally distinct blobs. Body-level knobs
(RESOLUTION_SCALE, PGXP_DEPTH) are common-knob specialisation
constants on every blob (constant_id = 0 and 3 per the project
convention).
To avoid maintaining 18 hand-edited .glsl files, the source is a
single template (data/shaders/vulkan/batch.vert.glsl) with #if
guards on TEXTURED, UV_LIMITS, INTERP_CENTROID / INTERP_SAMPLE, and
NOPERSP. The regen tool (tools/regen_vulkan_spirv.py) is extended
with a TEMPLATE_VARIANTS manifest that compiles the template once
per variant with the corresponding -D flags. Build-time impact is
zero - the script is still developer-only and the .inc files are
checked in.
The matching index encoding lives in src/common/vulkan/embedded_-
shaders.cpp next to the lookup helper:
attr = !textured ? 0 : (uv_limits ? 2 : 1) (0..2)
interp = per_sample_shading ? 2 : (msaa ? 1 : 0) (0..2)
persp = noperspective_color ? 1 : 0 (0..1)
index = attr * 6 + interp * 2 + persp (0..17)
The C++ side calls GetBatchVertexShaderBlob with the per-session
state (m_using_uv_limits, m_multisamples > 1, m_per_sample_shading,
m_disable_color_perspective) and the per-call 'textured' loop
variable to pick the right blob in CompilePipelines. The existing
m_batch_vertex_shaders[2] cache shape is preserved - the helper just
selects which two of the 18 blobs to instantiate this session.
Spec constants are applied at PIPELINE-create time inside
GetBatchPipeline rather than at module-create time, matching the
SpecConstants infrastructure laid down in patch 3. The values are
session-constant, so they are the same for every batch pipeline in
a session and the driver caches them keyed by (module + spec values)
in the pipeline cache.
Header-side ergonomics: instead of declaring 36 individual extern
arrays (18 SPIR-V + 18 size), the .h declares a small
EmbeddedShaderBlob struct and a single
k_batch_vs_blobs[18] array, plus the GetBatchVertexShaderBlob
helper. The same struct is intended to be reused for the eventual
batch FS conversion (likely many more blobs given the texture filter
state space).
Smoke tests:
- g++ -fsyntax-only on the touched common TU.
- spirv-val --target-env vulkan1.0 on all 18 blobs - 18/18 valid.
- Total .inc size: ~53 KiB across all 18 blobs.
- --target-env vulkan1.0 vs un-flagged glslangValidator: byte-
identical for every variant.
The batch VS is filled in CompilePipelines for all three precompile
modes (Enabled, Lazy, Disabled), so this conversion does not change
the hot-path-pre-build pattern from the patch 10-fix. The two VS
modules are present before any batch draw on every code path.
Test priority:
- Routine smoke under Enabled / Lazy / Disabled. Any rendering at
all exercises both VS modules immediately, so visual regressions
show up on the first frame of the first game booted.
- SSAA / MSAA round-trip in Disabled mode (per the patch-5-fix
protocol), specifically to confirm the structural-blob-pick
flips through 'none' -> 'centroid' -> 'sample' interp variants
cleanly as m_multisamples changes.
- Toggle 'disable color perspective' core option (under Texture
Correction) to flip the perspective axis; visual difference is
subtle but the blob-pick change is real.
- Toggle PGXP Geometry Correction (drives UV_LIMITS via
m_using_uv_limits) and PGXP Depth Buffer (drives PGXP_DEPTH
spec const) to flip the body and attribute-layout axes.
After this lands, the only remaining runtime glslang consumer in
the Vulkan backend is the batch FS (GenerateBatchFragmentShader at
gpu_hw_shadergen.cpp line ~667). That is a far larger state space
- six texture filters x ~14 boolean macros plus the structural
USE_DUAL_SOURCE / PALETTE_* axes - and will need to land in
several patches, one or two texture filters at a time.