Skip to content

Commit

Permalink
Fix D3D crashes/issues
Browse files Browse the repository at this point in the history
  • Loading branch information
RisingFog committed Jun 27, 2016
1 parent 88dbaf1 commit f31adf9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 34 deletions.
23 changes: 6 additions & 17 deletions Source/Core/VideoBackends/D3D/Render.cpp
Expand Up @@ -880,12 +880,8 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
}

// Dump frames
static int w = 0, h = 0;
if (SConfig::GetInstance().m_DumpFrames)
{
static int s_recordWidth;
static int s_recordHeight;

if (!s_screenshot_texture)
CreateScreenshotTexture();

Expand All @@ -897,9 +893,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
&source_box);
if (!bLastFrameDumped)
{
s_recordWidth = source_width;
s_recordHeight = source_height;
bAVIDumping = AVIDump::Start(s_recordWidth, s_recordHeight, AVIDump::DumpFormat::FORMAT_BGR);
bAVIDumping = AVIDump::Start(source_width, source_height, AVIDump::DumpFormat::FORMAT_BGR);
if (!bAVIDumping)
{
PanicAlert("Error dumping frames to AVI.");
Expand All @@ -908,7 +902,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
{
std::string msg = StringFromFormat("Dumping Frames to \"%sframedump0.avi\" (%dx%d RGB24)",
File::GetUserPath(D_DUMPFRAMES_IDX).c_str(),
s_recordWidth, s_recordHeight);
source_width, source_height);

OSD::AddMessage(msg, 2000);
}
Expand All @@ -918,14 +912,11 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
D3D11_MAPPED_SUBRESOURCE map;
D3D::context->Map(s_screenshot_texture, 0, D3D11_MAP_READ, 0, &map);

if (frame_data.empty() || w != s_recordWidth || h != s_recordHeight)
{
frame_data.resize(3 * s_recordWidth * s_recordHeight);
w = s_recordWidth;
h = s_recordHeight;
}
if (frame_data.capacity() != 3 * source_width * source_height)
frame_data.resize(3 * source_width * source_height);

formatBufferDump((u8*)map.pData, &frame_data[0], source_width, source_height, map.RowPitch);
FlipImageData(&frame_data[0], w, h);
FlipImageData(&frame_data[0], source_width, source_height);
AVIDump::AddFrame(&frame_data[0], source_width, source_height);
D3D::context->Unmap(s_screenshot_texture, 0);
}
Expand All @@ -936,8 +927,6 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
if (bLastFrameDumped && bAVIDumping)
{
std::vector<u8>().swap(frame_data);
w = h = 0;

AVIDump::Stop();
bAVIDumping = false;
OSD::AddMessage("Stop dumping frames to AVI", 2000);
Expand Down
22 changes: 5 additions & 17 deletions Source/Core/VideoBackends/D3D12/Render.cpp
Expand Up @@ -836,12 +836,8 @@ void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height
}

// Dump frames
static int w = 0, h = 0;
if (SConfig::GetInstance().m_DumpFrames)
{
static unsigned int s_record_width;
static unsigned int s_record_height;

if (!s_screenshot_texture)
CreateScreenshotTexture();

Expand Down Expand Up @@ -875,10 +871,7 @@ void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height

if (!bLastFrameDumped)
{
s_record_width = source_width;
s_record_height = source_height;
bAVIDumping =
AVIDump::Start(s_record_width, s_record_height, AVIDump::DumpFormat::FORMAT_BGR);
bAVIDumping = AVIDump::Start(source_width, source_height, AVIDump::DumpFormat::FORMAT_BGR);
if (!bAVIDumping)
{
PanicAlert("Error dumping frames to AVI.");
Expand All @@ -887,19 +880,15 @@ void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height
{
std::string msg = StringFromFormat("Dumping Frames to \"%sframedump0.avi\" (%dx%d RGB24)",
File::GetUserPath(D_DUMPFRAMES_IDX).c_str(),
s_record_width, s_record_height);
source_width, source_height);

OSD::AddMessage(msg, 2000);
}
}
if (bAVIDumping)
{
if (frame_data.empty() || w != s_record_width || h != s_record_height)
{
frame_data.resize(3 * s_record_width * s_record_height);
w = s_record_width;
h = s_record_height;
}
if (frame_data.capacity() != 3 * source_width * source_height)
frame_data.resize(3 * source_width * source_height);

void* screenshot_texture_map;
D3D12_RANGE read_range = {0, dst_location.PlacedFootprint.Footprint.RowPitch * source_height};
Expand All @@ -910,7 +899,7 @@ void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height
D3D12_RANGE write_range = {};
s_screenshot_texture->Unmap(0, &write_range);

FlipImageData(&frame_data[0], w, h);
FlipImageData(&frame_data[0], source_width, source_height);
AVIDump::AddFrame(&frame_data[0], source_width, source_height);
}
bLastFrameDumped = true;
Expand All @@ -920,7 +909,6 @@ void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height
if (bLastFrameDumped && bAVIDumping)
{
std::vector<u8>().swap(frame_data);
w = h = 0;

AVIDump::Stop();
bAVIDumping = false;
Expand Down

0 comments on commit f31adf9

Please sign in to comment.