rsx: Propagate split section information back to the texture cache

This commit is contained in:
kd-11 2019-05-13 20:53:00 +03:00 committed by kd-11
parent 3c7d8a1099
commit 4182f9984d
5 changed files with 127 additions and 13 deletions

View file

@ -134,6 +134,13 @@ namespace rsx
GcmTileInfo *tile = nullptr;
rsx::surface_antialiasing write_aa_mode = rsx::surface_antialiasing::center_1_sample;
union
{
rsx::surface_color_format gcm_color_format;
rsx::surface_depth_format gcm_depth_format;
}
format_info;
render_target_descriptor() {}
virtual ~render_target_descriptor()
@ -169,6 +176,26 @@ namespace rsx
write_aa_mode = read_aa_mode = rsx::surface_antialiasing::center_1_sample;
}
void set_format(rsx::surface_color_format format)
{
format_info.gcm_color_format = format;
}
void set_format(rsx::surface_depth_format format)
{
format_info.gcm_depth_format = format;
}
rsx::surface_color_format get_surface_color_format()
{
return format_info.gcm_color_format;
}
rsx::surface_depth_format get_surface_depth_format()
{
return format_info.gcm_depth_format;
}
bool test() const
{
if (dirty)
@ -438,6 +465,9 @@ namespace rsx
std::array<std::pair<u32, surface_type>, 4> m_bound_render_targets = {};
std::pair<u32, surface_type> m_bound_depth_stencil = {};
// List of sections derived from a section that has been split and invalidated
std::vector<surface_type> orphaned_surfaces;
std::list<surface_storage_type> invalidated_resources;
u64 cache_tag = 1ull; // Use 1 as the start since 0 is default tag on new surfaces
u64 write_tag = 1ull;
@ -483,7 +513,9 @@ namespace rsx
}
Traits::clone_surface(cmd, sink, region.source, new_address, region);
verify(HERE), region.target == Traits::get(sink);
orphaned_surfaces.push_back(region.target);
data[new_address] = std::move(sink);
};

View file

@ -422,6 +422,44 @@ void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool sk
}
}
if (!m_rtts.orphaned_surfaces.empty())
{
if (g_cfg.video.write_color_buffers || g_cfg.video.write_depth_buffer)
{
gl::texture::format format;
gl::texture::type type;
bool swap_bytes;
for (auto& surface : m_rtts.orphaned_surfaces)
{
if (surface->is_depth_surface())
{
if (!g_cfg.video.write_depth_buffer) continue;
const auto depth_format_gl = rsx::internals::surface_depth_format_to_gl(surface->get_surface_depth_format());
format = depth_format_gl.format;
type = depth_format_gl.type;
swap_bytes = true;
}
else
{
if (!g_cfg.video.write_color_buffers) continue;
const auto color_format_gl = rsx::internals::surface_color_format_to_gl(surface->get_surface_color_format());
format = color_format_gl.format;
type = color_format_gl.type;
swap_bytes = color_format_gl.swap_bytes;
}
m_gl_texture_cache.lock_memory_region(cmd, surface, surface->get_memory_range(),
surface->get_surface_width(), surface->get_surface_height(), surface->get_rsx_pitch(),
format, type, swap_bytes);
}
}
m_rtts.orphaned_surfaces.clear();
}
if (m_gl_texture_cache.get_ro_tex_invalidate_intr())
{
//Invalidate cached sampler state

View file

@ -183,6 +183,7 @@ struct gl_render_target_traits
rsx::apply_resolution_scale((u16)height, true), (GLenum)internal_fmt));
result->set_native_pitch((u16)width * format.channel_count * format.channel_size);
result->set_surface_dimensions((u16)width, (u16)height, (u16)pitch);
result->set_format(surface_color_format);
std::array<GLenum, 4> native_layout = { (GLenum)format.swizzle.a, (GLenum)format.swizzle.r, (GLenum)format.swizzle.g, (GLenum)format.swizzle.b };
result->set_native_component_layout(native_layout);
@ -212,6 +213,7 @@ struct gl_render_target_traits
result->set_native_pitch(native_pitch);
result->set_surface_dimensions((u16)width, (u16)height, (u16)pitch);
result->set_native_component_layout(native_layout);
result->set_format(surface_depth_format);
result->set_cleared(false);
result->queue_tag(address);
@ -233,14 +235,19 @@ struct gl_render_target_traits
sink.reset(new gl::render_target(new_w, new_h, internal_format));
sink->add_ref();
}
prev.target = sink.get();
sink->format_info = ref->format_info;
sink->set_native_pitch(prev.width * ref->get_bpp());
sink->set_surface_dimensions(prev.width, prev.height, ref->get_rsx_pitch());
sink->set_native_component_layout(ref->get_native_component_layout());
sink->queue_tag(address);
}
else
{
sink->set_rsx_pitch(ref->get_rsx_pitch());
}
prev.target = sink.get();
sink->sync_tag();
sink->set_old_contents_region(prev, false);
sink->set_cleared(false);
@ -251,8 +258,8 @@ struct gl_render_target_traits
bool is_compatible_surface(const gl::render_target* surface, const gl::render_target* ref, u16 width, u16 height, u8 /*sample_count*/)
{
return (surface->get_internal_format() == ref->get_internal_format() &&
surface->get_surface_width() == width &&
surface->get_surface_height() == height);
surface->get_surface_width() >= width &&
surface->get_surface_height() >= height);
}
static

View file

@ -3098,6 +3098,40 @@ void VKGSRender::prepare_rtts(rsx::framebuffer_creation_context context)
}
}
if (!m_rtts.orphaned_surfaces.empty())
{
if (g_cfg.video.write_color_buffers || g_cfg.video.write_depth_buffer)
{
u32 gcm_format;
bool swap_bytes;
for (auto& surface : m_rtts.orphaned_surfaces)
{
if (surface->is_depth_surface())
{
if (!g_cfg.video.write_depth_buffer) continue;
gcm_format = (surface->get_surface_depth_format() != rsx::surface_depth_format::z16) ? CELL_GCM_TEXTURE_DEPTH16 : CELL_GCM_TEXTURE_DEPTH24_D8;
swap_bytes = true;
}
else
{
if (!g_cfg.video.write_color_buffers) continue;
auto info = vk::get_compatible_gcm_format(surface->get_surface_color_format());
gcm_format = info.first;
swap_bytes = info.second;
}
m_texture_cache.lock_memory_region(*m_current_command_buffer, surface, surface->get_memory_range(),
surface->get_surface_width(), surface->get_surface_height(), surface->get_rsx_pitch(),
gcm_format, swap_bytes);
}
}
m_rtts.orphaned_surfaces.clear();
}
auto vk_depth_format = (layout.zeta_address == 0) ? VK_FORMAT_UNDEFINED : vk::get_compatible_depth_surface_format(m_device->get_formats_support(), layout.depth_format);
m_current_renderpass_id = vk::get_render_pass_location(vk::get_compatible_surface_format(layout.color_format).first, vk_depth_format, (u8)m_draw_buffers.size());

View file

@ -196,6 +196,7 @@ namespace rsx
change_image_layout(cmd, rtt.get(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, vk::get_image_subresource_range(0, 0, 1, 1, VK_IMAGE_ASPECT_COLOR_BIT));
rtt->set_format(format);
rtt->native_component_map = fmt.second;
rtt->rsx_pitch = (u16)pitch;
rtt->native_pitch = (u16)width * get_format_block_size_in_bytes(format);
@ -234,6 +235,7 @@ namespace rsx
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT| VK_IMAGE_USAGE_TRANSFER_SRC_BIT| VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
0));
ds->set_format(format);
ds->native_component_map = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_R };
change_image_layout(cmd, ds.get(), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, range);
@ -274,16 +276,17 @@ namespace rsx
ref->info.flags));
sink->add_ref();
}
prev.target = sink.get();
sink->format_info = ref->format_info;
sink->native_component_map = ref->native_component_map;
sink->rsx_pitch = ref->get_rsx_pitch();
sink->native_pitch = u16(prev.width * ref->get_bpp());
sink->surface_width = prev.width;
sink->surface_height = prev.height;
sink->queue_tag(address);
}
prev.target = sink.get();
sink->rsx_pitch = ref->get_rsx_pitch();
sink->sync_tag();
sink->set_old_contents_region(prev, false);
sink->dirty = true;
@ -295,8 +298,8 @@ namespace rsx
static bool is_compatible_surface(const vk::render_target* surface, const vk::render_target* ref, u16 width, u16 height, u8 /*sample_count*/)
{
return (surface->format() == ref->format() &&
surface->get_surface_width() == width &&
surface->get_surface_height() == height);
surface->get_surface_width() >= width &&
surface->get_surface_height() >= height);
}
static void get_surface_info(vk::render_target *surface, rsx::surface_format_info *info)