diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index dbe4f38f..88bc58eb 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -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; } diff --git a/src/core/gpu_hw.h b/src/core/gpu_hw.h index dad76d6a..16ab7ae9 100644 --- a/src/core/gpu_hw.h +++ b/src/core/gpu_hw.h @@ -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 diff --git a/src/core/gpu_hw_shadergen.cpp b/src/core/gpu_hw_shadergen.cpp index 4ec8c61f..b1b07b22 100644 --- a/src/core/gpu_hw_shadergen.cpp +++ b/src/core/gpu_hw_shadergen.cpp @@ -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";