This commit is contained in:
R2DLiu 2021-11-26 19:48:26 -05:00
commit 9cf53410c7
3 changed files with 33 additions and 38 deletions

View file

@ -27,11 +27,6 @@ static std::mutex ack_mutex;
SlippiNetplayClient* SLIPPI_NETPLAY = nullptr; SlippiNetplayClient* SLIPPI_NETPLAY = nullptr;
static bool IsOnline()
{
return SLIPPI_NETPLAY != nullptr;
}
// called from ---GUI--- thread // called from ---GUI--- thread
SlippiNetplayClient::~SlippiNetplayClient() SlippiNetplayClient::~SlippiNetplayClient()
{ {
@ -66,7 +61,7 @@ SlippiNetplayClient::SlippiNetplayClient(const std::string& address, const u16 r
: m_qos_handle(nullptr), m_qos_flow_id(0) : m_qos_handle(nullptr), m_qos_flow_id(0)
#endif #endif
{ {
WARN_LOG_FMT(SLIPPI_ONLINE, "Initializing Slippi Netplay for port: %d, with host: %s", localPort, WARN_LOG_FMT(SLIPPI_ONLINE, "Initializing Slippi Netplay for port: {}, with host: {}", localPort,
isDecider ? "true" : "false"); isDecider ? "true" : "false");
this->isDecider = isDecider; this->isDecider = isDecider;
@ -291,7 +286,7 @@ unsigned int SlippiNetplayClient::OnData(sf::Packet& packet)
break; break;
default: default:
WARN_LOG_FMT(SLIPPI_ONLINE, "Unknown message received with id : %d", mid); WARN_LOG_FMT(SLIPPI_ONLINE, "Unknown message received with id : {}", mid);
break; break;
} }
@ -422,7 +417,7 @@ void SlippiNetplayClient::ThreadFunc()
break; break;
} }
WARN_LOG_FMT(SLIPPI_ONLINE, "[Netplay] Not yet connected. Res: %d, Type: %d", net, WARN_LOG_FMT(SLIPPI_ONLINE, "[Netplay] Not yet connected. Res: {}, Type: {}", net,
netEvent.type); netEvent.type);
// Time out after enough time has passed // Time out after enough time has passed

View file

@ -207,4 +207,7 @@ private:
extern SlippiNetplayClient* SLIPPI_NETPLAY; // singleton static pointer extern SlippiNetplayClient* SLIPPI_NETPLAY; // singleton static pointer
static bool IsOnline(); inline bool IsOnline()
{
return SLIPPI_NETPLAY != nullptr;
}

View file

@ -1713,7 +1713,7 @@ static void GetDisplayRectForXFBEntry(TextureCacheBase::TCacheEntry* entry, u32
TextureCacheBase::TCacheEntry* TextureCacheBase::TCacheEntry*
TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride, TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
MathUtil::Rectangle<int>* display_rect) MathUtil::Rectangle<int>* display_rect)
{ {
const u8* src_data = Memory::GetPointer(address); const u8* src_data = Memory::GetPointer(address);
if (!src_data) if (!src_data)
@ -1742,9 +1742,9 @@ TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
// Create a new VRAM texture, and fill it with the data from guest RAM. // Create a new VRAM texture, and fill it with the data from guest RAM.
entry = AllocateCacheEntry(TextureConfig(width, height, 1, 1, 1, AbstractTextureFormat::RGBA8, entry = AllocateCacheEntry(TextureConfig(width, height, 1, 1, 1, AbstractTextureFormat::RGBA8,
AbstractTextureFlag_RenderTarget)); AbstractTextureFlag_RenderTarget));
entry->SetGeneralParameters(address, total_size, entry->SetGeneralParameters(address, total_size,
TextureAndTLUTFormat(TextureFormat::XFB, TLUTFormat::IA8), true); TextureAndTLUTFormat(TextureFormat::XFB, TLUTFormat::IA8), true);
entry->SetDimensions(width, height, 1); entry->SetDimensions(width, height, 1);
entry->SetHashes(hash, hash); entry->SetHashes(hash, hash);
entry->SetXfbCopy(stride); entry->SetXfbCopy(stride);
@ -1753,8 +1753,8 @@ TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
entry->may_have_overlapping_textures = false; entry->may_have_overlapping_textures = false;
entry->frameCount = FRAMECOUNT_INVALID; entry->frameCount = FRAMECOUNT_INVALID;
if (!g_ActiveConfig.UseGPUTextureDecoding() || if (!g_ActiveConfig.UseGPUTextureDecoding() ||
!DecodeTextureOnGPU(entry, 0, src_data, total_size, entry->format.texfmt, width, height, !DecodeTextureOnGPU(entry, 0, src_data, total_size, entry->format.texfmt, width, height,
width, height, stride, texMem, entry->format.tlutfmt)) width, height, stride, texMem, entry->format.tlutfmt))
{ {
const u32 decoded_size = width * height * sizeof(u32); const u32 decoded_size = width * height * sizeof(u32);
CheckTempSize(decoded_size); CheckTempSize(decoded_size);
@ -1776,7 +1776,7 @@ TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
// While this isn't really an xfb copy, we can treat it as such for dumping purposes // While this isn't really an xfb copy, we can treat it as such for dumping purposes
static int xfb_count = 0; static int xfb_count = 0;
entry->texture->Save( entry->texture->Save(
fmt::format("{}xfb_loaded_{}.png", File::GetUserPath(D_DUMPTEXTURES_IDX), xfb_count++), 0); fmt::format("{}xfb_loaded_{}.png", File::GetUserPath(D_DUMPTEXTURES_IDX), xfb_count++), 0);
} }
GetDisplayRectForXFBEntry(entry, width, height, display_rect); GetDisplayRectForXFBEntry(entry, width, height, display_rect);
@ -1785,7 +1785,10 @@ TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
TextureCacheBase::TCacheEntry* TextureCacheBase::TCacheEntry*
TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride, TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
MathUtil::Rectangle<int>* display_rect, float gamma, const MathUtil::Rectangle<int>& src_rect, const CopyFilterCoefficients::Values& copy_filter_coefficients, float y_scale, bool clamp_top, bool clamp_bottom) MathUtil::Rectangle<int>* display_rect, float gamma,
const MathUtil::Rectangle<int>& src_rect,
const CopyFilterCoefficients::Values& copy_filter_coefficients,
float y_scale, bool clamp_top, bool clamp_bottom)
{ {
auto filter_coefficients = GetVRAMCopyFilterCoefficients(copy_filter_coefficients); auto filter_coefficients = GetVRAMCopyFilterCoefficients(copy_filter_coefficients);
const u8* src_data = Memory::GetPointer(address); const u8* src_data = Memory::GetPointer(address);
@ -1798,13 +1801,9 @@ TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
u32 scaled_tex_w = g_renderer->EFBToScaledX(width); u32 scaled_tex_w = g_renderer->EFBToScaledX(width);
u32 scaled_tex_h = g_renderer->EFBToScaledY(height); u32 scaled_tex_h = g_renderer->EFBToScaledY(height);
// Compute total texture size. XFB textures aren't tiled, so this is simple.
const u32 total_size = height * stride;
const u64 hash = Common::GetHash64(src_data, total_size, 0);
TCacheEntry* entry = nullptr; TCacheEntry* entry = nullptr;
const TextureConfig config(scaled_tex_w, scaled_tex_h, 1, g_framebuffer_manager->GetEFBLayers(), const TextureConfig config(scaled_tex_w, scaled_tex_h, 1, g_framebuffer_manager->GetEFBLayers(),
1, AbstractTextureFormat::RGBA8, AbstractTextureFlag_RenderTarget); 1, AbstractTextureFormat::RGBA8, AbstractTextureFlag_RenderTarget);
entry = AllocateCacheEntry(config); entry = AllocateCacheEntry(config);
auto baseFormat = TexDecoder_GetEFBCopyBaseFormat(EFBCopyFormat::XFB); auto baseFormat = TexDecoder_GetEFBCopyBaseFormat(EFBCopyFormat::XFB);
@ -1826,7 +1825,8 @@ TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
if (entry) if (entry)
{ {
entry->SetGeneralParameters(address, 0, TexDecoder_GetEFBCopyBaseFormat(EFBCopyFormat::XFB), true); entry->SetGeneralParameters(address, 0, TexDecoder_GetEFBCopyBaseFormat(EFBCopyFormat::XFB),
true);
entry->SetDimensions(width, height, 1); entry->SetDimensions(width, height, 1);
entry->frameCount = FRAMECOUNT_INVALID; entry->frameCount = FRAMECOUNT_INVALID;
entry->should_force_safe_hashing = true; entry->should_force_safe_hashing = true;
@ -1834,16 +1834,14 @@ TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
entry->may_have_overlapping_textures = false; entry->may_have_overlapping_textures = false;
entry->is_custom_tex = false; entry->is_custom_tex = false;
/////////////////////// ///////////////////////
// Flush EFB pokes first, as they're expected to be included. // Flush EFB pokes first, as they're expected to be included.
g_framebuffer_manager->FlushEFBPokes(); g_framebuffer_manager->FlushEFBPokes();
// Get the pipeline which we will be using. If the compilation failed, this will be null. // Get the pipeline which we will be using. If the compilation failed, this will be null.
const AbstractPipeline* copy_pipeline = const AbstractPipeline* copy_pipeline =
g_shader_cache->GetEFBCopyToVRAMPipeline(TextureConversionShaderGen::GetShaderUid( g_shader_cache->GetEFBCopyToVRAMPipeline(TextureConversionShaderGen::GetShaderUid(
EFBCopyFormat::XFB, false, false, false, EFBCopyFormat::XFB, false, false, false, NeedsCopyFilterInShader(filter_coefficients)));
NeedsCopyFilterInShader(filter_coefficients)));
if (!copy_pipeline) if (!copy_pipeline)
{ {
WARN_LOG(VIDEO, "Skipping EFB copy to VRAM due to missing pipeline."); WARN_LOG(VIDEO, "Skipping EFB copy to VRAM due to missing pipeline.");
@ -1852,7 +1850,7 @@ TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
const auto scaled_src_rect = g_renderer->ConvertEFBRectangle(src_rect); const auto scaled_src_rect = g_renderer->ConvertEFBRectangle(src_rect);
const auto framebuffer_rect = g_renderer->ConvertFramebufferRectangle( const auto framebuffer_rect = g_renderer->ConvertFramebufferRectangle(
scaled_src_rect, g_framebuffer_manager->GetEFBFramebuffer()); scaled_src_rect, g_framebuffer_manager->GetEFBFramebuffer());
AbstractTexture* src_texture = g_framebuffer_manager->ResolveEFBColorTexture(framebuffer_rect); AbstractTexture* src_texture = g_framebuffer_manager->ResolveEFBColorTexture(framebuffer_rect);
src_texture->FinishedRendering(); src_texture->FinishedRendering();
@ -1894,7 +1892,7 @@ TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
g_renderer->SetPipeline(copy_pipeline); g_renderer->SetPipeline(copy_pipeline);
g_renderer->SetTexture(0, src_texture); g_renderer->SetTexture(0, src_texture);
g_renderer->SetSamplerState(0, linear_filter ? RenderState::GetLinearSamplerState() : g_renderer->SetSamplerState(0, linear_filter ? RenderState::GetLinearSamplerState() :
RenderState::GetPointSamplerState()); RenderState::GetPointSamplerState());
g_renderer->Draw(0, 3); g_renderer->Draw(0, 3);
g_renderer->EndUtilityDrawing(); g_renderer->EndUtilityDrawing();
entry->texture->FinishedRendering(); entry->texture->FinishedRendering();
@ -1905,8 +1903,7 @@ TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
{ {
static int xfb_count = 0; static int xfb_count = 0;
entry->texture->Save( entry->texture->Save(
fmt::format("{}xfb_copy_{}.png", File::GetUserPath(D_DUMPTEXTURES_IDX), xfb_count++), fmt::format("{}xfb_copy_{}.png", File::GetUserPath(D_DUMPTEXTURES_IDX), xfb_count++), 0);
0);
} }
u8* dst = Memory::GetPointer(address); u8* dst = Memory::GetPointer(address);
UninitializeXFBMemory(dst, stride, bytes_per_row, num_blocks_y); UninitializeXFBMemory(dst, stride, bytes_per_row, num_blocks_y);
@ -1932,12 +1929,12 @@ TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
if (overlapping_entry->OverlapsMemoryRange(address, covered_range)) if (overlapping_entry->OverlapsMemoryRange(address, covered_range))
{ {
u32 overlap_range = std::min(overlapping_entry->addr + overlapping_entry->size_in_bytes, u32 overlap_range = std::min(overlapping_entry->addr + overlapping_entry->size_in_bytes,
address + covered_range) - address + covered_range) -
std::max(overlapping_entry->addr, address); std::max(overlapping_entry->addr, address);
if (overlapping_entry->memory_stride != stride || if (overlapping_entry->memory_stride != stride ||
(!strided_efb_copy && overlapping_entry->size_in_bytes == overlap_range) || (!strided_efb_copy && overlapping_entry->size_in_bytes == overlap_range) ||
(strided_efb_copy && overlapping_entry->size_in_bytes == overlap_range && (strided_efb_copy && overlapping_entry->size_in_bytes == overlap_range &&
overlapping_entry->addr == address)) overlapping_entry->addr == address))
{ {
// Pending EFB copies which are completely covered by this new copy can simply be tossed, // Pending EFB copies which are completely covered by this new copy can simply be tossed,
// instead of having to flush them later on, since this copy will write over everything. // instead of having to flush them later on, since this copy will write over everything.
@ -1967,13 +1964,13 @@ TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
for (u32 i = 0; i < num_blocks_y; i++) for (u32 i = 0; i < num_blocks_y; i++)
{ {
FifoRecorder::GetInstance().UseMemory(address, bytes_per_row, MemoryUpdate::TEXTURE_MAP, FifoRecorder::GetInstance().UseMemory(address, bytes_per_row, MemoryUpdate::TEXTURE_MAP,
true); true);
address += stride; address += stride;
} }
} }
// Even if the copy is deferred, still compute the hash. This way if the copy is used as a texture // Even if the copy is deferred, still compute the hash. This way if the copy is used as a
// in a subsequent draw before it is flushed, it will have the same hash. // texture in a subsequent draw before it is flushed, it will have the same hash.
if (entry) if (entry)
{ {
const u64 entry_hash = entry->CalculateHash(); const u64 entry_hash = entry->CalculateHash();