Make the dx9 renderer working in headless mode

This commit is contained in:
Ced2911 2013-09-16 09:42:30 +02:00
parent 9f063fcbe9
commit 5c4ed26442
8 changed files with 196 additions and 8 deletions

View file

@ -200,7 +200,7 @@ void CompileShaders() {
bool useVsync = false;
void DirectxInit() {
void DirectxInit(HWND window) {
pD3D = Direct3DCreate9( D3D_SDK_VERSION );
@ -226,10 +226,11 @@ void DirectxInit() {
// format.
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof( d3dpp ) );
#ifdef _XBOX
d3dpp.BackBufferWidth = 1280;
d3dpp.BackBufferHeight = 720;
d3dpp.BackBufferFormat = ( D3DFORMAT )( D3DFMT_A8R8G8B8 );
#ifdef _XBOX
d3dpp.FrontBufferFormat = ( D3DFORMAT )( D3DFMT_LE_A8R8G8B8 );
#else
// TODO?
@ -244,8 +245,8 @@ void DirectxInit() {
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
//d3dpp.PresentationInterval = (useVsync == true)?D3DPRESENT_INTERVAL_ONE:D3DPRESENT_INTERVAL_IMMEDIATE;
//d3dpp.RingBufferParameters = d3dr;
HRESULT hr = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL,
HRESULT hr = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp, &pD3Ddevice);
if (hr != D3D_OK) {

View file

@ -24,7 +24,7 @@ extern IDirect3DVertexDeclaration9* pSoftVertexDecl;
bool CompilePixelShader(const char * code, LPDIRECT3DPIXELSHADER9 * pShader, LPD3DXCONSTANTTABLE * pShaderTable);
bool CompileVertexShader(const char * code, LPDIRECT3DVERTEXSHADER9 * pShader, LPD3DXCONSTANTTABLE * pShaderTable);
void DirectxInit();
void DirectxInit(HWND window);
#define D3DBLEND_UNK D3DSTENCILOP_FORCE_DWORD

View file

@ -54,7 +54,6 @@ bool GPU_Init() {
#if defined(_XBOX)
gpu = new DIRECTX9_GPU();
#elif defined(_WIN32)
DX9::DirectxInit();
gpu = new DIRECTX9_GPU();
#endif
break;

View file

@ -20,6 +20,7 @@
#ifdef _WIN32
#include "Windows/OpenGLBase.h"
#include "WindowsHeadlessHost.h"
#include "WindowsHeadlessHostDx9.h"
#endif
class PrintfLogger : public LogListener
@ -90,6 +91,17 @@ void printUsage(const char *progname, const char *reason)
fprintf(stderr, "\nSee headless.txt for details.\n");
}
static HeadlessHost * getHost(GPUCore gpuCore) {
switch(gpuCore) {
case GPU_NULL:
return new HeadlessHost();
case GPU_DIRECTX9:
return new WindowsHeadlessHostDx9();
default:
return new HEADLESSHOST_CLASS();
}
}
int main(int argc, const char* argv[])
{
bool fullLog = false;
@ -168,7 +180,7 @@ int main(int argc, const char* argv[])
return 1;
}
HeadlessHost *headlessHost = gpuCore != GPU_NULL ? new HEADLESSHOST_CLASS() : new HeadlessHost();
HeadlessHost *headlessHost = getHost(gpuCore);
host = headlessHost;
std::string error_string;
@ -211,7 +223,7 @@ int main(int argc, const char* argv[])
// Never report from tests.
g_Config.sReportHost = "";
g_Config.bAutoSaveSymbolMap = false;
g_Config.iRenderingMode = true;
g_Config.iRenderingMode = 0;
g_Config.bHardwareTransform = true;
#ifdef USING_GLES2
g_Config.iAnisotropyLevel = 0;

View file

@ -65,6 +65,8 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<LibraryPath>..\dx9sdk\Lib\x86;$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;$(FrameworkSDKDir)\lib</LibraryPath>
<IncludePath>..\dx9sdk\Include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
@ -187,6 +189,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="WindowsHeadlessHost.cpp" />
<ClCompile Include="WindowsHeadlessHostDx9.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="headless.txt" />
@ -216,6 +219,7 @@
<ClInclude Include="Compare.h" />
<ClInclude Include="StubHost.h" />
<ClInclude Include="WindowsHeadlessHost.h" />
<ClInclude Include="WindowsHeadlessHostDx9.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View file

@ -6,6 +6,7 @@
<ClCompile Include="WindowsHeadlessHost.cpp" />
<ClCompile Include="Compare.cpp" />
<ClCompile Include="..\UI\OnScreenDisplay.cpp" />
<ClCompile Include="WindowsHeadlessHostDx9.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="headless.txt" />
@ -15,5 +16,6 @@
<ClInclude Include="WindowsHeadlessHost.h" />
<ClInclude Include="Compare.h" />
<ClInclude Include="..\UI\OnScreenDisplay.h" />
<ClInclude Include="WindowsHeadlessHostDx9.h" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,121 @@
// 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 "WindowsHeadlessHostDx9.h"
#include "Compare.h"
#include <stdio.h>
#include "Common/CommonWindows.h"
#include <io.h>
#include "base/logging.h"
#include "GPU/Directx9/helper/global.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;
HWND DxCreateWindow()
{
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,
_T("PPSSPPHeadless"),
NULL,
};
RegisterClassEx(&wndClass);
DWORD style = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
return CreateWindowEx(0, _T("PPSSPPHeadless"), _T("PPSSPPHeadless"), style, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, NULL, NULL);
}
void WindowsHeadlessHostDx9::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("../"));
VFSRegister("", new DirectoryAssetReader("../Windows/assets/"));
VFSRegister("", new DirectoryAssetReader("../Windows/"));
// See SendDebugOutput() for how things get back on track.
}
void WindowsHeadlessHostDx9::SendDebugOutput(const std::string &output)
{
fwrite(output.data(), sizeof(char), output.length(), out);
OutputDebugStringUTF8(output.c_str());
}
void WindowsHeadlessHostDx9::SendDebugScreenshot(const u8 *pixbuf, u32 w, u32 h)
{
}
void WindowsHeadlessHostDx9::SetComparisonScreenshot(const std::string &filename)
{
comparisonScreenshot = filename;
}
bool WindowsHeadlessHostDx9::InitGL(std::string *error_message)
{
hWnd = DxCreateWindow();
ShowWindow(hWnd, TRUE);
SetFocus(hWnd);
DX9::DirectxInit(hWnd);
LoadNativeAssets();
DX9::pD3Ddevice->BeginScene();
return true;
}
void WindowsHeadlessHostDx9::ShutdownGL()
{
}
bool WindowsHeadlessHostDx9::ResizeGL()
{
return true;
}
void WindowsHeadlessHostDx9::SwapBuffers()
{
ShowWindow(hWnd, TRUE);
SetFocus(hWnd);
DX9::pD3Ddevice->EndScene();
DX9::pD3Ddevice->Present(0, 0, 0, 0);
DX9::pD3Ddevice->BeginScene();
}

View file

@ -0,0 +1,49 @@
// 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 "Common/CommonWindows.h"
// TODO: Get rid of this junk
class WindowsHeadlessHostDx9 : public HeadlessHost
{
public:
virtual bool InitGL(std::string *error_message);
virtual void ShutdownGL();
virtual void SwapBuffers();
virtual void SendDebugOutput(const std::string &output);
virtual void SendDebugScreenshot(const u8 *pixbuf, u32 w, u32 h);
virtual void SetComparisonScreenshot(const std::string &filename);
private:
bool ResizeGL();
void LoadNativeAssets();
HWND hWnd;
HDC hDC;
HGLRC hRC;
FILE *out;
std::string comparisonScreenshot;
};