diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index 13e1b1f5..dbe4f38f 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -1121,7 +1121,12 @@ GPU_HW::VRAMCopyUBOData GPU_HW::GetVRAMCopyUBOData(uint32_t src_x, uint32_t src_ width * m_resolution_scale, height * m_resolution_scale, m_GPUSTAT.set_mask_while_drawing ? 1u : 0u, - GetCurrentNormalizedVertexDepth()}; + GetCurrentNormalizedVertexDepth(), + // Cbuffer-routed RESOLUTION_SCALE - the shader's VRAM_SIZE / RCP_VRAM_SIZE + // aliases now derive from this field instead of having m_resolution_scale + // baked compile-time. See GenerateVRAMCopyFragmentShader. + m_resolution_scale, + 0u /* u_pad0 */}; return uniforms; } diff --git a/src/core/gpu_hw.h b/src/core/gpu_hw.h index ee1c727a..dad76d6a 100644 --- a/src/core/gpu_hw.h +++ b/src/core/gpu_hw.h @@ -167,6 +167,15 @@ protected: uint32_t u_height; uint32_t u_set_mask_bit; float u_depth_value; + // Appended for the cbuffer-routed RESOLUTION_SCALE refactor (this + // commit). Matches the trailing "uint u_resolution_scale, uint u_pad0" + // members on the HLSL side in GenerateVRAMCopyFragmentShader - + // u_pad0 keeps the cbuffer 16-byte-aligned (HLSL cbuffers pack to + // 16-byte rows; after u_depth_value at offset 36, adding one uint + // would end at offset 40, but the row ends at 48 so we pad to + // bring the total to 48 bytes). + uint32_t u_resolution_scale; + uint32_t u_pad0; }; class ShaderCompileProgressTracker diff --git a/src/core/gpu_hw_shadergen.cpp b/src/core/gpu_hw_shadergen.cpp index 0b4a0f02..4ec8c61f 100644 --- a/src/core/gpu_hw_shadergen.cpp +++ b/src/core/gpu_hw_shadergen.cpp @@ -93,6 +93,21 @@ void GPU_HW_ShaderGen::WriteBatchUniformBuffer(std::stringstream& ss) // the preprocessor just substitutes them with arithmetic over // u_resolution_scale. VRAM_WIDTH / VRAM_HEIGHT stay compile-time // literals because they are fixed PSX geometry, not session state. + WriteCBufferResolutionScaleAliases(ss); +} + +void GPU_HW_ShaderGen::WriteCBufferResolutionScaleAliases(std::stringstream& ss) +{ + // The caller has already declared a cbuffer that contains + // `uint u_resolution_scale` (either the batch UBO via + // WriteBatchUniformBuffer, or a per-shader UBO that grew the field + // as part of the non-batch cbuffer-routing refactor). All we do + // here is alias the legacy compile-time constants to the cbuffer + // field so existing shader bodies that reference RESOLUTION_SCALE / + // VRAM_SIZE / RCP_VRAM_SIZE keep compiling. The arithmetic over + // u_resolution_scale happens once per shader invocation - HLSL / + // GLSL fold the constant-folding-friendly bits (the VRAM_WIDTH / + // VRAM_HEIGHT literals) at compile time. ss << "#define RESOLUTION_SCALE u_resolution_scale\n"; ss << "#define VRAM_SIZE (uint2(" << VRAM_WIDTH << "u, " << VRAM_HEIGHT << "u) * u_resolution_scale)\n"; ss << "#define RCP_VRAM_SIZE (float2(1.0, 1.0) / float2(VRAM_SIZE))\n"; @@ -1304,13 +1319,27 @@ std::string GPU_HW_ShaderGen::GenerateVRAMCopyFragmentShader() std::stringstream ss; WriteHeader(ss); - WriteCommonFunctions(ss); DefineMacro(ss, "PGXP_DEPTH", m_pgxp_depth); + + // u_resolution_scale is at the END of the cbuffer (after u_depth_value) + // so existing field offsets stay stable - the only change is a new + // 4-byte field appended. VRAMCopyUBOData in gpu_hw.h must match. DeclareUniformBuffer(ss, {"uint2 u_src_coords", "uint2 u_dst_coords", "uint2 u_end_coords", "uint2 u_size", - "bool u_set_mask_bit", "float u_depth_value"}, + "bool u_set_mask_bit", "float u_depth_value", "uint u_resolution_scale", "uint u_pad0"}, true); + // Route RESOLUTION_SCALE / VRAM_SIZE / RCP_VRAM_SIZE through + // u_resolution_scale in the cbuffer above instead of having + // m_resolution_scale baked compile-time via WriteCommonFunctions's + // CONSTANT-emit path. After this, a resolution-scale toggle no + // longer changes the HLSL source string - same source, same hash, + // same DXBC - which is what makes vram_copy_ps pre-bakeable in a + // follow-up patch (cuts the variant axis from PGXP x scale down + // to just PGXP). + WriteCBufferResolutionScaleAliases(ss); + WriteCommonFunctions(ss, true); + DeclareTexture(ss, "samp0", 0, msaa); DefineMacro(ss, "MSAA_COPY", msaa); DeclareFragmentEntryPoint(ss, 0, 1, {}, true, 1, true, false, false, msaa); diff --git a/src/core/gpu_hw_shadergen.h b/src/core/gpu_hw_shadergen.h index e10112f7..a450becd 100644 --- a/src/core/gpu_hw_shadergen.h +++ b/src/core/gpu_hw_shadergen.h @@ -32,6 +32,15 @@ private: void WriteCommonFunctions(std::stringstream& ss, bool batch_uniform_buffer = false); void WriteBatchUniformBuffer(std::stringstream& ss); + + // Emit the #define aliases that route RESOLUTION_SCALE / VRAM_SIZE / + // RCP_VRAM_SIZE through u_resolution_scale in the shader's currently- + // in-scope cbuffer. Used by both WriteBatchUniformBuffer (where the + // cbuffer is the batch UBO) and by non-batch shaders that have added + // u_resolution_scale to their own per-shader UBO. Must be called + // AFTER the cbuffer declaration so u_resolution_scale is in scope. + void WriteCBufferResolutionScaleAliases(std::stringstream& ss); + void WriteBatchTextureFilter(std::stringstream& ss, GPUTextureFilter texture_filter); uint32_t m_resolution_scale;