Skip to content

Commit

Permalink
temporal fix for the hangs reported in the latest versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinob committed Oct 1, 2016
1 parent 7ffb18a commit 3858113
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
5 changes: 3 additions & 2 deletions Source/Core/VideoBackends/D3D12/TextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, PEControl::PixelFormat
D3DTexture2D* efb_tex = (src_format == PEControl::Z24) ?
FramebufferManager::GetEFBDepthTexture() :
FramebufferManager::GetEFBColorTexture();
const TargetRectangle targetSource = g_renderer->ConvertEFBRectangle(src_rect);
if (multisampled && scale_by_half)
{
multisampled = false;
Expand All @@ -446,11 +447,11 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, PEControl::PixelFormat
s_efb_copy_last_cbuf_id = cbuf_id;
}
// stretch picture with increased internal resolution
D3D::SetViewportAndScissor(0, 0, config.width, config.height);
D3D::SetViewportAndScissor(0, 0, targetSource.GetWidth() / (scale_by_half ? 2 : 1), targetSource.GetHeight() / (scale_by_half ? 2 : 1));
D3D::current_command_list->SetGraphicsRootConstantBufferView(DESCRIPTOR_TABLE_PS_CBVONE, s_efb_copy_stream_buffer->GetGPUAddressOfCurrentAllocation());
D3D::command_list_mgr->SetCommandListDirtyState(COMMAND_LIST_STATE_PS_CBV, true);

const TargetRectangle targetSource = g_renderer->ConvertEFBRectangle(src_rect);

// TODO: try targetSource.asRECT();
const D3D12_RECT sourcerect = CD3DX12_RECT(targetSource.left, targetSource.top, targetSource.right, targetSource.bottom);

Expand Down
6 changes: 3 additions & 3 deletions Source/Core/VideoBackends/DX11/TextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,10 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, PEControl::PixelFormat
FramebufferManager::GetEFBDepthTexture()->GetSRV() :
FramebufferManager::GetEFBColorTexture()->GetSRV();
}

const TargetRectangle targetSource = g_renderer->ConvertEFBRectangle(srcRect);
g_renderer->ResetAPIState();
// stretch picture with increased internal resolution
const D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)config.width, (float)config.height);
const D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)targetSource.GetWidth() * (scaleByHalf ? 0.5f : 1.0f), (float)targetSource.GetHeight() * (scaleByHalf ? 0.5f : 1.0f));
D3D::context->RSSetViewports(1, &vp);

// set transformation
Expand All @@ -429,7 +429,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, PEControl::PixelFormat
}
D3D::stateman->SetPixelConstants(efbcopycbuf[cbufid].get());

const TargetRectangle targetSource = g_renderer->ConvertEFBRectangle(srcRect);

// TODO: try targetSource.asRECT();
const D3D11_RECT sourcerect = CD3D11_RECT(targetSource.left, targetSource.top, targetSource.right, targetSource.bottom);

Expand Down
12 changes: 6 additions & 6 deletions Source/Core/VideoBackends/DX9/TextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,24 +234,24 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, PEControl::PixelFormat
D3D::dev->SetRenderTarget(0, Rendersurf);

D3DVIEWPORT9 vp;

TargetRectangle targetSource = g_renderer->ConvertEFBRectangle(srcRect);
// Stretch picture with increased internal resolution
vp.X = 0;
vp.Y = 0;
vp.Width = config.width;
vp.Height = config.height;
vp.Width = targetSource.GetWidth() / (scaleByHalf ? 2 : 1);
vp.Height = targetSource.GetHeight() / (scaleByHalf ? 2 : 1);
vp.MinZ = 0.0f;
vp.MaxZ = 1.0f;
D3D::dev->SetViewport(&vp);
RECT destrect;
destrect.bottom = config.height;
destrect.bottom = vp.Height;
destrect.left = 0;
destrect.right = config.width;
destrect.right = vp.Width;
destrect.top = 0;

PixelShaderManager::SetColorMatrix(colmat); // set transformation
D3D::dev->SetPixelShaderConstantF(C_COLORMATRIX, PixelShaderManager::GetBuffer(), 7);
TargetRectangle targetSource = g_renderer->ConvertEFBRectangle(srcRect);

RECT sourcerect;
sourcerect.bottom = targetSource.bottom;
sourcerect.left = targetSource.left;
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/VideoBackends/OGL/TextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,14 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, PEControl::PixelFormat
FramebufferManager::SetFramebuffer(framebuffer);

OpenGL_BindAttributelessVAO();

TargetRectangle R = g_renderer->ConvertEFBRectangle(srcRect);
glActiveTexture(GL_TEXTURE9);
glBindTexture(GL_TEXTURE_2D_ARRAY, read_texture);
if (scaleByHalf)
g_sampler_cache->BindLinearSampler(9);
else
g_sampler_cache->BindNearestSampler(9);
glViewport(0, 0, config.width, config.height);
glViewport(0, 0, R.GetWidth() / (scaleByHalf ? 2 : 1), R.GetHeight() / (scaleByHalf ? 2 : 1));

GLuint uniform_location;
if (srcFormat == PEControl::Z24)
Expand All @@ -457,7 +457,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, PEControl::PixelFormat
uniform_location = s_ColorMatrixPositionUniform;
}

TargetRectangle R = g_renderer->ConvertEFBRectangle(srcRect);

glUniform4f(uniform_location, static_cast<float>(R.left), static_cast<float>(R.top),
static_cast<float>(R.right), static_cast<float>(R.bottom));

Expand Down
3 changes: 0 additions & 3 deletions Source/Core/VideoCommon/BPStructs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,6 @@ void BPWritten(const BPCmd& bp)
// TODO: What's the behavior of out of bound access?
srcRect.right = (int)(bpmem.copyTexSrcXY.x + bpmem.copyTexSrcWH.x + 1);
srcRect.bottom = (int)(bpmem.copyTexSrcXY.y + bpmem.copyTexSrcWH.y + 1);
// fix to avoid crashes in oversized copies while a correct code is implemented
srcRect.right = std::min(srcRect.right, static_cast<int>(EFB_WIDTH));
srcRect.bottom = std::min(srcRect.bottom, static_cast<int>(EFB_HEIGHT));
UPE_Copy PE_copy = bpmem.triggerEFBCopy;

// Check if we are to copy from the EFB or draw to the XFB
Expand Down
14 changes: 10 additions & 4 deletions Source/Core/VideoCommon/TextureCacheBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,13 +1242,19 @@ void TextureCacheBase::CopyRenderTargetToTexture(u32 dstAddr, u32 dstFormat, u32
const u32 bytes_per_block = baseFormat == GX_TF_RGBA8 ? 64 : 32;

u32 bytes_per_row = num_blocks_x * bytes_per_block;

bool copy_to_ram = !g_ActiveConfig.bSkipEFBCopyToRam;
// temporal fix for hangs when trying to copy larger buffers that the actual efb size
bool copy_to_ram = !g_ActiveConfig.bSkipEFBCopyToRam && srcRect.GetWidth() <= EFB_WIDTH && srcRect.GetHeight() <= EFB_HEIGHT;
if (g_ActiveConfig.bLastStoryEFBToRam)
{
// mimimi085181: Ugly speedhack for the Last Story
copy_to_ram = copy_to_ram || ((tex_w == 64 || tex_w == 128 || tex_w == 256) && !isIntensity && tex_h != 1 && (dstFormat == 6 || dstFormat == 32));
}

EFBRectangle rectifiedRect;
rectifiedRect.left = std::min(srcRect.left, (int)EFB_WIDTH);
rectifiedRect.right = std::min(srcRect.right, (int)EFB_WIDTH);
rectifiedRect.top = std::min(srcRect.top, (int)EFB_HEIGHT);
rectifiedRect.bottom = std::min(srcRect.bottom, (int)EFB_HEIGHT);

bool copy_to_vram = true;
// Only apply triggered post-processing on specific formats, to avoid false positives.
Expand All @@ -1257,7 +1263,7 @@ void TextureCacheBase::CopyRenderTargetToTexture(u32 dstAddr, u32 dstFormat, u32
{
if (srcFormat != PEControl::Z24 && !isIntensity && dstFormat >= 4 && dstFormat <= 6)
{
const TargetRectangle targetSource = g_renderer->ConvertEFBRectangle(srcRect);
const TargetRectangle targetSource = g_renderer->ConvertEFBRectangle(rectifiedRect);
g_renderer->GetPostProcessor()->OnEFBCopy(&targetSource);
}
}
Expand Down Expand Up @@ -1350,7 +1356,7 @@ void TextureCacheBase::CopyRenderTargetToTexture(u32 dstAddr, u32 dstFormat, u32
entry->SetEfbCopy(dstStride);
entry->is_custom_tex = false;

entry->FromRenderTarget(dst, srcFormat, srcRect, scaleByHalf, cbufid, colmat);
entry->FromRenderTarget(dst, srcFormat, rectifiedRect, scaleByHalf, cbufid, colmat);

u64 hash = entry->CalculateHash();
entry->SetHashes(hash, hash);
Expand Down

0 comments on commit 3858113

Please sign in to comment.