Patch 4 in the glslang-elimination series. Completes the downsample subsystem: all four downsample pipeline build paths in src/core/gpu_hw_vulkan.cpp now use embedded SPIR-V. This patch is the first to plumb the common-knobs spec constant (RESOLUTION_SCALE at constant_id=0), establishing the project-wide pattern for the larger remaining utility shaders. Shaders converted by this patch: 1. AdaptiveDownsampleCompositeFragmentShader. The runtime-baked RESOLUTION_SCALE used to derive RCP_VRAM_SIZE = 1/(VRAM_SIZE) and a mip-level multiplier '(RESOLUTION_SCALE - 1)'. Both are now SPIR-V OpSpecConstantOp arithmetic chained from the constant_id=0 input; the driver folds them to literals at vkCreateGraphicsPipelines time once GPU_HW_Vulkan::m_resolution_scale is bound. Reads two textures at bindings 1 and 2 (matching ShaderGen's 'index + 1' convention for Vulkan). 2. BoxSampleDownsampleFragmentShader. Same RESOLUTION_SCALE spec constant, used three ways: in 'base_coords = gl_FragCoord * uvec2(RESOLUTION_SCALE, RESOLUTION_SCALE)' (OpSpecConstantComposite), in the inner loop bounds 'offset < RESOLUTION_SCALE', and in the final divisor 'color /= RESOLUTION_SCALE * RESOLUTION_SCALE' (OpSpecConstantOp IMul). Whether the loop unrolls is left to the driver; this matches the original runtime path's behaviour where GLSL frontend often unrolled the bound-as-literal version. At extreme RESOLUTION_SCALE=16 the inner body runs 256 times either way. GLSL constraint discovered (documented in the composite shader for future contributors): glslangValidator rejects spec-const-derived expressions at global 'const' scope - 'global const initializers must be constant'. The workaround is to compute the derived value inside main() as a regular vec2; the SPIR-V will then contain runtime ALU ops chained from the OpSpecConstant rather than the cleaner OpSpecConstantOp form, but the driver constant-folds either at specialisation time. Call site changes in src/core/gpu_hw_vulkan.cpp: - GetDownsampleCompositePassPipeline: switched to embedded blob with RESOLUTION_SCALE spec const. m_shadergen null-check dropped (it was only there for the glslang path). - GetDownsampleFirstPassPipeline (Box branch): switched to embedded blob with RESOLUTION_SCALE spec const. m_shadergen null-check that patch 3 had left inside this branch is now also removed - both branches of this function are fully pre-baked. The comment block at function entry is updated to reflect the new state. Cumulative state after this patch: - 9 of ~25-30 Bucket A variants converted. The entire downsample subsystem (4 pipelines: Adaptive first-pass, mid-pass, blur, composite, plus Box first-pass) is now glslang-free. - Spec constant infrastructure exercised on its second-stage use case: a numeric uint (RESOLUTION_SCALE) rather than a bool (FIRST_PASS from patch 3). Confirms the OpSpecConstant/OpSpecConstantOp paths through the SpecConstants helper work for both flavours. - Remaining Bucket A: VRAM read FS, VRAM update-depth FS (both trivial - just need MULTISAMPLES + possibly an MSAA-vs-not blob pair), VRAM copy FS (MSAA blob pair + RESOLUTION_SCALE + PGXP_DEPTH), VRAM write FS (SSBO vs uniform-buffer blob pair + RESOLUTION_SCALE), VRAM fill FS (RESOLUTION_SCALE + PGXP_DEPTH + WRAPPED + INTERLACED), Display FS (the multi-variant one). Smoke tests in the sandbox: - Both new .inc files reconstruct to SPIR-V that passes 'spirv-val --target-env vulkan1.0'. - spirv-dis on the composite FS confirms 'OpDecorate %RESOLUTION_SCALE SpecId 0' and 'OpSpecConstantOp %uint ISub %RESOLUTION_SCALE %uint_1' for the mip-level multiplier. - spirv-dis on the box-sample FS confirms 'OpDecorate %RESOLUTION_SCALE SpecId 0', 'OpSpecConstantComposite %v2uint' for the base_coords scaling, and 'OpSpecConstantOp %uint IMul' for the final divisor. - g++ -fsyntax-only on embedded_shaders.cpp against the real tree headers is clean. Smoke tests at user's end: - Cold-boot with shader cache nuked, downsample mode = Adaptive at several resolution scales (1x, 4x, 8x, ideally 16x). The composite pipeline now drives a spec-constant for RESOLUTION_SCALE; if the plumbing is wrong, the downsampled output will be either at the wrong scale (mip 0 used everywhere -> overly sharp) or at the maximum mip everywhere (overly blurry). Both modes should be visually unchanged from the patch-3 baseline. - Cold-boot with cache nuked, downsample mode = Box, same scales. Box-sample now also takes the spec constant; if mis-plumbed at scale > 1 the output will be all-black (loop runs 0 times if RESOLUTION_SCALE = 0 in SPIR-V) or wildly wrong colors (if the averaging divisor is wrong). - Toggle resolution scale at runtime (which triggers pipeline destroy + rebuild). Confirms the SpecConstants helper correctly re-specialises on each build with the new m_resolution_scale value. This is the test most likely to catch a 'spec value latched on first build and never updates' bug, if one exists.
43 lines
1.7 KiB
GLSL
43 lines
1.7 KiB
GLSL
// Pre-baked Vulkan source for
|
|
// GPU_HW_ShaderGen::GenerateAdaptiveDownsampleCompositeFragmentShader().
|
|
//
|
|
// Vulkan-only port. Originally "mipmap_resolve.glsl" from parallel-rsx.
|
|
// Reads the per-pixel mip-bias (single-channel) computed by the blur pass
|
|
// from samp1, picks a mip level on samp0 (the original color pyramid)
|
|
// scaled by (RESOLUTION_SCALE - 1), and writes the resolved color.
|
|
//
|
|
// Spec constant: RESOLUTION_SCALE at constant_id=0 per the project-wide
|
|
// convention (see Vulkan::SpecConstants header comment in builders.h).
|
|
// The PSX VRAM size is fixed at 1024x512; the *upscaled* VRAM size is
|
|
// VRAM_SIZE = (1024, 512) * RESOLUTION_SCALE, derived inside main() since
|
|
// GLSL forbids spec-const-derived expressions at global 'const' scope.
|
|
// The driver folds these to literals at vkCreateGraphicsPipelines time
|
|
// once the spec constant value is known.
|
|
//
|
|
// Descriptor binding offsets match ShaderGen::DeclareTexture for Vulkan:
|
|
// texture index N -> layout binding (N + 1). The pipeline-layout side
|
|
// (m_downsample_composite_descriptor_set_layout) declares bindings 1 and 2.
|
|
|
|
#version 450 core
|
|
|
|
layout(constant_id = 0) const uint RESOLUTION_SCALE = 1u;
|
|
|
|
layout(set = 0, binding = 1) uniform sampler2D samp0;
|
|
layout(set = 0, binding = 2) uniform sampler2D samp1;
|
|
|
|
layout(location = 0) in VertexData {
|
|
vec2 v_tex0;
|
|
};
|
|
|
|
layout(location = 0) out vec4 o_col0;
|
|
|
|
void main()
|
|
{
|
|
// RCP_VRAM_SIZE = 1.0 / float2(VRAM_WIDTH, VRAM_HEIGHT) / RESOLUTION_SCALE
|
|
vec2 rcp_vram_size = vec2(1.0 / 1024.0, 1.0 / 512.0) / float(RESOLUTION_SCALE);
|
|
vec2 uv = gl_FragCoord.xy * rcp_vram_size;
|
|
float bias = texture(samp1, uv).r;
|
|
float mip = float(RESOLUTION_SCALE - 1u) * bias;
|
|
vec3 color = textureLod(samp0, uv, mip).rgb;
|
|
o_col0 = vec4(color, 1.0);
|
|
}
|