rsx: Improve memory protection behavior when strict mode is off

This commit is contained in:
kd-11 2017-10-04 20:54:13 +03:00
parent 91ef202ee7
commit 5a03db7d2e
4 changed files with 21 additions and 20 deletions

View File

@ -193,10 +193,6 @@ 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);
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)
@ -204,7 +200,6 @@ void GLGSRender::begin()
else
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)))
{

View File

@ -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)

View File

@ -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);
}

View File

@ -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);
}
}
}