Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #622 from phire/sw-fix-frame-dump
Fixed Frame dumping in VideoSoftware.
  • Loading branch information
dolphin-emu-bot committed Jul 17, 2014
2 parents 8cf21cd + 92eed47 commit 51dff5a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 32 deletions.
37 changes: 11 additions & 26 deletions Source/Core/VideoBackends/Software/DebugUtil.cpp
Expand Up @@ -11,6 +11,7 @@
#include "VideoBackends/Software/EfbInterface.h"
#include "VideoBackends/Software/HwRasterizer.h"
#include "VideoBackends/Software/SWCommandProcessor.h"
#include "VideoBackends/Software/SWRenderer.h"
#include "VideoBackends/Software/SWStatistics.h"
#include "VideoBackends/Software/SWVideoConfig.h"
#include "VideoBackends/Software/TextureSampler.h"
Expand Down Expand Up @@ -66,7 +67,7 @@ static void SaveTexture(const std::string& filename, u32 texmap, s32 mip)

GetTextureRGBA(data, texmap, mip, width, height);

(void)TextureToPng(data, width*4, filename, width, height, true);
TextureToPng(data, width*4, filename, width, height, true);
delete[] data;

}
Expand Down Expand Up @@ -150,30 +151,15 @@ static void DumpEfb(const std::string& filename)
}
}

(void)TextureToPng(data, EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true);
TextureToPng(data, EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true);
delete[] data;
}

static void DumpDepth(const std::string& filename)
{
u8 *data = new u8[EFB_WIDTH * EFB_HEIGHT * 4];
u8 *writePtr = data;

for (int y = 0; y < EFB_HEIGHT; y++)
{
for (int x = 0; x < EFB_WIDTH; x++)
{
u32 depth = EfbInterface::GetDepth(x, y);
// depth to rgba
*(writePtr++) = depth & 0xff;
*(writePtr++) = (depth >> 8) & 0xff;
*(writePtr++) = (depth >> 16) & 0xff;
*(writePtr++) = 255;
}
}

(void)TextureToPng(data, EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true);
delete[] data;
static void DumpColorTexture(const std::string& filename, u32 width, u32 height)
{
TextureToPng(SWRenderer::getCurrentColorTexture(), width * 4, filename, width, height, true);
}

void DrawObjectBuffer(s16 x, s16 y, u8 *color, int bufferBase, int subBuffer, const char *name)
Expand Down Expand Up @@ -252,7 +238,7 @@ void OnObjectEnd()
File::GetUserPath(D_DUMPFRAMES_IDX).c_str(),
swstats.thisFrame.numDrawnObjects, ObjectBufferName[i], i - BufferBase[i]);

(void)TextureToPng((u8*)ObjectBuffer[i], EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true);
TextureToPng((u8*)ObjectBuffer[i], EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true);
memset(ObjectBuffer[i], 0, EFB_WIDTH * EFB_HEIGHT * sizeof(u32));

}
Expand All @@ -262,16 +248,15 @@ void OnObjectEnd()
}
}

void OnFrameEnd()
// If frame dumping is enabled, dump whatever is drawn to the screen.
void OnFrameEnd(u32 width, u32 height)
{
if (!g_bSkipCurrentFrame)
{
if (g_SWVideoConfig.bDumpFrames)
{
DumpEfb(StringFromFormat("%sframe%i_color.png",
File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), swstats.frameCount));
DumpDepth(StringFromFormat("%sframe%i_depth.png",
File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), swstats.frameCount));
DumpColorTexture(StringFromFormat("%sframe%i_color.png",
File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), swstats.frameCount), width, height);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Software/DebugUtil.h
Expand Up @@ -16,7 +16,7 @@ namespace DebugUtil
void OnObjectBegin();
void OnObjectEnd();

void OnFrameEnd();
void OnFrameEnd(u32 width, u32 height);

void DrawObjectBuffer(s16 x, s16 y, u8 *color, int bufferBase, int subBuffer, const char *name);

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Software/EfbCopy.cpp
Expand Up @@ -44,7 +44,7 @@ namespace EfbCopy
else
{
// Ask SWRenderer for the next color texture
u8 *colorTexture = SWRenderer::getColorTexture();
u8 *colorTexture = SWRenderer::getNextColorTexture();

EfbInterface::BypassXFB(colorTexture, fbWidth, fbHeight, sourceRc, Gamma);

Expand Down
10 changes: 7 additions & 3 deletions Source/Core/VideoBackends/Software/SWRenderer.cpp
Expand Up @@ -152,10 +152,14 @@ void SWRenderer::DrawDebugText()
SWRenderer::RenderText(debugtext.c_str(), 20, 20, 0xFFFFFF00);
}

u8* SWRenderer::getColorTexture() {
u8* SWRenderer::getNextColorTexture() {
return s_xfbColorTexture[!s_currentColorTexture];
}

u8* SWRenderer::getCurrentColorTexture() {
return s_xfbColorTexture[s_currentColorTexture];
}

void SWRenderer::swapColorTexture() {
s_currentColorTexture = !s_currentColorTexture;
}
Expand All @@ -168,7 +172,7 @@ void SWRenderer::UpdateColorTexture(EfbInterface::yuv422_packed *xfb, u32 fbWidt
}

u32 offset = 0;
u8 *TexturePointer = getColorTexture();
u8 *TexturePointer = getNextColorTexture();

for (u16 y = 0; y < fbHeight; y++)
{
Expand Down Expand Up @@ -202,7 +206,7 @@ void SWRenderer::Swap(u32 fbWidth, u32 fbHeight)
{
GLInterface->Update(); // just updates the render window position and the backbuffer size
if (!g_SWVideoConfig.bHwRasterizer)
SWRenderer::DrawTexture(s_xfbColorTexture[s_currentColorTexture], fbWidth, fbHeight);
SWRenderer::DrawTexture(getCurrentColorTexture(), fbWidth, fbHeight);

swstats.frameCount++;
SWRenderer::SwapBuffer();
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/VideoBackends/Software/SWRenderer.h
Expand Up @@ -18,7 +18,8 @@ namespace SWRenderer
void RenderText(const char* pstr, int left, int top, u32 color);
void DrawDebugText();

u8* getColorTexture();
u8* getNextColorTexture();
u8* getCurrentColorTexture();
void swapColorTexture();
void UpdateColorTexture(EfbInterface::yuv422_packed *xfb, u32 fbWidth, u32 fbHeight);
void DrawTexture(u8 *texture, int width, int height);
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/VideoBackends/Software/SWmain.cpp
Expand Up @@ -232,6 +232,9 @@ void VideoSoftware::Video_EndField()
}
}

// Dump frame if needed
DebugUtil::OnFrameEnd(s_beginFieldArgs.fbWidth, s_beginFieldArgs.fbHeight);

// Ideally we would just move all the OpenGL context stuff to the CPU thread,
// but this gets messy when the hardware rasterizer is enabled.
// And neobrain loves his hardware rasterizer.
Expand Down

0 comments on commit 51dff5a

Please sign in to comment.