Merge pull request #293 from unknownbrackets/headless

Headless w/GLES GPU
This commit is contained in:
Henrik Rydgård committed 2012-12-30 02:12:15 -08:00
commit 349b60cbbd
11 files changed
+328 -61

No files matched your search

+1 -1
View File
@@ -886,7 +886,7 @@ if(WIN32)
endif()
if(HEADLESS)
add_executable(PPSSPPHeadless headless/Headless.cpp)
add_executable(PPSSPPHeadless headless/Headless.cpp headless/StubHost.h)
target_link_libraries(PPSSPPHeadless ${CoreLibName}
${COCOA_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
setup_target_project(PPSSPPHeadless headless)
+2 -12
View File
@@ -22,6 +22,7 @@
#include "../System.h"
#include "../Config.h"
#include "../Host.h"
#include "../SaveState.h"
#include "HLE.h"
#include "../MIPS/MIPS.h"
@@ -77,12 +78,6 @@ typedef s32 SceMode;
typedef s64 SceOff;
typedef u64 SceIores;
std::string emuDebugOutput;
const std::string &EmuDebugOutput() {
return emuDebugOutput;
}
typedef u32 (*DeferredAction)(SceUID id, int param);
DeferredAction defAction = 0;
u32 defParam = 0;
@@ -644,12 +639,7 @@ u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 outPtr,
std::string data(Memory::GetCharPointer(argAddr), argLen);
if (PSP_CoreParameter().printfEmuLog)
{
printf("%s", data.c_str());
#ifdef _WIN32
OutputDebugString(data.c_str());
#endif
// Also collect the debug output
emuDebugOutput += data;
host->SendDebugOutput(data.c_str());
}
else
{
-2
View File
@@ -29,5 +29,3 @@ KernelObject *__KernelDirListingObject();
void Register_IoFileMgrForUser();
void Register_StdioForUser();
const std::string &EmuDebugOutput();
+4 -6
View File
@@ -182,20 +182,18 @@ bool __KernelIsRunning() {
void sceKernelExitGame()
{
INFO_LOG(HLE,"sceKernelExitGame");
if (PSP_CoreParameter().headLess)
exit(0);
else
if (!PSP_CoreParameter().headLess)
PanicAlert("Game exited");
__KernelSwitchOffThread("game exited");
Core_Stop();
}
void sceKernelExitGameWithStatus()
{
INFO_LOG(HLE,"sceKernelExitGameWithStatus");
if (PSP_CoreParameter().headLess)
exit(0);
else
if (!PSP_CoreParameter().headLess)
PanicAlert("Game exited (with status)");
__KernelSwitchOffThread("game exited");
Core_Stop();
}
+3
View File
@@ -60,6 +60,9 @@ public:
virtual bool IsDebuggingEnabled() {return true;}
virtual bool AttemptLoadSymbolMap() {return false;}
virtual void SetWindowTitle(const char *message) {}
// Used for headless.
virtual void SendDebugOutput(const std::string &output) {}
};
extern Host *host;
+29 -38
View File
@@ -13,34 +13,10 @@
#include "Log.h"
#include "LogManager.h"
// TODO: Get rid of this junk
class HeadlessHost : public Host
{
public:
// virtual void StartThread()
virtual void UpdateUI() {}
virtual void UpdateMemView() {}
virtual void UpdateDisassembly() {}
virtual void SetDebugMode(bool mode) { }
virtual void InitGL() {}
virtual void BeginFrame() {}
virtual void EndFrame() {}
virtual void ShutdownGL() {}
virtual void InitSound(PMixer *mixer) {}
virtual void UpdateSound() {}
virtual void ShutdownSound() {}
// this is sent from EMU thread! Make sure that Host handles it properly!
virtual void BootDone() {}
virtual void PrepareShutdown() {}
virtual bool IsDebuggingEnabled() {return false;}
virtual bool AttemptLoadSymbolMap() {return false;}
};
#include "StubHost.h"
#ifdef _WIN32
#include "WindowsHeadlessHost.h"
#endif
class PrintfLogger : public LogListener
{
@@ -50,20 +26,20 @@ public:
switch (level)
{
case LogTypes::LDEBUG:
printf("D %s", msg);
fprintf(stderr, "D %s", msg);
break;
case LogTypes::LINFO:
printf("I %s", msg);
fprintf(stderr, "I %s", msg);
break;
case LogTypes::LERROR:
printf("E %s", msg);
fprintf(stderr, "E %s", msg);
break;
case LogTypes::LWARNING:
printf("W %s", msg);
fprintf(stderr, "W %s", msg);
break;
case LogTypes::LNOTICE:
default:
printf("N %s", msg);
fprintf(stderr, "N %s", msg);
break;
}
}
@@ -79,6 +55,12 @@ void printUsage(const char *progname, const char *reason)
fprintf(stderr, "Options:\n");
fprintf(stderr, " -m, --mount umd.cso mount iso on umd:\n");
fprintf(stderr, " -l, --log full log output, not just emulated printfs\n");
HEADLESSHOST_CLASS h1;
HeadlessHost h2;
if (typeid(h1) != typeid(h2))
fprintf(stderr, " --graphics use the full gpu backend (slower)\n");
fprintf(stderr, " -f use the fast interpreter\n");
fprintf(stderr, " -j use jit (overrides -f)\n");
fprintf(stderr, " -c, --compare compare with output in file.expected\n");
@@ -91,6 +73,7 @@ int main(int argc, const char* argv[])
bool useJit = false;
bool fastInterpreter = false;
bool autoCompare = false;
bool useGraphics = false;
const char *bootFilename = 0;
const char *mountIso = 0;
@@ -114,6 +97,8 @@ int main(int argc, const char* argv[])
fastInterpreter = true;
else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--compare"))
autoCompare = true;
else if (!strcmp(argv[i], "--graphics"))
useGraphics = true;
else if (bootFilename == 0)
bootFilename = argv[i];
else
@@ -140,7 +125,9 @@ int main(int argc, const char* argv[])
return 1;
}
host = new HeadlessHost();
HeadlessHost *headlessHost = useGraphics ? new HEADLESSHOST_CLASS() : new HeadlessHost();
host = headlessHost;
host->InitGL();
LogManager::Init();
LogManager *logman = LogManager::GetInstance();
@@ -160,7 +147,7 @@ int main(int argc, const char* argv[])
coreParameter.mountIso = mountIso ? mountIso : "";
coreParameter.startPaused = false;
coreParameter.cpuCore = useJit ? CPU_JIT : (fastInterpreter ? CPU_FASTINTERPRETER : CPU_INTERPRETER);
coreParameter.gpuCore = GPU_NULL;
coreParameter.gpuCore = headlessHost->isGLWorking() ? GPU_GLES : GPU_NULL;
coreParameter.enableSound = false;
coreParameter.headLess = true;
coreParameter.printfEmuLog = true;
@@ -177,8 +164,9 @@ int main(int argc, const char* argv[])
return 1;
}
coreState = CORE_RUNNING;
host->BootDone();
coreState = CORE_RUNNING;
while (coreState == CORE_RUNNING)
{
// Run for a frame at a time, just because.
@@ -191,10 +179,13 @@ int main(int argc, const char* argv[])
coreState = CORE_RUNNING;
}
// NOTE: we won't get here until I've gotten rid of the exit(0) in sceExitProcess or whatever it's called
host->ShutdownGL();
PSP_Shutdown();
delete host;
host = NULL;
headlessHost = NULL;
if (autoCompare)
{
std::string expect_filename = std::string(bootFilename).substr(strlen(bootFilename - 4)) + ".expected";
+7 -2
View File
@@ -81,7 +81,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../Common;..;../Core;../native/ext/glew;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../Common;..;../Core;../native/ext/glew;../native</AdditionalIncludeDirectories>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
</ClCompile>
<Link>
@@ -112,7 +112,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../Common;..;../Core;../native/ext/glew;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../Common;..;../Core;../native/ext/glew;../native</AdditionalIncludeDirectories>
<BufferSecurityCheck>false</BufferSecurityCheck>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
@@ -151,6 +151,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="WindowsHeadlessHost.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="headless.txt" />
@@ -175,6 +176,10 @@
<Project>{f761046e-6c38-4428-a5f1-38391a37bb34}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClInclude Include="StubHost.h" />
<ClInclude Include="WindowsHeadlessHost.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
+5
View File
@@ -3,8 +3,13 @@
<ItemGroup>
<ClCompile Include="Headless.cpp" />
<ClCompile Include="..\native\ext\glew\glew.c" />
<ClCompile Include="WindowsHeadlessHost.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="headless.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="StubHost.h" />
<ClInclude Include="WindowsHeadlessHost.h" />
</ItemGroup>
</Project>
+55
View File
@@ -0,0 +1,55 @@
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
#include "../Core/Host.h"
#define HEADLESSHOST_CLASS HeadlessHost
// TODO: Get rid of this junk
class HeadlessHost : public Host
{
public:
// virtual void StartThread()
virtual void UpdateUI() {}
virtual void UpdateMemView() {}
virtual void UpdateDisassembly() {}
virtual void SetDebugMode(bool mode) { }
virtual void InitGL() {}
virtual void BeginFrame() {}
virtual void EndFrame() {}
virtual void ShutdownGL() {}
virtual void InitSound(PMixer *mixer) {}
virtual void UpdateSound() {}
virtual void ShutdownSound() {}
// this is sent from EMU thread! Make sure that Host handles it properly
virtual void BootDone() {}
virtual void PrepareShutdown() {}
virtual bool IsDebuggingEnabled() {return false;}
virtual bool AttemptLoadSymbolMap() {return false;}
virtual void SendDebugOutput(const std::string &output) { printf("%s", output.c_str()); }
virtual bool isGLWorking() { return false; }
};
+174
View File
@@ -0,0 +1,174 @@
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "WindowsHeadlessHost.h"
#include <stdio.h>
#include <windows.h>
#include <io.h>
#include "gfx_es2/gl_state.h"
#include "gfx/gl_common.h"
#include "gfx/gl_lost_manager.h"
#include "file/vfs.h"
#include "file/zip_read.h"
const bool WINDOW_VISIBLE = false;
const int WINDOW_WIDTH = 480;
const int WINDOW_HEIGHT = 272;
typedef BOOL (APIENTRY *PFNWGLSWAPINTERVALFARPROC)(int value);
PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = NULL;
HWND CreateHiddenWindow()
{
static WNDCLASSEX wndClass = {
sizeof(WNDCLASSEX),
CS_HREDRAW | CS_VREDRAW | CS_OWNDC,
DefWindowProc,
0,
0,
NULL,
NULL,
LoadCursor(NULL, IDC_ARROW),
(HBRUSH) GetStockObject(BLACK_BRUSH),
NULL,
"PPSSPPHeadless",
NULL,
};
RegisterClassEx(&wndClass);
DWORD style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP;
return CreateWindowEx(0, "PPSSPPHeadless", "PPSSPPHeadless", style, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, NULL, NULL);
}
void SetVSync(int value)
{
const char *extensions = (const char *) glGetString(GL_EXTENSIONS);
if (!strstr(extensions, "WGL_EXT_swap_control"))
return;
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC) wglGetProcAddress("wglSwapIntervalEXT");
if (wglSwapIntervalEXT != NULL)
wglSwapIntervalEXT(value);
}
void WindowsHeadlessHost::LoadNativeAssets()
{
// Native is kinda talkative, but that's annoying in our case.
out = _fdopen(_dup(_fileno(stdout)), "wt");
freopen("NUL", "wt", stdout);
VFSRegister("", new DirectoryAssetReader("assets/"));
VFSRegister("", new DirectoryAssetReader(""));
VFSRegister("", new DirectoryAssetReader("../"));
gl_lost_manager_init();
// See SendDebugOutput() for how things get back on track.
}
void WindowsHeadlessHost::SendDebugOutput(const std::string &output)
{
fprintf_s(out, "%s", output.c_str());
OutputDebugString(output.c_str());
}
void WindowsHeadlessHost::InitGL()
{
glOkay = false;
hWnd = CreateHiddenWindow();
if (WINDOW_VISIBLE)
{
ShowWindow(hWnd, TRUE);
SetFocus(hWnd);
}
int pixelFormat;
static PIXELFORMATDESCRIPTOR pfd = {0};
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
#define ENFORCE(x, msg) { if (!(x)) { fprintf(stderr, msg); return; } }
ENFORCE(hDC = GetDC(hWnd), "Unable to create DC.");
ENFORCE(pixelFormat = ChoosePixelFormat(hDC, &pfd), "Unable to match pixel format.");
ENFORCE(SetPixelFormat(hDC, pixelFormat, &pfd), "Unable to set pixel format.");
ENFORCE(hRC = wglCreateContext(hDC), "Unable to create GL context.");
ENFORCE(wglMakeCurrent(hDC, hRC), "Unable to activate GL context.");
SetVSync(0);
glewInit();
glstate.Initialize();
LoadNativeAssets();
if (ResizeGL())
glOkay = true;
}
void WindowsHeadlessHost::ShutdownGL()
{
if (hRC)
{
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hRC);
hRC = NULL;
}
if (hDC)
ReleaseDC(hWnd, hDC);
hDC = NULL;
DestroyWindow(hWnd);
hWnd = NULL;
}
bool WindowsHeadlessHost::ResizeGL()
{
if (!hWnd)
return false;
RECT rc;
GetWindowRect(hWnd, &rc);
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, WINDOW_WIDTH, WINDOW_HEIGHT, 0.0f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
return true;
}
void WindowsHeadlessHost::BeginFrame()
{
}
void WindowsHeadlessHost::EndFrame()
{
SwapBuffers(hDC);
}
+48
View File
@@ -0,0 +1,48 @@
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
#include "StubHost.h"
#undef HEADLESSHOST_CLASS
#define HEADLESSHOST_CLASS WindowsHeadlessHost
#include <windows.h>
// TODO: Get rid of this junk
class WindowsHeadlessHost : public HeadlessHost
{
public:
virtual void InitGL();
virtual void BeginFrame();
virtual void EndFrame();
virtual void ShutdownGL();
virtual bool isGLWorking() { return glOkay; }
virtual void SendDebugOutput(const std::string &output);
private:
bool ResizeGL();
void LoadNativeAssets();
bool glOkay;
HWND hWnd;
HDC hDC;
HGLRC hRC;
FILE *out;
};