core: route RESOLUTION_SCALE through vram_write_ps cbuffer
Same refactor ase56d4d4applied to vram_write_ps. Adds `uint u_resolution_scale, uint u_pad0` to its cbuffer, routes RESOLUTION_SCALE / VRAM_SIZE / RCP_VRAM_SIZE through the cbuffer via WriteCBufferResolutionScaleAliases, switches WriteCommonFunctions to the cbuffer-aware path (true) instead of the legacy literal emission (false default). vram_write_ps body references both RESOLUTION_SCALE and VRAM_SIZE directly: uint2 coords = uint2(uint(v_pos.x) / RESOLUTION_SCALE, fixYCoord(uint(v_pos.y)) / RESOLUTION_SCALE); ... offset.x = (coords.x < u_base_coords.x) ? ((VRAM_SIZE.x / RESOLUTION_SCALE) - u_base_coords.x + coords.x) : (coords.x - u_base_coords.x); offset.y = (coords.y < u_base_coords.y) ? ((VRAM_SIZE.y / RESOLUTION_SCALE) - u_base_coords.y + coords.y) : (coords.y - u_base_coords.y); The #define aliases route both names to u_resolution_scale-based arithmetic, identical to what the literal-baked constants expanded to for any given m_resolution_scale. The shader body is unchanged. Variant axis dropped: vram_write_ps previously had PGXP_DEPTH (2) x use_ssbo (2) x m_resolution_scale (N) variants. After this commit it's 4 variants (PGXP_DEPTH x use_ssbo) regardless of the current resolution scale. Files: * gpu_hw_shadergen.cpp: GenerateVRAMWriteFragmentShader reordered so DeclareUniformBuffer runs before WriteCommonFunctions(ss, true). u_resolution_scale + u_pad0 appended to the cbuffer member list. WriteCBufferResolutionScaleAliases call inserted between the cbuffer and WriteCommonFunctions. * gpu_hw.h: VRAMWriteUBOData grows by 8 bytes (u_resolution_scale + u_pad0). 36 -> 44 bytes total. The HLSL/GLSL compiler rounds the cbuffer up to a multiple of 16 internally (48 bytes visible to the shader), but we only upload sizeof(struct) = 44 bytes via the runtime push - the shader never reads beyond u_resolution_scale at offset 36-39, so the trailing 4 bytes the GPU view sees but we don't push are never accessed. * gpu_hw.cpp: GetVRAMWriteUBOData populates the two new fields. m_resolution_scale into u_resolution_scale; 0 into u_pad0. Cross-backend compat: same as vram_copy_ps (e56d4d4). D3D11 / OpenGL upload via runtime sizeof; D3D12 / Vulkan use root / push constants and have MAX_PUSH_CONSTANTS_SIZE = 64 byte ceiling (44 fits with headroom). Shader-cache invalidation: vram_write_ps's source string changes on every backend - first boot after this lands re-compiles all 4 (PGXP x use_ssbo) variants once, subsequent boots hit the regenerated cache entries. Test: VRAM writes (which run on every game's framebuffer update path - so every frame in practice) render correctly at every resolution scale. The coords / offset math in the body is the heaviest user of RESOLUTION_SCALE / VRAM_SIZE across the non-batch shader family, so this is the strongest validation that the alias plumbing is correct. If u_resolution_scale weren't populated, dst_x / dst_y / offset computations would be wrong and games would render with VRAM offsets off by a factor of m_resolution_scale - visible immediately as garbled framebuffers. Next: vram_read_ps (RESOLUTION_SCALE in the box-filter loop bounds) and display_ps (RESOLUTION_SCALE for chroma sampling coords + the box-filter downsampling on 24-bit modes). After those, the only remaining non-batch shader using compile-time- baked RESOLUTION_SCALE will be the adaptive_downsample family, which is a separate concern.
This commit is contained in:
parent
e56d4d4f7b
commit
9d2b49d226
3 changed files with 30 additions and 3 deletions
|
|
@ -1095,7 +1095,13 @@ GPU_HW::VRAMWriteUBOData GPU_HW::GetVRAMWriteUBOData(uint32_t x, uint32_t y, uin
|
|||
{
|
||||
const VRAMWriteUBOData uniforms = {
|
||||
(x % VRAM_WIDTH), (y % VRAM_HEIGHT), ((x + width) % VRAM_WIDTH), ((y + height) % VRAM_HEIGHT), width,
|
||||
height, buffer_offset, (set_mask) ? 0x8000u : 0x00, GetCurrentNormalizedVertexDepth()};
|
||||
height, buffer_offset, (set_mask) ? 0x8000u : 0x00, GetCurrentNormalizedVertexDepth(),
|
||||
// Cbuffer-routed RESOLUTION_SCALE - see GenerateVRAMWriteFragmentShader
|
||||
// for the alias plumbing. The body uses RESOLUTION_SCALE +
|
||||
// VRAM_SIZE which now derive from u_resolution_scale at runtime
|
||||
// instead of being baked at shadergen time.
|
||||
m_resolution_scale,
|
||||
0u /* u_pad0 */};
|
||||
return uniforms;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -153,6 +153,15 @@ protected:
|
|||
uint32_t u_buffer_base_offset;
|
||||
uint32_t u_mask_or_bits;
|
||||
float u_depth_value;
|
||||
// Appended for the cbuffer-routed RESOLUTION_SCALE refactor.
|
||||
// Matches the trailing "uint u_resolution_scale, uint u_pad0"
|
||||
// members on the HLSL side in GenerateVRAMWriteFragmentShader.
|
||||
// u_pad0 brings total to 44 bytes (the HLSL compiler rounds the
|
||||
// cbuffer up to the next 16-byte multiple internally, but we
|
||||
// upload exactly sizeof(struct) bytes on every backend and the
|
||||
// shader never reads beyond u_resolution_scale).
|
||||
uint32_t u_resolution_scale;
|
||||
uint32_t u_pad0;
|
||||
};
|
||||
|
||||
struct VRAMCopyUBOData
|
||||
|
|
|
|||
|
|
@ -1253,13 +1253,25 @@ std::string GPU_HW_ShaderGen::GenerateVRAMWriteFragmentShader(bool use_ssbo)
|
|||
{
|
||||
std::stringstream ss;
|
||||
WriteHeader(ss);
|
||||
WriteCommonFunctions(ss);
|
||||
DefineMacro(ss, "PGXP_DEPTH", m_pgxp_depth);
|
||||
|
||||
// u_resolution_scale appended; u_pad0 keeps the cbuffer 16-byte-
|
||||
// aligned. VRAMWriteUBOData in gpu_hw.h must match this layout.
|
||||
DeclareUniformBuffer(ss,
|
||||
{"uint2 u_base_coords", "uint2 u_end_coords", "uint2 u_size", "uint u_buffer_base_offset",
|
||||
"uint u_mask_or_bits", "float u_depth_value"},
|
||||
"uint u_mask_or_bits", "float u_depth_value", "uint u_resolution_scale", "uint u_pad0"},
|
||||
true);
|
||||
|
||||
// Route RESOLUTION_SCALE / VRAM_SIZE / RCP_VRAM_SIZE through the
|
||||
// cbuffer above. Same pattern as vram_copy_ps - the body references
|
||||
// to RESOLUTION_SCALE / VRAM_SIZE at lines 1304-1305 below resolve
|
||||
// through the #define aliases. This removes the scale axis from
|
||||
// vram_write_ps's variant matrix; what remains is PGXP_DEPTH x
|
||||
// use_ssbo = 4 variants, down from 4 x N where N is the count of
|
||||
// distinct resolution scale values the user has cycled through.
|
||||
WriteCBufferResolutionScaleAliases(ss);
|
||||
WriteCommonFunctions(ss, true);
|
||||
|
||||
if (use_ssbo && m_glsl)
|
||||
{
|
||||
ss << "layout(std430";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue