I think clean up DX11 code a bit. Used "smart" pointers to avoid need to manually AddRef/Release in many places. Eliminated the D3DBlob class (replaced with just D3D10CreateBlob). Eliminated some Init/Shutdown functions (moved stuff into ctors/dtors). This should not affect behavior at all, only code maintainability.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7421 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Jordan Woyak
2011-03-30 07:17:23 +00:00
parent c316417a34
commit 3d5d205c73
40 changed files with 1384 additions and 1611 deletions

View File

@ -17,21 +17,35 @@
#pragma once
#include <vector>
#include <D3DX11.h>
#include <D3Dcompiler.h>
#include "D3DUtil.h"
#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__); }
#define CHECK(cond, Message, ...) if (!(cond)) { \
PanicAlert(__FUNCTION__ "Failed in %s at line %d: " Message, __FILE__, __LINE__, __VA_ARGS__); }
class D3DTexture2D;
SharedPtr<ID3D11Texture2D> CreateTexture2DShared(
const D3D11_TEXTURE2D_DESC* pDesc, const D3D11_SUBRESOURCE_DATA* pInitialData);
SharedPtr<ID3D11BlendState> CreateBlendStateShared(const D3D11_BLEND_DESC *pBlendStateDesc);
SharedPtr<ID3D11InputLayout> CreateInputLayoutShared(const D3D11_INPUT_ELEMENT_DESC *pInputElementDescs,
UINT NumElements, const void *pShaderBytecodeWithInputSignature, SIZE_T BytecodeLength);
SharedPtr<ID3D11Buffer> CreateBufferShared(const D3D11_BUFFER_DESC *pDesc,
const D3D11_SUBRESOURCE_DATA *pInitialData);
namespace D3D
{
@ -44,15 +58,16 @@ void UnloadD3D();
void UnloadD3DX();
void UnloadD3DCompiler();
void EnumAAModes(IDXGIAdapter* adapter, std::vector<DXGI_SAMPLE_DESC>& aa_modes);
std::vector<DXGI_SAMPLE_DESC> EnumAAModes(IDXGIAdapter* adapter);
DXGI_SAMPLE_DESC GetAAMode(int index);
HRESULT Create(HWND wnd);
void Close();
extern ID3D11Device* device;
extern ID3D11DeviceContext* context;
extern IDXGISwapChain* swapchain;
extern SharedPtr<ID3D11Device> g_device;
extern SharedPtr<ID3D11DeviceContext> g_context;
extern SharedPtr<IDXGISwapChain> g_swapchain;
extern bool bFrameInProgress;
void Reset();
@ -62,7 +77,7 @@ void Present();
unsigned int GetBackBufferWidth();
unsigned int GetBackBufferHeight();
D3DTexture2D* &GetBackBuffer();
D3DTexture2D* GetBackBuffer();
const char* PixelShaderVersionString();
const char* GeometryShaderVersionString();
const char* VertexShaderVersionString();
@ -73,10 +88,14 @@ unsigned int GetMaxTextureSize();
// Ihis function will assign a name to the given resource.
// The DirectX debug layer will make it easier to identify resources that way,
// e.g. when listing up all resources who have unreleased references.
inline void SetDebugObjectName(ID3D11DeviceChild* resource, const char* name)
template <typename T>
void SetDebugObjectName(T resource, const char* name)
{
static_assert(std::is_convertible<T, ID3D11DeviceChild*>::value,
"resource must be convertible to ID3D11DeviceChild*");
#if defined(_DEBUG) || defined(DEBUGFAST)
resource->SetPrivateData( WKPDID_D3DDebugObjectName, (UINT)strlen(name), name);
resource->SetPrivateData(WKPDID_D3DDebugObjectName, (UINT)strlen(name), name);
#endif
}
@ -108,6 +127,8 @@ 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;
typedef HRESULT (WINAPI* D3D10CREATEBLOB)(SIZE_T NumBytes, LPD3D10BLOB *ppBuffer);
extern D3D10CREATEBLOB PD3D10CreateBlob;
typedef HRESULT (WINAPI *D3DREFLECT)(LPCVOID, SIZE_T, REFIID, void**);
extern D3DREFLECT PD3DReflect;