rsx: Optimize metrics a bit

- For some reason this has a massive impact on performance above some arbitrary threshold of calls
  Shows up under surface_cache::get_merged_memory_region when doing gathers.
This commit is contained in:
kd-11 2022-03-05 18:42:53 +03:00 committed by kd-11
parent 6812fa4764
commit 0df903090d
10 changed files with 51 additions and 53 deletions

View File

@ -721,9 +721,9 @@ namespace rsx
auto this_range = it->surface->get_memory_range();
ensure(this_range.overlaps(range));
const auto native_pitch = it->surface->get_surface_width(rsx::surface_metrics::bytes);
const auto native_pitch = it->surface->get_surface_width<rsx::surface_metrics::bytes>();
const auto rsx_pitch = it->surface->get_rsx_pitch();
auto num_rows = it->surface->get_surface_height(rsx::surface_metrics::samples);
auto num_rows = it->surface->get_surface_height<rsx::surface_metrics::samples>();
bool valid = false;
if (this_range.start < range.start)
@ -1002,8 +1002,8 @@ namespace rsx
info.base_address = range.start;
info.is_depth = is_depth;
const u32 normalized_surface_width = surface->get_surface_width(rsx::surface_metrics::bytes) / required_bpp;
const u32 normalized_surface_height = surface->get_surface_height(rsx::surface_metrics::samples);
const u32 normalized_surface_width = surface->get_surface_width<rsx::surface_metrics::bytes>() / required_bpp;
const u32 normalized_surface_height = surface->get_surface_height<rsx::surface_metrics::samples>();
if (range.start >= texaddr) [[likely]]
{

View File

@ -94,12 +94,12 @@ namespace rsx
auto src = static_cast<T>(source);
std::tie(src_w, src_h) = rsx::apply_resolution_scale<true>(src_w, src_h,
src->get_surface_width(rsx::surface_metrics::pixels),
src->get_surface_height(rsx::surface_metrics::pixels));
src->get_surface_width<rsx::surface_metrics::pixels>(),
src->get_surface_height<rsx::surface_metrics::pixels>());
std::tie(dst_w, dst_h) = rsx::apply_resolution_scale<true>(dst_w, dst_h,
target_surface->get_surface_width(rsx::surface_metrics::pixels),
target_surface->get_surface_height(rsx::surface_metrics::pixels));
target_surface->get_surface_width<rsx::surface_metrics::pixels>()),
target_surface->get_surface_height<rsx::surface_metrics::pixels>()));
}
width = src_w;
@ -178,9 +178,10 @@ namespace rsx
virtual bool is_depth_surface() const = 0;
virtual void release_ref(image_storage_type) const = 0;
inline u32 get_surface_width(rsx::surface_metrics metrics = rsx::surface_metrics::pixels) const
template<rsx::surface_metrics Metrics = rsx::surface_metrics::pixels>
u32 get_surface_width() const
{
switch (metrics)
switch constexpr (Metrics)
{
case rsx::surface_metrics::samples:
return surface_width * samples_x;
@ -188,22 +189,19 @@ namespace rsx
return surface_width;
case rsx::surface_metrics::bytes:
return native_pitch;
default:
fmt::throw_exception("Unknown surface metric %d", u32(metrics));
}
}
inline u32 get_surface_height(rsx::surface_metrics metrics = rsx::surface_metrics::pixels) const
template<rsx::surface_metrics Metrics = rsx::surface_metrics::pixels>
u32 get_surface_height() const
{
switch (metrics)
switch constexpr (Metrics)
{
case rsx::surface_metrics::samples:
case rsx::surface_metrics::bytes:
return surface_height * samples_y;
case rsx::surface_metrics::pixels:
return surface_height;
default:
fmt::throw_exception("Unknown surface metric %d", u32(metrics));
}
}
@ -219,7 +217,7 @@ namespace rsx
inline u8 get_bpp() const
{
return u8(get_native_pitch() / get_surface_width(rsx::surface_metrics::samples));
return u8(get_native_pitch() / get_surface_width<rsx::surface_metrics::samples>());
}
inline u8 get_spp() const
@ -514,11 +512,11 @@ namespace rsx
template <typename T>
surface_inheritance_result inherit_surface_contents(T* surface)
{
const auto child_w = get_surface_width(rsx::surface_metrics::bytes);
const auto child_h = get_surface_height(rsx::surface_metrics::bytes);
const auto child_w = get_surface_width<rsx::surface_metrics::bytes>();
const auto child_h = get_surface_height<rsx::surface_metrics::bytes>();
const auto parent_w = surface->get_surface_width(rsx::surface_metrics::bytes);
const auto parent_h = surface->get_surface_height(rsx::surface_metrics::bytes);
const auto parent_w = surface->get_surface_width<rsx::surface_metrics::bytes>();
const auto parent_h = surface->get_surface_height<rsx::surface_metrics::bytes>();
const auto rect = rsx::intersect_region(surface->base_addr, parent_w, parent_h, 1, base_addr, child_w, child_h, 1, get_rsx_pitch());
const auto src_offset = std::get<0>(rect);
@ -606,17 +604,17 @@ namespace rsx
}
// Returns the rect area occupied by this surface expressed as an 8bpp image with no AA
areau get_normalized_memory_area() const
inline areau get_normalized_memory_area() const
{
const u16 internal_width = get_surface_width(rsx::surface_metrics::bytes);
const u16 internal_height = get_surface_height(rsx::surface_metrics::bytes);
const u16 internal_width = get_surface_width<rsx::surface_metrics::bytes>();
const u16 internal_height = get_surface_height<rsx::surface_metrics::bytes>();
return { 0, 0, internal_width, internal_height };
}
rsx::address_range get_memory_range() const
inline rsx::address_range get_memory_range() const
{
const u32 internal_height = get_surface_height(rsx::surface_metrics::samples);
const u32 internal_height = get_surface_height<rsx::surface_metrics::samples>());
const u32 excess = (rsx_pitch - native_pitch);
return rsx::address_range::start_length(base_addr, internal_height * rsx_pitch - excess);
}

View File

@ -1952,7 +1952,7 @@ namespace rsx
u32 coverage_size = 0;
for (const auto& section : overlapping_fbos)
{
const auto area = section.surface->get_native_pitch() * section.surface->get_surface_height(rsx::surface_metrics::bytes);
const auto area = section.surface->get_native_pitch() * section.surface->get_surface_height<rsx::surface_metrics::bytes>();
coverage_size += area;
}
@ -2509,8 +2509,8 @@ namespace rsx
typeless_info.src_gcm_format = helpers::get_sized_blit_format(src_is_argb8, false, is_format_convert);
}
if (surf->get_surface_width(rsx::surface_metrics::pixels) != surf->width() ||
surf->get_surface_height(rsx::surface_metrics::pixels) != surf->height())
if (surf->get_surface_width<rsx::surface_metrics::pixels>() != surf->width() ||
surf->get_surface_height<rsx::surface_metrics::pixels>() != surf->height())
{
// Must go through a scaling operation due to resolution scaling being present
ensure(g_cfg.video.resolution_scale_percent != 100);
@ -2606,8 +2606,8 @@ namespace rsx
size2u src_dimensions = { 0, 0 };
if (src_is_render_target)
{
src_dimensions.width = src_subres.surface->get_surface_width(rsx::surface_metrics::samples);
src_dimensions.height = src_subres.surface->get_surface_height(rsx::surface_metrics::samples);
src_dimensions.width = src_subres.surface->get_surface_width<rsx::surface_metrics::samples>();
src_dimensions.height = src_subres.surface->get_surface_height<rsx::surface_metrics::samples>();
}
const auto props = texture_cache_helpers::get_optimal_blit_target_properties(
@ -2761,8 +2761,8 @@ namespace rsx
typeless_info.dst_context = texture_upload_context::framebuffer_storage;
dst_is_depth_surface = typeless_info.dst_is_typeless ? false : dst_subres.is_depth;
max_dst_width = static_cast<u16>(dst_subres.surface->get_surface_width(rsx::surface_metrics::samples) * typeless_info.dst_scaling_hint);
max_dst_height = dst_subres.surface->get_surface_height(rsx::surface_metrics::samples);
max_dst_width = static_cast<u16>(dst_subres.surface->get_surface_width<rsx::surface_metrics::samples>() * typeless_info.dst_scaling_hint);
max_dst_height = dst_subres.surface->get_surface_height<rsx::surface_metrics::samples>();
}
// Create source texture if does not exist
@ -3109,8 +3109,8 @@ namespace rsx
if (src_is_render_target)
{
const auto surface_width = src_subres.surface->get_surface_width(rsx::surface_metrics::pixels);
const auto surface_height = src_subres.surface->get_surface_height(rsx::surface_metrics::pixels);
const auto surface_width = src_subres.surface->get_surface_width<rsx::surface_metrics::pixels>();
const auto surface_height = src_subres.surface->get_surface_height<rsx::surface_metrics::pixels>();
std::tie(src_area.x1, src_area.y1) = rsx::apply_resolution_scale<false>(src_area.x1, src_area.y1, surface_width, surface_height);
std::tie(src_area.x2, src_area.y2) = rsx::apply_resolution_scale<true>(src_area.x2, src_area.y2, surface_width, surface_height);
@ -3120,8 +3120,8 @@ namespace rsx
if (dst_is_render_target)
{
const auto surface_width = dst_subres.surface->get_surface_width(rsx::surface_metrics::pixels);
const auto surface_height = dst_subres.surface->get_surface_height(rsx::surface_metrics::pixels);
const auto surface_width = dst_subres.surface->get_surface_width<rsx::surface_metrics::pixels>();
const auto surface_height = dst_subres.surface->get_surface_height<rsx::surface_metrics::pixels>();
std::tie(dst_area.x1, dst_area.y1) = rsx::apply_resolution_scale<false>(dst_area.x1, dst_area.y1, surface_width, surface_height);
std::tie(dst_area.x2, dst_area.y2) = rsx::apply_resolution_scale<true>(dst_area.x2, dst_area.y2, surface_width, surface_height);

View File

@ -303,8 +303,8 @@ namespace rsx
const auto h = std::min(section_end, slice_end) - dst_y;
dst_y = (dst_y - slice_begin);
const auto surface_width = section.surface->get_surface_width(rsx::surface_metrics::pixels);
const auto surface_height = section.surface->get_surface_height(rsx::surface_metrics::pixels);
const auto surface_width = section.surface->get_surface_width<rsx::surface_metrics::pixels>();
const auto surface_height = section.surface->get_surface_height<rsx::surface_metrics::pixels>();
const auto [src_width, src_height] = rsx::apply_resolution_scale<true>(section.src_area.width, h, surface_width, surface_height);
const auto [dst_width, dst_height] = rsx::apply_resolution_scale<true>(section.dst_area.width, h, attr.width, attr.height);
@ -477,8 +477,8 @@ namespace rsx
return false;
}
const auto surface_width = texptr->get_surface_width(rsx::surface_metrics::samples);
const auto surface_height = texptr->get_surface_height(rsx::surface_metrics::samples);
const auto surface_width = texptr->get_surface_width<rsx::surface_metrics::samples>();
const auto surface_height = texptr->get_surface_height<rsx::surface_metrics::samples>();
switch (extended_dimension)
{
@ -507,8 +507,8 @@ namespace rsx
{
texptr->read_barrier(cmd);
const auto surface_width = texptr->get_surface_width(rsx::surface_metrics::samples);
const auto surface_height = texptr->get_surface_height(rsx::surface_metrics::samples);
const auto surface_width = texptr->get_surface_width<rsx::surface_metrics::samples>();
const auto surface_height = texptr->get_surface_height<rsx::surface_metrics::samples>();
bool is_depth = texptr->is_depth_surface();
auto attr2 = attr;

View File

@ -38,8 +38,8 @@ gl::texture* GLGSRender::get_present_source(gl::present_surface_info* info, cons
if (section.base_address >= info->address)
{
const auto surface_width = surface->get_surface_width(rsx::surface_metrics::samples);
const auto surface_height = surface->get_surface_height(rsx::surface_metrics::samples);
const auto surface_width = surface->get_surface_width<rsx::surface_metrics::samples>();
const auto surface_height = surface->get_surface_height<rsx::surface_metrics::samples>();
if (section.base_address == info->address)
{

View File

@ -382,7 +382,7 @@ void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool /*
m_gl_texture_cache.lock_memory_region(
cmd, surface, surface->get_memory_range(), false,
surface->get_surface_width(rsx::surface_metrics::pixels), surface->get_surface_height(rsx::surface_metrics::pixels), surface->get_rsx_pitch(),
surface->get_surface_width<rsx::surface_metrics::pixels>(), surface->get_surface_height<rsx::surface_metrics::pixels>(), surface->get_rsx_pitch(),
format, type, swap_bytes);
}

View File

@ -194,7 +194,7 @@ struct gl_render_target_traits
{
auto internal_format = static_cast<GLenum>(ref->get_internal_format());
const auto [new_w, new_h] = rsx::apply_resolution_scale<true>(prev.width, prev.height,
ref->get_surface_width(rsx::surface_metrics::pixels), ref->get_surface_height(rsx::surface_metrics::pixels));
ref->get_surface_width<rsx::surface_metrics::pixels>(), ref->get_surface_height<rsx::surface_metrics::pixels>());
sink = std::make_unique<gl::render_target>(new_w, new_h, internal_format, ref->format_class());
sink->add_ref();
@ -237,8 +237,8 @@ struct gl_render_target_traits
{
return (surface->get_internal_format() == ref->get_internal_format() &&
surface->get_spp() == sample_count &&
surface->get_surface_width(rsx::surface_metrics::pixels) >= width &&
surface->get_surface_height(rsx::surface_metrics::pixels) >= height);
surface->get_surface_width<rsx::surface_metrics::pixels>() >= width &&
surface->get_surface_height<rsx::surface_metrics::pixels>() >= height);
}
static

View File

@ -2463,7 +2463,7 @@ void VKGSRender::prepare_rtts(rsx::framebuffer_creation_context context)
m_texture_cache.lock_memory_region(
*m_current_command_buffer, surface, surface->get_memory_range(), false,
surface->get_surface_width(rsx::surface_metrics::pixels), surface->get_surface_height(rsx::surface_metrics::pixels), surface->get_rsx_pitch(),
surface->get_surface_width<rsx::surface_metrics::pixels>(), surface->get_surface_height<rsx::surface_metrics::pixels>(), surface->get_rsx_pitch(),
gcm_format, swap_bytes);
}

View File

@ -288,8 +288,8 @@ vk::viewable_image* VKGSRender::get_present_source(vk::present_surface_info* inf
if (section.base_address >= info->address)
{
const auto surface_width = surface->get_surface_width(rsx::surface_metrics::samples);
const auto surface_height = surface->get_surface_height(rsx::surface_metrics::samples);
const auto surface_width = surface->get_surface_width<rsx::surface_metrics::samples>();
const auto surface_height = surface->get_surface_height<rsx::surface_metrics::samples>();
if (section.base_address == info->address)
{

View File

@ -271,7 +271,7 @@ namespace vk
if (!sink)
{
const auto [new_w, new_h] = rsx::apply_resolution_scale<true>(prev.width, prev.height,
ref->get_surface_width(rsx::surface_metrics::pixels), ref->get_surface_height(rsx::surface_metrics::pixels));
ref->get_surface_width<rsx::surface_metrics::pixels>(), ref->get_surface_height<rsx::surface_metrics::pixels>());
auto& dev = cmd.get_command_pool().get_owner();
sink = std::make_unique<vk::render_target>(dev, dev.get_memory_mapping().device_local,