diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.cpp b/rpcs3/Emu/RSX/GL/GLGSRender.cpp index 0f2e2f4c25..350228b41f 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.cpp +++ b/rpcs3/Emu/RSX/GL/GLGSRender.cpp @@ -193,17 +193,12 @@ void GLGSRender::begin() float range_near = rsx::method_registers.clip_min(); float range_far = rsx::method_registers.clip_max(); - if (g_cfg.video.strict_rendering_mode) - gl_state.depth_range(range_near, range_far); + //Workaround to preserve depth precision but respect z direction + //Ni no Kuni sets a very restricted z range (0.9x - 1.) and depth reads / tests are broken + if (range_near <= range_far) + gl_state.depth_range(0.f, 1.f); else - { - //Workaround to preserve depth precision but respect z direction - //Ni no Kuni sets a very restricted z range (0.9x - 1.) and depth reads / tests are broken - if (range_near <= range_far) - gl_state.depth_range(0.f, 1.f); - else - gl_state.depth_range(1.f, 0.f); - } + gl_state.depth_range(1.f, 0.f); } if (glDepthBoundsEXT && (gl_state.enable(rsx::method_registers.depth_bounds_test_enabled(), GL_DEPTH_BOUNDS_TEST_EXT))) diff --git a/rpcs3/Emu/RSX/GL/GLTextureCache.h b/rpcs3/Emu/RSX/GL/GLTextureCache.h index 39a7f6fea5..b910b031e9 100644 --- a/rpcs3/Emu/RSX/GL/GLTextureCache.h +++ b/rpcs3/Emu/RSX/GL/GLTextureCache.h @@ -193,7 +193,7 @@ namespace gl void reset(const u32 base, const u32 size, const bool flushable=false) { - rsx::protection_policy policy = g_cfg.video.strict_rendering_mode ? rsx::protection_policy::protect_policy_full_range : rsx::protection_policy::protect_policy_one_page; + rsx::protection_policy policy = g_cfg.video.strict_rendering_mode ? rsx::protection_policy::protect_policy_full_range : rsx::protection_policy::protect_policy_conservative; rsx::buffered_section::reset(base, size, policy); if (flushable) diff --git a/rpcs3/Emu/RSX/VK/VKTextureCache.h b/rpcs3/Emu/RSX/VK/VKTextureCache.h index 2c2ff4b221..9d1fad1c67 100644 --- a/rpcs3/Emu/RSX/VK/VKTextureCache.h +++ b/rpcs3/Emu/RSX/VK/VKTextureCache.h @@ -35,7 +35,7 @@ namespace vk if (length > cpu_address_range) release_dma_resources(); - rsx::protection_policy policy = g_cfg.video.strict_rendering_mode ? rsx::protection_policy::protect_policy_full_range : rsx::protection_policy::protect_policy_one_page; + rsx::protection_policy policy = g_cfg.video.strict_rendering_mode ? rsx::protection_policy::protect_policy_full_range : rsx::protection_policy::protect_policy_conservative; rsx::buffered_section::reset(base, length, policy); } diff --git a/rpcs3/Emu/RSX/rsx_cache.h b/rpcs3/Emu/RSX/rsx_cache.h index 51af8ddb06..d7845704fa 100644 --- a/rpcs3/Emu/RSX/rsx_cache.h +++ b/rpcs3/Emu/RSX/rsx_cache.h @@ -53,6 +53,7 @@ namespace rsx enum protection_policy { protect_policy_one_page, //Only guard one page, preferrably one where this section 'wholly' fits + protect_policy_conservative, //Guards as much memory as possible that is guaranteed to only be covered by the defined range without sharing protect_policy_full_range //Guard the full memory range. Shared pages may be invalidated by access outside the object we're guarding }; @@ -90,18 +91,23 @@ namespace rsx locked_address_base = (base & ~4095); - if (protect_policy == protect_policy_one_page) + if ((protect_policy != protect_policy_full_range) && (length >= 4096)) { + const u32 limit = base + length; + const u32 block_end = (limit & ~4095); + const u32 block_start = (locked_address_base < base) ? (locked_address_base + 4096) : locked_address_base; + locked_address_range = 4096; - if (locked_address_base < base) + + if (block_start < block_end) { - //Try the next page if we can - //TODO: If an object spans a boundary without filling either side, guard the larger page occupancy - const u32 next_page = locked_address_base + 4096; - if ((base + length) >= (next_page + 4096)) + //Page boundaries cover at least one unique page + locked_address_base = block_start; + + if (protect_policy == protect_policy_conservative) { - //The object spans the entire page. Guard this instead - locked_address_base = next_page; + //Protect full unique range + locked_address_range = (block_end - block_start); } } }