2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:29:41 +00:00
|
|
|
// Refer to the license.txt file included.
|
2010-06-13 19:50:06 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2013-11-13 04:58:49 +00:00
|
|
|
#include <d3d11.h>
|
2013-10-19 09:27:57 +00:00
|
|
|
#include <d3dcompiler.h>
|
2014-02-19 11:14:09 +00:00
|
|
|
#include <dxgi.h>
|
2011-06-11 19:37:21 +00:00
|
|
|
#include <vector>
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/Common.h"
|
2016-10-07 20:55:13 +00:00
|
|
|
#include "Common/MsgHandler.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
|
2013-10-29 05:23:17 +00:00
|
|
|
namespace DX11
|
2011-01-29 20:16:51 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
#define SAFE_RELEASE(x) \
|
|
|
|
{ \
|
|
|
|
if (x) \
|
|
|
|
(x)->Release(); \
|
|
|
|
(x) = nullptr; \
|
|
|
|
}
|
|
|
|
#define SAFE_DELETE(x) \
|
|
|
|
{ \
|
|
|
|
delete (x); \
|
|
|
|
(x) = nullptr; \
|
|
|
|
}
|
|
|
|
#define SAFE_DELETE_ARRAY(x) \
|
|
|
|
{ \
|
|
|
|
delete[](x); \
|
|
|
|
(x) = nullptr; \
|
|
|
|
}
|
|
|
|
#define CHECK(cond, Message, ...) \
|
|
|
|
if (!(cond)) \
|
|
|
|
{ \
|
|
|
|
PanicAlert(__FUNCTION__ " failed in %s at line %d: " Message, __FILE__, __LINE__, \
|
|
|
|
__VA_ARGS__); \
|
|
|
|
}
|
2010-06-13 19:50:06 +00:00
|
|
|
|
|
|
|
class D3DTexture2D;
|
2011-01-29 20:16:51 +00:00
|
|
|
|
2010-06-13 19:50:06 +00:00
|
|
|
namespace D3D
|
|
|
|
{
|
2010-11-23 19:58:02 +00:00
|
|
|
HRESULT LoadDXGI();
|
|
|
|
HRESULT LoadD3D();
|
2011-02-26 23:41:02 +00:00
|
|
|
HRESULT LoadD3DCompiler();
|
2010-11-21 15:34:04 +00:00
|
|
|
void UnloadDXGI();
|
2010-11-23 19:58:02 +00:00
|
|
|
void UnloadD3D();
|
2011-02-26 23:41:02 +00:00
|
|
|
void UnloadD3DCompiler();
|
2010-11-23 19:58:02 +00:00
|
|
|
|
2013-07-22 12:38:09 +00:00
|
|
|
D3D_FEATURE_LEVEL GetFeatureLevel(IDXGIAdapter* adapter);
|
2011-03-30 07:17:23 +00:00
|
|
|
std::vector<DXGI_SAMPLE_DESC> EnumAAModes(IDXGIAdapter* adapter);
|
2010-11-21 15:34:04 +00:00
|
|
|
|
2010-06-13 19:50:06 +00:00
|
|
|
HRESULT Create(HWND wnd);
|
|
|
|
void Close();
|
|
|
|
|
2011-06-11 19:37:21 +00:00
|
|
|
extern ID3D11Device* device;
|
|
|
|
extern ID3D11DeviceContext* context;
|
2014-06-14 22:23:43 +00:00
|
|
|
extern HWND hWnd;
|
2010-06-13 19:50:06 +00:00
|
|
|
extern bool bFrameInProgress;
|
|
|
|
|
|
|
|
void Reset();
|
|
|
|
bool BeginFrame();
|
|
|
|
void EndFrame();
|
|
|
|
void Present();
|
|
|
|
|
|
|
|
unsigned int GetBackBufferWidth();
|
|
|
|
unsigned int GetBackBufferHeight();
|
2016-06-24 08:43:46 +00:00
|
|
|
D3DTexture2D*& GetBackBuffer();
|
2010-06-16 23:25:19 +00:00
|
|
|
const char* PixelShaderVersionString();
|
2011-03-14 09:38:29 +00:00
|
|
|
const char* GeometryShaderVersionString();
|
2010-06-16 23:25:19 +00:00
|
|
|
const char* VertexShaderVersionString();
|
2010-06-19 01:02:43 +00:00
|
|
|
bool BGRATexturesSupported();
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2010-07-11 16:26:46 +00:00
|
|
|
unsigned int GetMaxTextureSize();
|
|
|
|
|
2014-07-26 11:00:49 +00:00
|
|
|
HRESULT SetFullscreenState(bool enable_fullscreen);
|
2016-11-09 00:41:38 +00:00
|
|
|
bool GetFullscreenState();
|
2014-07-26 11:00:49 +00:00
|
|
|
|
2014-11-14 19:46:49 +00:00
|
|
|
// This function will assign a name to the given resource.
|
2010-06-13 19:50:06 +00:00
|
|
|
// The DirectX debug layer will make it easier to identify resources that way,
|
|
|
|
// e.g. when listing up all resources who have unreleased references.
|
2011-03-30 07:17:23 +00:00
|
|
|
template <typename T>
|
|
|
|
void SetDebugObjectName(T resource, const char* name)
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
static_assert(std::is_convertible<T, ID3D11DeviceChild*>::value,
|
|
|
|
"resource must be convertible to ID3D11DeviceChild*");
|
2010-06-13 19:50:06 +00:00
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
2016-06-24 08:43:46 +00:00
|
|
|
if (resource)
|
|
|
|
resource->SetPrivateData(WKPDID_D3DDebugObjectName, (UINT)(name ? strlen(name) : 0), name);
|
2010-06-13 19:50:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-02-09 12:14:45 +00:00
|
|
|
template <typename T>
|
|
|
|
std::string GetDebugObjectName(T resource)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
static_assert(std::is_convertible<T, ID3D11DeviceChild*>::value,
|
|
|
|
"resource must be convertible to ID3D11DeviceChild*");
|
|
|
|
std::string name;
|
2015-02-09 12:14:45 +00:00
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
2016-06-24 08:43:46 +00:00
|
|
|
if (resource)
|
|
|
|
{
|
|
|
|
UINT size = 0;
|
|
|
|
resource->GetPrivateData(WKPDID_D3DDebugObjectName, &size, nullptr); // get required size
|
|
|
|
name.resize(size);
|
|
|
|
resource->GetPrivateData(WKPDID_D3DDebugObjectName, &size, const_cast<char*>(name.data()));
|
|
|
|
}
|
2015-02-09 12:14:45 +00:00
|
|
|
#endif
|
2016-06-24 08:43:46 +00:00
|
|
|
return name;
|
2015-02-09 12:14:45 +00:00
|
|
|
}
|
|
|
|
|
2013-10-19 09:27:57 +00:00
|
|
|
} // namespace D3D
|
2010-06-27 14:04:49 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
typedef HRESULT(WINAPI* CREATEDXGIFACTORY)(REFIID, void**);
|
2010-11-21 15:34:04 +00:00
|
|
|
extern CREATEDXGIFACTORY PCreateDXGIFactory;
|
2016-06-24 08:43:46 +00:00
|
|
|
typedef HRESULT(WINAPI* D3D11CREATEDEVICE)(IDXGIAdapter*, D3D_DRIVER_TYPE, HMODULE, UINT,
|
|
|
|
CONST D3D_FEATURE_LEVEL*, UINT, UINT, ID3D11Device**,
|
|
|
|
D3D_FEATURE_LEVEL*, ID3D11DeviceContext**);
|
2011-01-29 20:16:51 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
typedef HRESULT(WINAPI* D3DREFLECT)(LPCVOID, SIZE_T, REFIID, void**);
|
2011-02-26 23:41:02 +00:00
|
|
|
extern D3DREFLECT PD3DReflect;
|
2013-10-19 09:27:57 +00:00
|
|
|
extern pD3DCompile PD3DCompile;
|
2011-02-26 23:41:02 +00:00
|
|
|
|
2011-02-14 02:18:03 +00:00
|
|
|
} // namespace DX11
|