Put some stuff in the gfx plugins into namespaces, so that the symbols won't collide if someone decides to merge the gfx plugins into dolphin too. still more things left to do though.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6972 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard
2011-01-29 20:16:51 +00:00
parent fb35a83d2c
commit 7f97ce79bb
55 changed files with 531 additions and 329 deletions

View File

@ -22,6 +22,9 @@
#include "D3DTexture.h"
#include "GfxState.h"
namespace DX11
{
HINSTANCE hD3DXDll = NULL;
D3DX11COMPILEFROMMEMORYTYPE PD3DX11CompileFromMemory = NULL;
D3DX11FILTERTEXTURETYPE PD3DX11FilterTexture = NULL;
@ -468,4 +471,6 @@ void Present()
swapchain->Present((UINT)g_ActiveConfig.bVSync, 0);
}
} // namespace
} // namespace D3D
} // namespace DX11

View File

@ -21,12 +21,16 @@
#include "Common.h"
#include <vector>
namespace DX11
{
#define SAFE_RELEASE(x) { if (x) (x)->Release(); (x) = NULL; }
#define SAFE_DELETE(x) { delete (x); (x) = NULL; }
#define SAFE_DELETE_ARRAY(x) { delete[] (x); (x) = NULL; }
#define CHECK(cond, Message, ...) if (!(cond)) { PanicAlert(__FUNCTION__ "Failed in %s at line %d: " Message, __FILE__, __LINE__, __VA_ARGS__); }
class D3DTexture2D;
namespace D3D
{
@ -100,3 +104,5 @@ typedef HRESULT (WINAPI* CREATEDXGIFACTORY)(REFIID, void**);
extern CREATEDXGIFACTORY PCreateDXGIFactory;
typedef HRESULT (WINAPI* D3D11CREATEDEVICE)(IDXGIAdapter*, D3D_DRIVER_TYPE, HMODULE, UINT, CONST D3D_FEATURE_LEVEL*, UINT, UINT, ID3D11Device**, D3D_FEATURE_LEVEL*, ID3D11DeviceContext**);
extern D3D11CREATEDEVICE PD3D11CreateDevice;
} // namespace DX11

View File

@ -18,6 +18,9 @@
#include <d3d11.h>
#include "D3DBlob.h"
namespace DX11
{
D3DBlob::D3DBlob(unsigned int blob_size, const u8* init_data) : ref(1), size(blob_size), blob(NULL)
{
data = new u8[blob_size];
@ -62,3 +65,5 @@ u8* D3DBlob::Data()
{
return data;
}
} // namespace DX11

View File

@ -21,6 +21,9 @@
struct ID3D10Blob;
namespace DX11
{
// use this class instead ID3D10Blob or ID3D11Blob whenever possible
class D3DBlob
{
@ -46,3 +49,5 @@ private:
u8* data;
ID3D10Blob* blob;
};
} // namespace

View File

@ -22,6 +22,9 @@
#include "D3DBase.h"
#include "D3DShader.h"
namespace DX11
{
namespace D3D
{
@ -149,3 +152,5 @@ ID3D11PixelShader* CompileAndCreatePixelShader(const char* code, unsigned int le
}
} // namespace
} // namespace DX11

View File

@ -22,6 +22,9 @@
struct ID3D11PixelShader;
struct ID3D11VertexShader;
namespace DX11
{
namespace D3D
{
ID3D11VertexShader* CreateVertexShaderFromByteCode(const void* bytecode, unsigned int len);
@ -39,4 +42,6 @@ namespace D3D
inline ID3D11PixelShader* CreatePixelShaderFromByteCode(D3DBlob* bytecode) { return CreatePixelShaderFromByteCode(bytecode->Data(), bytecode->Size()); }
inline ID3D11VertexShader* CompileAndCreateVertexShader(D3DBlob* code) { return CompileAndCreateVertexShader((const char*)code->Data(), code->Size()); }
inline ID3D11PixelShader* CompileAndCreatePixelShader(D3DBlob* code) { return CompileAndCreatePixelShader((const char*)code->Data(), code->Size()); }
}
}
} // namespace DX11

View File

@ -18,6 +18,9 @@
#include "D3DBase.h"
#include "D3DTexture.h"
namespace DX11
{
namespace D3D
{
@ -113,3 +116,5 @@ D3DTexture2D::~D3DTexture2D()
SAFE_RELEASE(dsv);
SAFE_RELEASE(tex);
}
} // namespace DX11

View File

@ -17,7 +17,10 @@
#pragma once
#include "d3d11.h"
#include <d3d11.h>
namespace DX11
{
namespace D3D
{
@ -53,3 +56,5 @@ private:
D3D11_BIND_FLAG bindflags;
UINT ref;
};
} // namespace DX11

View File

@ -24,6 +24,9 @@
#include "D3DShader.h"
#include "GfxState.h"
namespace DX11
{
namespace D3D
{
@ -690,4 +693,6 @@ void drawClearQuad(u32 Color, float z, ID3D11PixelShader* PShader, ID3D11VertexS
context->Draw(4, clearq_offset);
}
} // namespace
} // namespace D3D
} // namespace DX11

View File

@ -17,9 +17,12 @@
#pragma once
#include "d3d11.h"
#include <d3d11.h>
#include <MathUtil.h>
namespace DX11
{
namespace D3D
{
// Font creation flags
@ -83,3 +86,5 @@ namespace D3D
void drawClearQuad(u32 Color, float z, ID3D11PixelShader* PShader, ID3D11VertexShader* Vshader, ID3D11InputLayout* layout);
void drawColorQuad(u32 Color, float x1, float y1, float x2, float y2);
}
}

View File

@ -24,6 +24,8 @@
#include "Render.h"
#include "VertexShaderCache.h"
namespace DX11 {
FramebufferManager::Efb FramebufferManager::m_efb;
D3DTexture2D* &FramebufferManager::GetEFBColorTexture() { return m_efb.color_tex; }
@ -204,3 +206,5 @@ void XFBSource::CopyEFB(float Gamma)
D3D::context->OMSetRenderTargets(1, &FramebufferManager::GetEFBColorTexture()->GetRTV(),
FramebufferManager::GetEFBDepthTexture()->GetDSV());
}
} // namespace DX11

View File

@ -24,6 +24,8 @@
#include "D3DTexture.h"
namespace DX11 {
// On the GameCube, the game sends a request for the graphics processor to
// transfer its internal EFB (Embedded Framebuffer) to an area in GameCube RAM
// called the XFB (External Framebuffer). The size and location of the XFB is
@ -105,4 +107,6 @@ private:
} m_efb;
};
} // namespace DX11
#endif

View File

@ -20,6 +20,9 @@
#include "D3DBase.h"
#include "GfxState.h"
namespace DX11
{
namespace D3D
{
@ -86,3 +89,5 @@ void StateManager::Apply()
}
} // namespace
} // namespace DX11

View File

@ -23,6 +23,9 @@ struct ID3D11BlendState;
struct ID3D11DepthStencilState;
struct ID3D11RasterizerState;
namespace DX11
{
namespace D3D
{
@ -73,3 +76,5 @@ private:
extern StateManager* stateman;
} // namespace
} // namespace DX11

View File

@ -27,7 +27,7 @@ class D3DVertexFormat : public NativeVertexFormat
D3D11_INPUT_ELEMENT_DESC m_elems[32];
UINT m_num_elems;
D3DBlob* m_vs_bytecode;
DX11::D3DBlob* m_vs_bytecode;
ID3D11InputLayout* m_layout;
public:
@ -141,17 +141,17 @@ void D3DVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl)
void D3DVertexFormat::SetupVertexPointers()
{
if (m_vs_bytecode != VertexShaderCache::GetActiveShaderBytecode())
if (m_vs_bytecode != DX11::VertexShaderCache::GetActiveShaderBytecode())
{
SAFE_RELEASE(m_vs_bytecode);
SAFE_RELEASE(m_layout);
m_vs_bytecode = VertexShaderCache::GetActiveShaderBytecode();
m_vs_bytecode = DX11::VertexShaderCache::GetActiveShaderBytecode();
m_vs_bytecode->AddRef();
HRESULT hr = D3D::device->CreateInputLayout(m_elems, m_num_elems, m_vs_bytecode->Data(), m_vs_bytecode->Size(), &m_layout);
HRESULT hr = DX11::D3D::device->CreateInputLayout(m_elems, m_num_elems, m_vs_bytecode->Data(), m_vs_bytecode->Size(), &m_layout);
if (FAILED(hr)) PanicAlert("Failed to create input layout, %s %d\n", __FILE__, __LINE__);
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_layout, "input layout used to emulate the GX pipeline");
DX11::D3D::SetDebugObjectName((ID3D11DeviceChild*)m_layout, "input layout used to emulate the GX pipeline");
}
D3D::context->IASetInputLayout(m_layout);
DX11::D3D::context->IASetInputLayout(m_layout);
}

View File

@ -30,6 +30,14 @@
extern int frameCount;
// See comment near the bottom of this file.
float psconstants[C_PENVCONST_END*4];
bool pscbufchanged = true;
namespace DX11
{
PixelShaderCache::PSCache PixelShaderCache::PixelShaders;
const PixelShaderCache::PSCacheEntry* PixelShaderCache::last_entry;
@ -39,9 +47,6 @@ ID3D11PixelShader* s_ColorMatrixProgram[2] = {NULL};
ID3D11PixelShader* s_ColorCopyProgram[2] = {NULL};
ID3D11PixelShader* s_DepthMatrixProgram[2] = {NULL};
ID3D11PixelShader* s_ClearProgram = NULL;
float psconstants[C_PENVCONST_END*4];
bool pscbufchanged = true;
ID3D11Buffer* pscbuf = NULL;
const char clear_program_code[] = {
@ -205,49 +210,6 @@ ID3D11PixelShader* PixelShaderCache::GetClearProgram()
return s_ClearProgram;
}
// HACK to avoid some invasive VideoCommon changes
// these values are hardcoded, they depend on internal D3DCompile behavior; TODO: Solve this with D3DReflect or something
// offset given in floats, table index is float4
unsigned int ps_constant_offset_table[] = {
0, 4, 8, 12, // C_COLORS, 16
16, 20, 24, 28, // C_KCOLORS, 16
32, // C_ALPHA, 4
36, 40, 44, 48, 52, 56, 60, 64, // C_TEXDIMS, 32
68, 72, // C_ZBIAS, 8
76, 80, // C_INDTEXSCALE, 8
84, 88, 92, 96, 100, 104, // C_INDTEXMTX, 24
108, 112, 116, // C_FOG, 12
120, 124, 128, 132, 136, // C_PLIGHTS0, 20
140, 144, 148, 152, 156, // C_PLIGHTS1, 20
160, 164, 168, 172, 176, // C_PLIGHTS2, 20
180, 184, 188, 192, 196, // C_PLIGHTS3, 20
200, 204, 208, 212, 216, // C_PLIGHTS4, 20
220, 224, 228, 232, 236, // C_PLIGHTS5, 20
240, 244, 248, 252, 256, // C_PLIGHTS6, 20
260, 264, 268, 272, 276, // C_PLIGHTS7, 20
280, 284, 288, 292 // C_PMATERIALS, 16
};
void SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
psconstants[ps_constant_offset_table[const_number] ] = f1;
psconstants[ps_constant_offset_table[const_number]+1] = f2;
psconstants[ps_constant_offset_table[const_number]+2] = f3;
psconstants[ps_constant_offset_table[const_number]+3] = f4;
pscbufchanged = true;
}
void SetPSConstant4fv(unsigned int const_number, const float* f)
{
memcpy(&psconstants[ps_constant_offset_table[const_number]], f, sizeof(float)*4);
pscbufchanged = true;
}
void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float* f)
{
memcpy(&psconstants[ps_constant_offset_table[const_number]], f, sizeof(float)*4*count);
pscbufchanged = true;
}
ID3D11Buffer* &PixelShaderCache::GetConstantBuffer()
{
// TODO: divide the global variables of the generated shaders into about 5 constant buffers to speed this up
@ -422,4 +384,53 @@ bool PixelShaderCache::InsertByteCode(const PIXELSHADERUID &uid, const void* byt
INCSTAT(stats.numPixelShadersCreated);
SETSTAT(stats.numPixelShadersAlive, PixelShaders.size());
return true;
}
}
} // DX11
// These are "callbacks" from VideoCommon and thus must be outside namespace DX11.
// This will have to be changed when we merge.
// HACK to avoid some invasive VideoCommon changes
// these values are hardcoded, they depend on internal D3DCompile behavior; TODO: Solve this with D3DReflect or something
// offset given in floats, table index is float4
static const unsigned int ps_constant_offset_table[] = {
0, 4, 8, 12, // C_COLORS, 16
16, 20, 24, 28, // C_KCOLORS, 16
32, // C_ALPHA, 4
36, 40, 44, 48, 52, 56, 60, 64, // C_TEXDIMS, 32
68, 72, // C_ZBIAS, 8
76, 80, // C_INDTEXSCALE, 8
84, 88, 92, 96, 100, 104, // C_INDTEXMTX, 24
108, 112, 116, // C_FOG, 12
120, 124, 128, 132, 136, // C_PLIGHTS0, 20
140, 144, 148, 152, 156, // C_PLIGHTS1, 20
160, 164, 168, 172, 176, // C_PLIGHTS2, 20
180, 184, 188, 192, 196, // C_PLIGHTS3, 20
200, 204, 208, 212, 216, // C_PLIGHTS4, 20
220, 224, 228, 232, 236, // C_PLIGHTS5, 20
240, 244, 248, 252, 256, // C_PLIGHTS6, 20
260, 264, 268, 272, 276, // C_PLIGHTS7, 20
280, 284, 288, 292 // C_PMATERIALS, 16
};
void SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
psconstants[ps_constant_offset_table[const_number] ] = f1;
psconstants[ps_constant_offset_table[const_number]+1] = f2;
psconstants[ps_constant_offset_table[const_number]+2] = f3;
psconstants[ps_constant_offset_table[const_number]+3] = f4;
pscbufchanged = true;
}
void SetPSConstant4fv(unsigned int const_number, const float* f)
{
memcpy(&psconstants[ps_constant_offset_table[const_number]], f, sizeof(float)*4);
pscbufchanged = true;
}
void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float* f)
{
memcpy(&psconstants[ps_constant_offset_table[const_number]], f, sizeof(float)*4*count);
pscbufchanged = true;
}

View File

@ -24,6 +24,8 @@
class PIXELSHADERUID;
enum DSTALPHA_MODE;
namespace DX11 {
class PixelShaderCache
{
public:
@ -58,3 +60,5 @@ private:
static PSCache PixelShaders;
static const PSCacheEntry* last_entry;
};
} // namespace DX11

View File

@ -40,6 +40,9 @@
#include "VertexShaderCache.h"
namespace DX11
{
static int s_fps = 0;
static u32 s_LastAA = 0;
@ -305,9 +308,6 @@ void TeardownDeviceObjects()
SAFE_RELEASE(resetraststate);
}
namespace DX11
{
Renderer::Renderer()
{
int x, y, w_temp, h_temp;
@ -1340,4 +1340,4 @@ void Renderer::SetInterlacingMode()
// TODO
}
}
} // namespace DX11

View File

@ -26,6 +26,13 @@
#include "Globals.h"
#include "VertexShaderCache.h"
// See comment near the bottom of this file
static unsigned int vs_constant_offset_table[C_VENVCONST_END];
float vsconstants[C_VENVCONST_END*4];
bool vscbufchanged = true;
namespace DX11 {
VertexShaderCache::VSCache VertexShaderCache::vshaders;
const VertexShaderCache::VSCacheEntry *VertexShaderCache::last_entry;
@ -41,43 +48,8 @@ ID3D11VertexShader* VertexShaderCache::GetClearVertexShader() { return ClearVert
ID3D11InputLayout* VertexShaderCache::GetSimpleInputLayout() { return SimpleLayout; }
ID3D11InputLayout* VertexShaderCache::GetClearInputLayout() { return ClearLayout; }
float vsconstants[C_VENVCONST_END*4];
bool vscbufchanged = true;
ID3D11Buffer* vscbuf = NULL;
// maps the constant numbers to float indices in the constant buffer
unsigned int vs_constant_offset_table[C_VENVCONST_END];
void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
vsconstants[vs_constant_offset_table[const_number] ] = f1;
vsconstants[vs_constant_offset_table[const_number]+1] = f2;
vsconstants[vs_constant_offset_table[const_number]+2] = f3;
vsconstants[vs_constant_offset_table[const_number]+3] = f4;
vscbufchanged = true;
}
void SetVSConstant4fv(unsigned int const_number, const float* f)
{
memcpy(&vsconstants[vs_constant_offset_table[const_number]], f, sizeof(float)*4);
vscbufchanged = true;
}
void SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float* f)
{
for (unsigned int i = 0; i < count; i++)
{
memcpy(&vsconstants[vs_constant_offset_table[const_number+i]], f+3*i, sizeof(float)*3);
vsconstants[vs_constant_offset_table[const_number+i]+3] = 0.f;
}
vscbufchanged = true;
}
void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float* f)
{
memcpy(&vsconstants[vs_constant_offset_table[const_number]], f, sizeof(float)*4*count);
vscbufchanged = true;
}
ID3D11Buffer* &VertexShaderCache::GetConstantBuffer()
{
// TODO: divide the global variables of the generated shaders into about 5 constant buffers to speed this up
@ -292,3 +264,39 @@ bool VertexShaderCache::InsertByteCode(const VERTEXSHADERUID &uid, D3DBlob* bcod
return true;
}
} // namespace DX11
// These are "callbacks" from VideoCommon and thus must be outside namespace DX11.
// This will have to be changed when we merge.
// maps the constant numbers to float indices in the constant buffer
void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
vsconstants[vs_constant_offset_table[const_number] ] = f1;
vsconstants[vs_constant_offset_table[const_number]+1] = f2;
vsconstants[vs_constant_offset_table[const_number]+2] = f3;
vsconstants[vs_constant_offset_table[const_number]+3] = f4;
vscbufchanged = true;
}
void SetVSConstant4fv(unsigned int const_number, const float* f)
{
memcpy(&vsconstants[vs_constant_offset_table[const_number]], f, sizeof(float)*4);
vscbufchanged = true;
}
void SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float* f)
{
for (unsigned int i = 0; i < count; i++)
{
memcpy(&vsconstants[vs_constant_offset_table[const_number+i]], f+3*i, sizeof(float)*3);
vsconstants[vs_constant_offset_table[const_number+i]+3] = 0.f;
}
vscbufchanged = true;
}
void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float* f)
{
memcpy(&vsconstants[vs_constant_offset_table[const_number]], f, sizeof(float)*4*count);
vscbufchanged = true;
}

View File

@ -25,6 +25,8 @@
class VERTEXSHADERUID;
namespace DX11 {
class VertexShaderCache
{
public:
@ -70,4 +72,6 @@ private:
static const VSCacheEntry* last_entry;
};
} // namespace DX11
#endif // _VERTEXSHADERCACHE_H

View File

@ -180,17 +180,17 @@ void DllConfig(void *_hParent)
#if defined(HAVE_WX) && HAVE_WX
InitBackendInfo();
HRESULT hr = D3D::LoadDXGI();
if (SUCCEEDED(hr)) hr = D3D::LoadD3D();
HRESULT hr = DX11::D3D::LoadDXGI();
if (SUCCEEDED(hr)) hr = DX11::D3D::LoadD3D();
if (FAILED(hr))
{
D3D::UnloadDXGI();
DX11::D3D::UnloadDXGI();
return;
}
IDXGIFactory* factory;
IDXGIAdapter* ad;
hr = PCreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
hr = DX11::PCreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if (FAILED(hr))
PanicAlert("Failed to create IDXGIFactory object");
@ -209,7 +209,7 @@ void DllConfig(void *_hParent)
{
char buf[32];
std::vector<DXGI_SAMPLE_DESC> modes;
D3D::EnumAAModes(ad, modes);
DX11::D3D::EnumAAModes(ad, modes);
for (unsigned int i = 0; i < modes.size(); ++i)
{
if (i == 0) sprintf_s(buf, 32, "None");
@ -229,8 +229,8 @@ void DllConfig(void *_hParent)
diag->ShowModal();
diag->Destroy();
D3D::UnloadDXGI();
D3D::UnloadD3D();
DX11::D3D::UnloadDXGI();
DX11::D3D::UnloadD3D();
#endif
}
@ -279,9 +279,9 @@ void Video_Prepare()
g_renderer = new DX11::Renderer;
g_texture_cache = new DX11::TextureCache;
g_vertex_manager = new DX11::VertexManager;
VertexShaderCache::Init();
PixelShaderCache::Init();
D3D::InitUtils();
DX11::VertexShaderCache::Init();
DX11::PixelShaderCache::Init();
DX11::D3D::InitUtils();
// VideoCommon
BPInit();
@ -316,9 +316,9 @@ void Shutdown()
VertexLoaderManager::Shutdown();
// internal interfaces
D3D::ShutdownUtils();
PixelShaderCache::Shutdown();
VertexShaderCache::Shutdown();
DX11::D3D::ShutdownUtils();
DX11::PixelShaderCache::Shutdown();
DX11::VertexShaderCache::Shutdown();
delete g_vertex_manager;
delete g_texture_cache;
delete g_renderer;