本文整理汇总了C++中IDXGIAdapter类的典型用法代码示例。如果您正苦于以下问题:C++ IDXGIAdapter类的具体用法?C++ IDXGIAdapter怎么用?C++ IDXGIAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IDXGIAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateDXGIFactory
bool CD3D11Driver::init(SCreationParameters& createParam)
{
HRESULT result;
IDXGIFactory* factory;
IDXGIAdapter* adapter;
IDXGIOutput* adapterOutput;
unsigned int numModes, i, numerator = 0, denominator = 1, stringLength;
DXGI_MODE_DESC* displayModeList;
DXGI_ADAPTER_DESC adapterDesc;
int error;
D3D11_TEXTURE2D_DESC depthBufferDesc;
//D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
//D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
//D3D11_RASTERIZER_DESC rasterDesc;
//D3D11_VIEWPORT viewport;
//const SCreationParameters& params = mDevice->getCreationParameters();
// Create a DirectX graphics interface factory.
mBackBufferWidth = createParam.BackBufferWidth;
mBackBufferHeight = createParam.BackBufferHeight;
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if (FAILED(result))
{
return false;
}
// Use the factory to create an adapter for the primary graphics interface (video card).
result = factory->EnumAdapters(0, &adapter);
if (FAILED(result))
{
return false;
}
// Enumerate the primary adapter output (monitor).
result = adapter->EnumOutputs(0, &adapterOutput);
if (FAILED(result))
{
return false;
}
// Get the number of modes that fit the DXGI_FORMAT_R8G8B8A8_UNORM display format for the adapter output (monitor).
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL);
if (FAILED(result))
{
return false;
}
// Create a list to hold all the possible display modes for this monitor/video card combination.
displayModeList = new DXGI_MODE_DESC[numModes];
if (!displayModeList)
{
return false;
}
// Now fill the display mode list structures.
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList);
if (FAILED(result))
{
return false;
}
// Now go through all the display modes and find the one that matches the screen width and height.
// When a match is found store the numerator and denominator of the refresh rate for that monitor.
for (i = 0; i < numModes; i++)
{
if (displayModeList[i].Width == (unsigned int)createParam.BackBufferWidth)
{
if (displayModeList[i].Height == (unsigned int)createParam.BackBufferHeight)
{
numerator = displayModeList[i].RefreshRate.Numerator;
denominator = displayModeList[i].RefreshRate.Denominator;
}
}
}
// Get the adapter (video card) description.
result = adapter->GetDesc(&adapterDesc);
if (FAILED(result))
{
return false;
}
// Store the dedicated video card memory in megabytes.
mVideoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024);
// Convert the name of the video card to a character array and store it.
error = wcstombs_s(&stringLength, mVideoCardDescription, 128, adapterDesc.Description, 128);
if (error != 0)
{
return false;
}
// Release the display mode list.
delete[] displayModeList;
displayModeList = 0;
// Release the adapter output.
//.........这里部分代码省略.........
示例2: eventGenerator
//--------------------------------------------------------------------------------------
// Enumerate for each adapter all of the supported display modes,
// device types, adapter formats, back buffer formats, window/full screen support,
// depth stencil formats, multisampling types/qualities, and presentations intervals.
//
// For each combination of device type (HAL/REF), adapter format, back buffer format, and
// IsWindowed it will call the app's ConfirmDevice callback. This allows the app
// to reject or allow that combination based on its caps/etc. It also allows the
// app to change the BehaviorFlags. The BehaviorFlags defaults non-pure HWVP
// if supported otherwise it will default to SWVP, however the app can change this
// through the ConfirmDevice callback.
//--------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT CD3D11Enumeration::Enumerate( LPDXUTCALLBACKISD3D11DEVICEACCEPTABLE IsD3D11DeviceAcceptableFunc,
void* pIsD3D11DeviceAcceptableFuncUserContext )
{
CDXUTPerfEventGenerator eventGenerator( DXUT_PERFEVENTCOLOR, L"DXUT D3D11 Enumeration" );
HRESULT hr;
auto pFactory = DXUTGetDXGIFactory();
if( !pFactory )
return E_FAIL;
m_bHasEnumerated = true;
m_IsD3D11DeviceAcceptableFunc = IsD3D11DeviceAcceptableFunc;
m_pIsD3D11DeviceAcceptableFuncUserContext = pIsD3D11DeviceAcceptableFuncUserContext;
ClearAdapterInfoList();
for( int index = 0; ; ++index )
{
IDXGIAdapter* pAdapter = nullptr;
hr = pFactory->EnumAdapters( index, &pAdapter );
if( FAILED( hr ) ) // DXGIERR_NOT_FOUND is expected when the end of the list is hit
break;
IDXGIAdapter2* pAdapter2 = nullptr;
if ( SUCCEEDED( pAdapter->QueryInterface( __uuidof(IDXGIAdapter2), ( LPVOID* )&pAdapter2 ) ) )
{
// Succeeds on DirectX 11.1 Runtime systems
DXGI_ADAPTER_DESC2 desc;
hr = pAdapter2->GetDesc2( &desc );
pAdapter2->Release();
if ( SUCCEEDED(hr) && ( desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE ) )
{
// Skip "always there" Microsoft Basics Display Driver
pAdapter->Release();
continue;
}
}
auto pAdapterInfo = new (std::nothrow) CD3D11EnumAdapterInfo;
if( !pAdapterInfo )
{
SAFE_RELEASE( pAdapter );
return E_OUTOFMEMORY;
}
pAdapterInfo->AdapterOrdinal = index;
pAdapter->GetDesc( &pAdapterInfo->AdapterDesc );
pAdapterInfo->m_pAdapter = pAdapter;
// Enumerate the device driver types on the adapter.
hr = EnumerateDevices( pAdapterInfo );
if( FAILED( hr ) )
{
delete pAdapterInfo;
continue;
}
hr = EnumerateOutputs( pAdapterInfo );
if( FAILED( hr ) || pAdapterInfo->outputInfoList.empty() )
{
delete pAdapterInfo;
continue;
}
// Get info for each devicecombo on this device
if( FAILED( hr = EnumerateDeviceCombos( pAdapterInfo ) ) )
{
delete pAdapterInfo;
continue;
}
m_AdapterInfoList.push_back( pAdapterInfo );
}
// If we did not get an adapter then we should still enumerate WARP and Ref.
if (m_AdapterInfoList.size() == 0)
{
auto pAdapterInfo = new (std::nothrow) CD3D11EnumAdapterInfo;
if( !pAdapterInfo )
{
return E_OUTOFMEMORY;
}
pAdapterInfo->bAdapterUnavailable = true;
hr = EnumerateDevices( pAdapterInfo );
// Get info for each devicecombo on this device
if( FAILED( hr = EnumerateDeviceCombosNoAdapter( pAdapterInfo ) ) )
//.........这里部分代码省略.........
示例3: LOG
HRESULT touchmind::Context::CreateDeviceResources() {
#ifdef TOUCHMIND_CONTEXT_DEBUG
LOG_ENTER;
#endif
HRESULT hr = S_OK;
RECT rcClient;
ID3D10Device1 *pDevice = nullptr;
IDXGIDevice *pDXGIDevice = nullptr;
IDXGIAdapter *pAdapter = nullptr;
IDXGIFactory *pDXGIFactory = nullptr;
IDXGISurface *pSurface = nullptr;
if (m_hwnd == nullptr) {
LOG(SEVERITY_LEVEL_WARN) << L"HWND has not been set.";
return S_FALSE;
}
GetClientRect(m_hwnd, &rcClient);
UINT nWidth = std::abs(rcClient.right - rcClient.left);
UINT nHeight = std::abs(rcClient.bottom - rcClient.top);
if (!m_pDevice) {
#ifdef TOUCHMIND_CONTEXT_DEBUG
LOG(SEVERITY_LEVEL_DEBUG) << L"Creating D3D Device.";
#endif
#ifdef _DEBUG
// GMA950 doesn't work with D3D10_CREATE_DEVICE_DEBUG
UINT nDeviceFlags = D3D10_CREATE_DEVICE_BGRA_SUPPORT | D3D10_CREATE_DEVICE_DEBUG;
// UINT nDeviceFlags = D3D10_CREATE_DEVICE_BGRA_SUPPORT;
#else
UINT nDeviceFlags = D3D10_CREATE_DEVICE_BGRA_SUPPORT;
#endif
hr = _CreateD3DDevice(nullptr, D3D10_DRIVER_TYPE_HARDWARE, nDeviceFlags, &pDevice);
if (FAILED(hr)) {
LOG(SEVERITY_LEVEL_INFO) << L"Creating hardware support D3D10 device was failed. Try D3D10_DRIVER_TYPE_WARP.";
hr = _CreateD3DDevice(nullptr, D3D10_DRIVER_TYPE_WARP, nDeviceFlags, &pDevice);
if (FAILED(hr)) {
LOG(SEVERITY_LEVEL_FATAL) << L"Creating D3D10 device was failed.";
return hr;
}
}
if (SUCCEEDED(hr)) {
hr = pDevice->QueryInterface(&m_pDevice);
}
if (SUCCEEDED(hr)) {
hr = pDevice->QueryInterface(&pDXGIDevice);
}
if (SUCCEEDED(hr)) {
hr = pDXGIDevice->GetAdapter(&pAdapter);
}
if (SUCCEEDED(hr)) {
hr = pAdapter->GetParent(IID_PPV_ARGS(&pDXGIFactory));
}
if (SUCCEEDED(hr)) {
DXGI_SWAP_CHAIN_DESC swapDesc;
::ZeroMemory(&swapDesc, sizeof(swapDesc));
swapDesc.BufferDesc.Width = nWidth;
swapDesc.BufferDesc.Height = nHeight;
swapDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
swapDesc.BufferDesc.RefreshRate.Numerator = 60;
swapDesc.BufferDesc.RefreshRate.Denominator = 1;
swapDesc.SampleDesc.Count = m_msaaSampleCount;
swapDesc.SampleDesc.Quality = m_msaaQuality;
swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapDesc.BufferCount = 1;
swapDesc.OutputWindow = m_hwnd;
swapDesc.Windowed = TRUE;
hr = pDXGIFactory->CreateSwapChain(m_pDevice, &swapDesc, &m_pSwapChain);
#ifdef DEBUG_GPU_RESOURCE
LOG(SEVERITY_LEVEL_INFO) << L"[GPU RESOURCE] IDXGISwapChain = [" << std::hex << m_pSwapChain << L"]" << std::dec;
#endif
if (FAILED(hr)) {
LOG(SEVERITY_LEVEL_FATAL) << L"Creating swap chain was failed.";
return hr;
}
}
if (SUCCEEDED(hr)) {
hr = _CreateD3DDeviceResources();
}
if (SUCCEEDED(hr)) {
hr = _RecreateSizedResources(nWidth, nHeight);
}
if (SUCCEEDED(hr)) {
if (m_pRenderEventListener != nullptr) {
m_pRenderEventListener->CreateD2DResources(this, m_pD2DFactory, m_pD2DTexture2DRenderTarget);
}
}
}
SafeRelease(&pDevice);
SafeRelease(&pDXGIDevice);
SafeRelease(&pAdapter);
SafeRelease(&pDXGIFactory);
SafeRelease(&pSurface);
//.........这里部分代码省略.........
示例4: ZeroMemory
//.........这里部分代码省略.........
ZeroMemory(&depthStencilDesc, sizeof(depthStencilDesc));
// Set up the description of the stencil state.
depthStencilDesc.DepthEnable = true;
depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
depthStencilDesc.StencilEnable = true;
depthStencilDesc.StencilReadMask = 0xFF;
depthStencilDesc.StencilWriteMask = 0xFF;
// Stencil operations if pixel is front-facing.
depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
// Stencil operations if pixel is back-facing.
depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
// Create the depth stencil state.
hr = m_pD3D11Device->CreateDepthStencilState(&depthStencilDesc, &m_pDepthStencilState);
// Set the depth stencil state.
//DebugHR(hr);
D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
// Initialize the depth stencil view.
ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));
// Set up the depth stencil view description.
depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
depthStencilViewDesc.Texture2D.MipSlice = 0;
// Create the depth stencil view.
hr = m_pD3D11Device->CreateDepthStencilView(m_pDepthStencilBuffer.Get(), &depthStencilViewDesc, &m_pDepthStencilView);
//DebugHR(hr);
// ////////////Clear the second depth stencil state before setting the parameters.//////////////////////
D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
ZeroMemory(&depthDisabledStencilDesc, sizeof(depthDisabledStencilDesc));
// Now create a second depth stencil state which turns off the Z buffer for 2D rendering. The only difference is
// that DepthEnable is set to false, all other parameters are the same as the other depth stencil state.
depthDisabledStencilDesc.DepthEnable = false;
depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthDisabledStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
depthDisabledStencilDesc.StencilEnable = true;
depthDisabledStencilDesc.StencilReadMask = 0xFF;
depthDisabledStencilDesc.StencilWriteMask = 0xFF;
depthDisabledStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthDisabledStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
depthDisabledStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthDisabledStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
depthDisabledStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthDisabledStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
depthDisabledStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthDisabledStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
// Create the state using the device.
hr = m_pD3D11Device->CreateDepthStencilState(&depthDisabledStencilDesc, &m_pDepthDisabledStencilState);
//DebugHR(hr);
// Setup the raster description which will determine how and what polygons will be drawn.
D3D11_RASTERIZER_DESC rasterDesc;
rasterDesc.AntialiasedLineEnable = false;
rasterDesc.CullMode = D3D11_CULL_BACK;
rasterDesc.DepthBias = 0;
rasterDesc.DepthBiasClamp = 0.0f;
rasterDesc.DepthClipEnable = true;
rasterDesc.FillMode = D3D11_FILL_SOLID;
rasterDesc.FrontCounterClockwise = false;
rasterDesc.MultisampleEnable = false;
rasterDesc.ScissorEnable = false;
rasterDesc.SlopeScaledDepthBias = 0.0f;
// Create the rasterizer state from the description we just filled out.
hr = m_pD3D11Device->CreateRasterizerState(&rasterDesc, &m_pRasterState);
//DebugHR(hr);
///////////////////////////////////////////////////////////////////////////////
unsigned int numModes, i, numerator, denominator, stringLength;
IDXGIFactory* factory;
IDXGIAdapter* adapter;
IDXGISurface *surface;
DXGI_ADAPTER_DESC adapterDesc;
// Create a DirectX graphics interface factory.
CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
// Use the factory to create an adapter for the primary graphics interface (video card).
factory->EnumAdapters(0, &adapter);
adapter->GetDesc(&adapterDesc);
m_videoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024);
// Convert the name of the video card to a character array and store it.
m_videoCardInfo = std::wstring(L"Video Card :") + adapterDesc.Description;
}
示例5: Kore_Microsoft_affirm
void Graphics4::init(int windowId, int depthBufferBits, int stencilBufferBits, bool vSync) {
#ifdef KORE_VR
vsync = false;
#else
vsync = vSync;
#endif
for (int i = 0; i < 1024 * 4; ++i) vertexConstants[i] = 0;
for (int i = 0; i < 1024 * 4; ++i) fragmentConstants[i] = 0;
#ifdef KORE_WINDOWS
HWND hwnd = Window::get(windowId)->_data.handle;
#endif
UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#ifdef _DEBUG
creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_FEATURE_LEVEL featureLevels[] = {
#ifdef KORE_WINDOWSAPP
D3D_FEATURE_LEVEL_11_1,
#endif
D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0};
#ifdef KORE_WINDOWSAPP
IDXGIAdapter3* adapter = nullptr;
#ifdef KORE_HOLOLENS
adapter = holographicFrameController->getCompatibleDxgiAdapter().Get();
#endif
Kore_Microsoft_affirm(D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_HARDWARE, nullptr, creationFlags, featureLevels, ARRAYSIZE(featureLevels), D3D11_SDK_VERSION,
&device, &featureLevel, &context));
#elif KORE_OCULUS
IDXGIFactory* dxgiFactory = nullptr;
Windows::affirm(CreateDXGIFactory1(__uuidof(IDXGIFactory), (void**)(&dxgiFactory)));
Windows::affirm(D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, 0, creationFlags, featureLevels, ARRAYSIZE(featureLevels), D3D11_SDK_VERSION, &device,
&featureLevel, &context));
#endif
// affirm(device0.As(&device));
// affirm(context0.As(&context));
// m_windowBounds = m_window->Bounds;
const int _DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL = 3;
const int _DXGI_SWAP_EFFECT_FLIP_DISCARD = 4;
if (swapChain != nullptr) {
Kore_Microsoft_affirm(swapChain->ResizeBuffers(2, 0, 0, DXGI_FORMAT_B8G8R8A8_UNORM, 0));
}
else {
#ifdef KORE_WINDOWS
DXGI_SWAP_CHAIN_DESC swapChainDesc = {0};
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1; // 60Hz
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.Width = System::windowWidth(windowId); // use automatic sizing
swapChainDesc.BufferDesc.Height = System::windowHeight(windowId);
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // this is the most common swapchain format
// swapChainDesc.Stereo = false;
swapChainDesc.SampleDesc.Count = antialiasingSamples() > 1 ? antialiasingSamples() : 1;
swapChainDesc.SampleDesc.Quality = antialiasingSamples() > 1 ? D3D11_STANDARD_MULTISAMPLE_PATTERN : 0;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferCount = 2; // use two buffers to enable flip effect
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; // DXGI_SCALING_NONE;
if (isWindows10OrGreater()) {
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
//(DXGI_SWAP_EFFECT) _DXGI_SWAP_EFFECT_FLIP_DISCARD;
}
else if (isWindows8OrGreater()) {
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
//(DXGI_SWAP_EFFECT) _DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
}
else {
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
}
swapChainDesc.Flags = 0;
swapChainDesc.OutputWindow = Window::get(windowId)->_data.handle;
swapChainDesc.Windowed = true;
#endif
#if defined(KORE_WINDOWSAPP)
#ifdef KORE_HOLOLENS
// The Windows::Graphics::Holographic::HolographicSpace owns its own swapchain so we don't need to create one here
#else
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
swapChainDesc.Width = 0; // use automatic sizing
swapChainDesc.Height = 0;
swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // this is the most common swapchain format
swapChainDesc.Stereo = false;
swapChainDesc.SampleDesc.Count = antialiasingSamples() > 1 ? antialiasingSamples() : 1;
swapChainDesc.SampleDesc.Quality = antialiasingSamples() > 1 ? D3D11_STANDARD_MULTISAMPLE_PATTERN : 0;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferCount = 2; // use two buffers to enable flip effect
swapChainDesc.Scaling = DXGI_SCALING_NONE;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // we recommend using this swap effect for all applications
swapChainDesc.Flags = 0;
IDXGIDevice1* dxgiDevice;
//.........这里部分代码省略.........
示例6: Create
HRESULT Create(HWND wnd)
{
hWnd = wnd;
HRESULT hr;
RECT client;
GetClientRect(hWnd, &client);
xres = client.right - client.left;
yres = client.bottom - client.top;
hr = LoadDXGI();
if (SUCCEEDED(hr)) hr = LoadD3D();
if (SUCCEEDED(hr)) hr = LoadD3DCompiler();
if (FAILED(hr))
{
UnloadDXGI();
UnloadD3D();
UnloadD3DCompiler();
return hr;
}
IDXGIFactory* factory;
IDXGIAdapter* adapter;
IDXGIOutput* output;
hr = PCreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if (FAILED(hr)) MessageBox(wnd, _T("Failed to create IDXGIFactory object"), _T("Dolphin Direct3D 11 backend"), MB_OK | MB_ICONERROR);
hr = factory->EnumAdapters(g_ActiveConfig.iAdapter, &adapter);
if (FAILED(hr))
{
// try using the first one
hr = factory->EnumAdapters(0, &adapter);
if (FAILED(hr)) MessageBox(wnd, _T("Failed to enumerate adapters"), _T("Dolphin Direct3D 11 backend"), MB_OK | MB_ICONERROR);
}
// TODO: Make this configurable
hr = adapter->EnumOutputs(0, &output);
if (FAILED(hr))
{
// try using the first one
hr = adapter->EnumOutputs(0, &output);
if (FAILED(hr)) MessageBox(wnd, _T("Failed to enumerate outputs"), _T("Dolphin Direct3D 11 backend"), MB_OK | MB_ICONERROR);
}
// get supported AA modes
aa_modes = EnumAAModes(adapter);
if (g_Config.iMultisampleMode >= (int)aa_modes.size())
{
g_Config.iMultisampleMode = 0;
UpdateActiveConfig();
}
DXGI_SWAP_CHAIN_DESC swap_chain_desc;
memset(&swap_chain_desc, 0, sizeof(swap_chain_desc));
swap_chain_desc.BufferCount = 1;
swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swap_chain_desc.OutputWindow = wnd;
swap_chain_desc.SampleDesc.Count = 1;
swap_chain_desc.SampleDesc.Quality = 0;
swap_chain_desc.Windowed = TRUE;
DXGI_MODE_DESC mode_desc;
memset(&mode_desc, 0, sizeof(mode_desc));
mode_desc.Width = xres;
mode_desc.Height = yres;
mode_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
mode_desc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
hr = output->FindClosestMatchingMode(&mode_desc, &swap_chain_desc.BufferDesc, nullptr);
if (FAILED(hr)) MessageBox(wnd, _T("Failed to find a supported video mode"), _T("Dolphin Direct3D 11 backend"), MB_OK | MB_ICONERROR);
// forcing buffer resolution to xres and yres.. TODO: The new video mode might not actually be supported!
swap_chain_desc.BufferDesc.Width = xres;
swap_chain_desc.BufferDesc.Height = yres;
#if defined(_DEBUG) || defined(DEBUGFAST)
// Creating debug devices can sometimes fail if the user doesn't have the correct
// version of the DirectX SDK. If it does, simply fallback to a non-debug device.
{
hr = PD3D11CreateDeviceAndSwapChain(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr,
D3D11_CREATE_DEVICE_SINGLETHREADED | D3D11_CREATE_DEVICE_DEBUG,
supported_feature_levels, NUM_SUPPORTED_FEATURE_LEVELS,
D3D11_SDK_VERSION, &swap_chain_desc, &swapchain, &device,
&featlevel, &context);
}
if (FAILED(hr))
#endif
{
hr = PD3D11CreateDeviceAndSwapChain(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr,
D3D11_CREATE_DEVICE_SINGLETHREADED,
supported_feature_levels, NUM_SUPPORTED_FEATURE_LEVELS,
D3D11_SDK_VERSION, &swap_chain_desc, &swapchain, &device,
&featlevel, &context);
}
if (FAILED(hr))
{
MessageBox(wnd, _T("Failed to initialize Direct3D.\nMake sure your video card supports at least D3D 10.0"), _T("Dolphin Direct3D 11 backend"), MB_OK | MB_ICONERROR);
SAFE_RELEASE(device);
SAFE_RELEASE(context);
//.........这里部分代码省略.........
示例7: InitDevice
//--------------------------------------------------------------------------------------
// Create Direct3D device and swap chain
//--------------------------------------------------------------------------------------
HRESULT InitDevice()
{
HRESULT hr = S_OK;
RECT rc;
GetClientRect( g_hWnd, &rc );
UINT width = rc.right - rc.left;
UINT height = rc.bottom - rc.top;
UINT createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_DRIVER_TYPE driverTypes[] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE,
};
UINT numDriverTypes = ARRAYSIZE( driverTypes );
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
};
UINT numFeatureLevels = ARRAYSIZE( featureLevels );
for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
{
g_driverType = driverTypes[driverTypeIndex];
hr = D3D11CreateDevice( nullptr, g_driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels,
D3D11_SDK_VERSION, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
if ( hr == E_INVALIDARG )
{
// DirectX 11.0 platforms will not recognize D3D_FEATURE_LEVEL_11_1 so we need to retry without it
hr = D3D11CreateDevice( nullptr, g_driverType, nullptr, createDeviceFlags, &featureLevels[1], numFeatureLevels - 1,
D3D11_SDK_VERSION, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
}
if( SUCCEEDED( hr ) )
break;
}
if( FAILED( hr ) )
return hr;
// Obtain DXGI factory from device (since we used nullptr for pAdapter above)
IDXGIFactory1* dxgiFactory = nullptr;
{
IDXGIDevice* dxgiDevice = nullptr;
hr = g_pd3dDevice->QueryInterface( __uuidof(IDXGIDevice), reinterpret_cast<void**>(&dxgiDevice) );
if (SUCCEEDED(hr))
{
IDXGIAdapter* adapter = nullptr;
hr = dxgiDevice->GetAdapter(&adapter);
if (SUCCEEDED(hr))
{
hr = adapter->GetParent( __uuidof(IDXGIFactory1), reinterpret_cast<void**>(&dxgiFactory) );
adapter->Release();
}
dxgiDevice->Release();
}
}
if (FAILED(hr))
return hr;
// Create swap chain
IDXGIFactory2* dxgiFactory2 = nullptr;
hr = dxgiFactory->QueryInterface( __uuidof(IDXGIFactory2), reinterpret_cast<void**>(&dxgiFactory2) );
if ( dxgiFactory2 )
{
// DirectX 11.1 or later
hr = g_pd3dDevice->QueryInterface( __uuidof(ID3D11Device1), reinterpret_cast<void**>(&g_pd3dDevice1) );
if (SUCCEEDED(hr))
{
(void) g_pImmediateContext->QueryInterface( __uuidof(ID3D11DeviceContext1), reinterpret_cast<void**>(&g_pImmediateContext1) );
}
DXGI_SWAP_CHAIN_DESC1 sd;
ZeroMemory(&sd, sizeof(sd));
sd.Width = width;
sd.Height = height;
sd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.BufferCount = 1;
hr = dxgiFactory2->CreateSwapChainForHwnd( g_pd3dDevice, g_hWnd, &sd, nullptr, nullptr, &g_pSwapChain1 );
if (SUCCEEDED(hr))
{
hr = g_pSwapChain1->QueryInterface( __uuidof(IDXGISwapChain), reinterpret_cast<void**>(&g_pSwapChain) );
}
//.........这里部分代码省略.........
示例8: sizeof
void D3D11::init( int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen, float screenDepth, float screenNear )
{
m_vsyncEnabled = vsync;
m_isWindows = fullscreen;
IDXGIFactory * pfactory;
if(FAILED(CreateDXGIFactory(__uuidof(IDXGIFactory),(void**)&pfactory)))
return;
IDXGIAdapter * pAdapter;
if(FAILED(pfactory->EnumAdapters(0,&pAdapter)))
return;
IDXGIOutput * out;
if(FAILED(pAdapter->EnumOutputs(0,&out)))
return;
int numModes;
DXGI_MODE_DESC * displaymodeList;
if(FAILED(out->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM,DXGI_ENUM_MODES_INTERLACED,&numModes,NULL)))
return;
displaymodeList = new DXGI_MODE_DESC[numModes];
if(FAILED(out->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM,DXGI_ENUM_MODES_INTERLACED,&numModes,displaymodeList)))
return;
int numerator,denomerator;
for(int i = 0; i < numModes; ++i)
{
if(displaymodeList[i].Height == screenHeight && displaymodeList[i].Width == screenWidth)
{
numerator = displaymodeList[i].RefreshRate.Numerator;
denomerator = displaymodeList[i].RefreshRate.Denominator;
}
}
DXGI_ADAPTER_DESC desc;
if(FAILED(pAdapter->GetDesc(&desc)))
return;
int length;
m_videoCardMemory = static_cast<int>(desc.DedicatedVideoMemory/1024/1024);
wcstombs_s(&length,m_videoCardDescription,128,desc.Description,128);
delete[] displaymodeList;
displaymodeList = NULL;
out->Release();
out = NULL;
pAdapter->Release();
pAdapter = NULL;
pfactory->Release();
pfactory = NULL;
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc,sizeof(DXGI_SWAP_CHAIN_DESC));
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Width = screenWidth;
swapChainDesc.BufferDesc.Height = screenHeight;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
if(m_vsyncEnabled)
{
swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
swapChainDesc.BufferDesc.RefreshRate.Denominator = denomerator;
}
else
{
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
}
swapChainDesc.Windowed = m_isWindows;
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
D3D_FEATURE_LEVEL level = D3D_FEATURE_LEVEL_11_0;
if(FAILED(D3D11CreateDeviceAndSwapChain(NULL,D3D_DRIVER_TYPE_HARDWARE,NULL,0,
&level,1,D3D11_SDK_VERSION,&swapChainDesc,&m_swapChain,&m_device,NULL,&m_deviceContext)))
return;
ID3D11Texture2D *backbufferTex;
if(FAILED(m_swapChain->GetBuffer(0,__uuidof(ID3D11Texture2D),(LPVOID*)&backbufferTex)))
return;
if(FAILED(m_device->CreateRenderTargetView(backbufferTex,NULL,&m_renderView)))
return;
backbufferTex->Release();
backbufferTex = 0;
D3D11_TEXTURE2D_DESC depthBufferDesc;
ZeroMemory(&depthBufferDesc, sizeof(depthBufferDesc));
depthBufferDesc.Width = screenWidth;
depthBufferDesc.Height = screenHeight;
depthBufferDesc.MipLevels = 1;
depthBufferDesc.ArraySize = 1;
depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthBufferDesc.SampleDesc.Count = 1;
depthBufferDesc.SampleDesc.Quality = 0;
depthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
depthBufferDesc.CPUAccessFlags = 0;
depthBufferDesc.MiscFlags = 0;
if(FAILED(m_device->CreateTexture2D(&depthBufferDesc, NULL, &m_depthStencilBuffer)))
return ;
//.........这里部分代码省略.........
示例9: InitDevice
//--------------------------------------------------------------------------------------
// Create Direct3D device and swap chain
//--------------------------------------------------------------------------------------
HRESULT InitDevice()
{
HRESULT hr = S_OK;
RECT rc;
GetClientRect( g_hWnd, &rc );
UINT width = rc.right - rc.left;
UINT height = rc.bottom - rc.top;
UINT createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_DRIVER_TYPE driverTypes[] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE,
};
UINT numDriverTypes = ARRAYSIZE( driverTypes );
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
};
UINT numFeatureLevels = ARRAYSIZE( featureLevels );
for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
{
g_driverType = driverTypes[driverTypeIndex];
hr = D3D11CreateDevice( nullptr, g_driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels,
D3D11_SDK_VERSION, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
if ( hr == E_INVALIDARG )
{
// DirectX 11.0 platforms will not recognize D3D_FEATURE_LEVEL_11_1 so we need to retry without it
hr = D3D11CreateDevice( nullptr, g_driverType, nullptr, createDeviceFlags, &featureLevels[1], numFeatureLevels - 1,
D3D11_SDK_VERSION, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
}
if( SUCCEEDED( hr ) )
break;
}
if( FAILED( hr ) )
return hr;
// Obtain DXGI factory from device (since we used nullptr for pAdapter above)
IDXGIFactory1* dxgiFactory = nullptr;
{
IDXGIDevice* dxgiDevice = nullptr;
hr = g_pd3dDevice->QueryInterface( __uuidof(IDXGIDevice), reinterpret_cast<void**>(&dxgiDevice) );
if (SUCCEEDED(hr))
{
IDXGIAdapter* adapter = nullptr;
hr = dxgiDevice->GetAdapter(&adapter);
if (SUCCEEDED(hr))
{
hr = adapter->GetParent( __uuidof(IDXGIFactory1), reinterpret_cast<void**>(&dxgiFactory) );
adapter->Release();
}
dxgiDevice->Release();
}
}
if (FAILED(hr))
return hr;
// Create swap chain
IDXGIFactory2* dxgiFactory2 = nullptr;
hr = dxgiFactory->QueryInterface( __uuidof(IDXGIFactory2), reinterpret_cast<void**>(&dxgiFactory2) );
if ( dxgiFactory2 )
{
// DirectX 11.1 or later
hr = g_pd3dDevice->QueryInterface( __uuidof(ID3D11Device1), reinterpret_cast<void**>(&g_pd3dDevice1) );
if (SUCCEEDED(hr))
{
(void) g_pImmediateContext->QueryInterface( __uuidof(ID3D11DeviceContext1), reinterpret_cast<void**>(&g_pImmediateContext1) );
}
DXGI_SWAP_CHAIN_DESC1 sd;
ZeroMemory(&sd, sizeof(sd));
sd.Width = width;
sd.Height = height;
sd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.BufferCount = 1;
hr = dxgiFactory2->CreateSwapChainForHwnd( g_pd3dDevice, g_hWnd, &sd, nullptr, nullptr, &g_pSwapChain1 );
if (SUCCEEDED(hr))
{
hr = g_pSwapChain1->QueryInterface( __uuidof(IDXGISwapChain), reinterpret_cast<void**>(&g_pSwapChain) );
}
//.........这里部分代码省略.........
示例10: ISwapChain
/**
* @brief
* Constructor
*/
SwapChain::SwapChain(Direct3D11Renderer &direct3D11Renderer, handle nativeWindowHandle) :
ISwapChain(direct3D11Renderer),
mDxgiSwapChain(nullptr),
mD3D11RenderTargetView(nullptr),
mD3D11DepthStencilView(nullptr)
{
// Get the Direct3D 11 device instance
ID3D11Device *d3d11Device = direct3D11Renderer.getD3D11Device();
// Get the native window handle
const HWND hWnd = reinterpret_cast<HWND>(nativeWindowHandle);
// Get a IDXGIFactory1 instance
IDXGIDevice *dxgiDevice = nullptr;
IDXGIAdapter *dxgiAdapter = nullptr;
IDXGIFactory1 *dxgiFactory1 = nullptr;
d3d11Device->QueryInterface(&dxgiDevice);
dxgiDevice->GetAdapter(&dxgiAdapter);
dxgiAdapter->GetParent(IID_PPV_ARGS(&dxgiFactory1));
dxgiAdapter->Release();
dxgiDevice->Release();
// Get the width and height of the given native window and ensure they are never ever zero
// -> See "getSafeWidthAndHeight()"-method comments for details
long width = 1;
long height = 1;
{
// Get the client rectangle of the given native window
RECT rect;
::GetClientRect(hWnd, &rect);
// Get the width and height...
width = rect.right - rect.left;
height = rect.bottom - rect.top;
// ... and ensure that none of them is ever zero
if (width < 1)
{
width = 1;
}
if (height < 1)
{
height = 1;
}
}
// Create the swap chain
DXGI_SWAP_CHAIN_DESC dxgiSwapChainDesc;
::ZeroMemory(&dxgiSwapChainDesc, sizeof(dxgiSwapChainDesc));
dxgiSwapChainDesc.BufferCount = 1;
dxgiSwapChainDesc.BufferDesc.Width = static_cast<UINT>(width);
dxgiSwapChainDesc.BufferDesc.Height = static_cast<UINT>(height);
dxgiSwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
dxgiSwapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
dxgiSwapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
dxgiSwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
dxgiSwapChainDesc.OutputWindow = hWnd;
dxgiSwapChainDesc.SampleDesc.Count = 1;
dxgiSwapChainDesc.SampleDesc.Quality = 0;
dxgiSwapChainDesc.Windowed = TRUE;
dxgiFactory1->CreateSwapChain(d3d11Device, &dxgiSwapChainDesc, &mDxgiSwapChain);
dxgiFactory1->Release();
// Disable alt-return for automatic fullscreen state change
// -> We handle this manually to have more control over it
dxgiFactory1->MakeWindowAssociation(hWnd, DXGI_MWA_NO_ALT_ENTER);
// Create the Direct3D 11 views
if (nullptr != mDxgiSwapChain)
{
createDirect3D11Views();
}
// Assign a default name to the resource for debugging purposes
#ifndef DIRECT3D11RENDERER_NO_DEBUG
setDebugName("Swap chain");
#endif
}
示例11: InitBackendInfo
void InitBackendInfo()
{
HRESULT hr = DX11::D3D::LoadDXGI();
if (SUCCEEDED(hr)) hr = DX11::D3D::LoadD3D();
if (FAILED(hr))
{
DX11::D3D::UnloadDXGI();
return;
}
g_Config.backend_info.APIType = API_D3D;
g_Config.backend_info.bSupportsExclusiveFullscreen = true;
g_Config.backend_info.bSupportsDualSourceBlend = true;
g_Config.backend_info.bSupportsPrimitiveRestart = true;
g_Config.backend_info.bSupportsOversizedViewports = false;
g_Config.backend_info.bSupportsGeometryShaders = true;
g_Config.backend_info.bSupports3DVision = true;
g_Config.backend_info.bSupportsPostProcessing = false;
IDXGIFactory* factory;
IDXGIAdapter* ad;
hr = DX11::PCreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if (FAILED(hr))
PanicAlert("Failed to create IDXGIFactory object");
// adapters
g_Config.backend_info.Adapters.clear();
g_Config.backend_info.AAModes.clear();
while (factory->EnumAdapters((UINT)g_Config.backend_info.Adapters.size(), &ad) != DXGI_ERROR_NOT_FOUND)
{
const size_t adapter_index = g_Config.backend_info.Adapters.size();
DXGI_ADAPTER_DESC desc;
ad->GetDesc(&desc);
// TODO: These don't get updated on adapter change, yet
if (adapter_index == g_Config.iAdapter)
{
std::string samples;
std::vector<DXGI_SAMPLE_DESC> modes = DX11::D3D::EnumAAModes(ad);
for (unsigned int i = 0; i < modes.size(); ++i)
{
if (i == 0)
samples = _trans("None");
else if (modes[i].Quality)
samples = StringFromFormat(_trans("%d samples (quality level %d)"), modes[i].Count, modes[i].Quality);
else
samples = StringFromFormat(_trans("%d samples"), modes[i].Count);
g_Config.backend_info.AAModes.push_back(samples);
}
bool shader_model_5_supported = (DX11::D3D::GetFeatureLevel(ad) >= D3D_FEATURE_LEVEL_11_0);
// Requires the earlydepthstencil attribute (only available in shader model 5)
g_Config.backend_info.bSupportsEarlyZ = shader_model_5_supported;
// Requires full UAV functionality (only available in shader model 5)
g_Config.backend_info.bSupportsBBox = shader_model_5_supported;
// Requires the instance attribute (only available in shader model 5)
g_Config.backend_info.bSupportsGSInstancing = shader_model_5_supported;
}
g_Config.backend_info.Adapters.push_back(UTF16ToUTF8(desc.Description));
ad->Release();
}
factory->Release();
// Clear ppshaders string vector
g_Config.backend_info.PPShaders.clear();
g_Config.backend_info.AnaglyphShaders.clear();
DX11::D3D::UnloadDXGI();
DX11::D3D::UnloadD3D();
}
示例12: Create
HRESULT Create(HWND wnd)
{
hWnd = wnd;
HRESULT hr;
RECT client;
GetClientRect(hWnd, &client);
xres = client.right - client.left;
yres = client.bottom - client.top;
hr = LoadDXGI();
if (SUCCEEDED(hr)) hr = LoadD3D();
if (SUCCEEDED(hr)) hr = LoadD3DCompiler();
if (FAILED(hr))
{
UnloadDXGI();
UnloadD3D();
UnloadD3DCompiler();
return hr;
}
IDXGIFactory* factory;
IDXGIAdapter* adapter;
IDXGIOutput* output;
hr = PCreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if (FAILED(hr)) MessageBox(wnd, _T("Failed to create IDXGIFactory object"), _T("Dolphin Direct3D 11 backend"), MB_OK | MB_ICONERROR);
hr = factory->EnumAdapters(g_ActiveConfig.iAdapter, &adapter);
if (FAILED(hr))
{
// try using the first one
hr = factory->EnumAdapters(0, &adapter);
if (FAILED(hr)) MessageBox(wnd, _T("Failed to enumerate adapters"), _T("Dolphin Direct3D 11 backend"), MB_OK | MB_ICONERROR);
}
// TODO: Make this configurable
hr = adapter->EnumOutputs(0, &output);
if (FAILED(hr))
{
// try using the first one
IDXGIAdapter* firstadapter;
hr = factory->EnumAdapters(0, &firstadapter);
if (!FAILED(hr))
hr = firstadapter->EnumOutputs(0, &output);
if (FAILED(hr)) MessageBox(wnd,
_T("Failed to enumerate outputs!\n")
_T("This usually happens when you've set your video adapter to the Nvidia GPU in an Optimus-equipped system.\n")
_T("Set Dolphin to use the high-performance graphics in Nvidia's drivers instead and leave Dolphin's video adapter set to the Intel GPU."),
_T("Dolphin Direct3D 11 backend"), MB_OK | MB_ICONERROR);
SAFE_RELEASE(firstadapter);
}
// get supported AA modes
aa_modes = EnumAAModes(adapter);
if (std::find_if(
aa_modes.begin(),
aa_modes.end(),
[](const DXGI_SAMPLE_DESC& desc) {return desc.Count == g_Config.iMultisamples;}
) == aa_modes.end())
{
g_Config.iMultisamples = 1;
UpdateActiveConfig();
}
DXGI_SWAP_CHAIN_DESC swap_chain_desc = {};
swap_chain_desc.BufferCount = 1;
swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swap_chain_desc.OutputWindow = wnd;
swap_chain_desc.SampleDesc.Count = 1;
swap_chain_desc.SampleDesc.Quality = 0;
swap_chain_desc.Windowed = !g_Config.bFullscreen;
DXGI_OUTPUT_DESC out_desc = {};
output->GetDesc(&out_desc);
DXGI_MODE_DESC mode_desc = {};
mode_desc.Width = out_desc.DesktopCoordinates.right - out_desc.DesktopCoordinates.left;
mode_desc.Height = out_desc.DesktopCoordinates.bottom - out_desc.DesktopCoordinates.top;
mode_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
mode_desc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
hr = output->FindClosestMatchingMode(&mode_desc, &swap_chain_desc.BufferDesc, nullptr);
if (FAILED(hr)) MessageBox(wnd, _T("Failed to find a supported video mode"), _T("Dolphin Direct3D 11 backend"), MB_OK | MB_ICONERROR);
if (swap_chain_desc.Windowed)
{
// forcing buffer resolution to xres and yres..
// this is not a problem as long as we're in windowed mode
swap_chain_desc.BufferDesc.Width = xres;
swap_chain_desc.BufferDesc.Height = yres;
}
#if defined(_DEBUG) || defined(DEBUGFAST)
// Creating debug devices can sometimes fail if the user doesn't have the correct
// version of the DirectX SDK. If it does, simply fallback to a non-debug device.
{
hr = PD3D11CreateDeviceAndSwapChain(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr,
D3D11_CREATE_DEVICE_SINGLETHREADED | D3D11_CREATE_DEVICE_DEBUG,
supported_feature_levels, NUM_SUPPORTED_FEATURE_LEVELS,
D3D11_SDK_VERSION, &swap_chain_desc, &swapchain, &device,
//.........这里部分代码省略.........
示例13: defined
bool DX::InitDirect3D()
{
UINT createDeviceFlags = 0;
// Do we want a debug device?
#if defined(DEBUG) || defined(_DEBUG)
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
// Create the device and determine the supported feature level
featureLevel = D3D_FEATURE_LEVEL_9_1; // Will be overwritten by next line
HRESULT hr = D3D11CreateDevice(
0,
driverType,
0,
createDeviceFlags,
0,
0,
D3D11_SDK_VERSION,
&device,
&featureLevel,
&deviceContext);
// Handle any device creation or DirectX version errors
if( FAILED(hr) )
{
MessageBox(0, L"D3D11CreateDevice Failed", 0, 0);
return false;
}
// Check for 4X MSAA quality support
HR(device->CheckMultisampleQualityLevels(
DXGI_FORMAT_R8G8B8A8_UNORM,
4,
&msaa4xQuality));
assert( msaa4xQuality > 0 ); // Potential problem if quality is 0
// Set up a swap chain description
DXGI_SWAP_CHAIN_DESC swapChainDesc;
swapChainDesc.BufferDesc.Width = windowWidth;
swapChainDesc.BufferDesc.Height = windowHeight;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferCount = 1;
swapChainDesc.OutputWindow = hMainWnd;
swapChainDesc.Windowed = true;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
swapChainDesc.Flags = 0;
if( enable4xMsaa )
{
// Set up 4x MSAA
swapChainDesc.SampleDesc.Count = 4;
swapChainDesc.SampleDesc.Quality = msaa4xQuality - 1;
}
else
{
// No MSAA
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
}
// To correctly create the swap chain, we must use the IDXGIFactory that
// was used to create the device.
IDXGIDevice* dxgiDevice = 0;
IDXGIAdapter* dxgiAdapter = 0;
IDXGIFactory* dxgiFactory = 0;
HR(device->QueryInterface( __uuidof(IDXGIDevice), (void**)&dxgiDevice));
HR(dxgiDevice->GetParent( __uuidof(IDXGIAdapter), (void**)&dxgiAdapter));
HR(dxgiAdapter->GetParent( __uuidof(IDXGIFactory), (void**)&dxgiFactory));
// Finally make the swap chain and release the DXGI stuff
HR(dxgiFactory->CreateSwapChain(device, &swapChainDesc, &swapChain));
ReleaseMacro(dxgiDevice);
ReleaseMacro(dxgiAdapter);
ReleaseMacro(dxgiFactory);
// The remaining steps also need to happen each time the window
// is resized, so just run the OnResize method
OnResize();
return true;
}
示例14: InitD3D
// Direct3D 초기화
HRESULT InitD3D( void )
{
HRESULT hr = S_OK;
D3D_FEATURE_LEVEL FeatureLevelsRequested[6] = { D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1 };
UINT numLevelsRequested = 6;
D3D_FEATURE_LEVEL FeatureLevelsSupported;
// 디바이스 생성
hr = D3D11CreateDevice( NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
0,
FeatureLevelsRequested,
numLevelsRequested,
D3D11_SDK_VERSION,
&g_pd3dDevice,
&FeatureLevelsSupported,
&g_pImmediateContext );
if( FAILED ( hr ) ) {
return hr;
}
// 팩토리 취득
IDXGIDevice * pDXGIDevice;
hr = g_pd3dDevice->QueryInterface( __uuidof( IDXGIDevice ), ( void ** )&pDXGIDevice );
IDXGIAdapter * pDXGIAdapter;
hr = pDXGIDevice->GetParent( __uuidof( IDXGIAdapter ), ( void ** )&pDXGIAdapter );
IDXGIFactory * pIDXGIFactory;
pDXGIAdapter->GetParent( __uuidof( IDXGIFactory ), ( void ** )&pIDXGIFactory);
// 스왑체인 작성
DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory( &sd, sizeof( sd ) );
sd.BufferCount = 1;
sd.BufferDesc.Width = g_nClientWidth;
sd.BufferDesc.Height = g_nClientHeight;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = g_hWnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;
hr = pIDXGIFactory->CreateSwapChain( g_pd3dDevice, &sd, &g_pSwapChain );
pDXGIDevice->Release();
pDXGIAdapter->Release();
pIDXGIFactory->Release();
if( FAILED ( hr ) ) {
return hr;
}
// 렌더링 타깃 생성
ID3D11Texture2D *pBackBuffer = NULL;
D3D11_TEXTURE2D_DESC BackBufferSurfaceDesc;
hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer );
if ( FAILED( hr ) ) {
MessageBox( NULL, _T( "Can't get backbuffer." ), _T( "Error" ), MB_OK );
return hr;
}
pBackBuffer->GetDesc( &BackBufferSurfaceDesc );
hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRTV );
SAFE_RELEASE( pBackBuffer );
if ( FAILED( hr ) ) {
MessageBox( NULL, _T( "Can't create render target view." ), _T( "Error" ), MB_OK );
return hr;
}
g_pImmediateContext->OMSetRenderTargets( 1, &g_pRTV, NULL );
// 래스터라이저 설정
D3D11_RASTERIZER_DESC drd;
ZeroMemory( &drd, sizeof( drd ) );
drd.FillMode = D3D11_FILL_SOLID;
drd.CullMode = D3D11_CULL_NONE;
drd.FrontCounterClockwise = FALSE;
drd.DepthClipEnable = TRUE;
hr = g_pd3dDevice->CreateRasterizerState( &drd, &g_pRS );
if ( FAILED( hr ) ) {
MessageBox( NULL, _T( "Can't create rasterizer state." ), _T( "Error" ), MB_OK );
return hr;
}
g_pImmediateContext->RSSetState( g_pRS );
// 뷰포트 설정
D3D11_VIEWPORT vp;
vp.Width = ( FLOAT )g_nClientWidth;
vp.Height = ( FLOAT )g_nClientHeight;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0.0f;
vp.TopLeftY = 0.0f;
//.........这里部分代码省略.........
示例15: CollectReports
// nsIMemoryMultiReporter abstract method implementation
NS_IMETHOD
CollectReports(nsIMemoryMultiReporterCallback* aCb,
nsISupports* aClosure)
{
int32_t winVers, buildNum;
HANDLE ProcessHandle = GetCurrentProcess();
int64_t dedicatedBytesUsed = 0;
int64_t sharedBytesUsed = 0;
int64_t committedBytesUsed = 0;
IDXGIAdapter *DXGIAdapter;
HMODULE gdi32Handle;
PFND3DKMTQS queryD3DKMTStatistics;
winVers = gfxWindowsPlatform::WindowsOSVersion(&buildNum);
// GPU memory reporting is not available before Windows 7
if (winVers < gfxWindowsPlatform::kWindows7)
return NS_OK;
if (gdi32Handle = LoadLibrary(TEXT("gdi32.dll")))
queryD3DKMTStatistics = (PFND3DKMTQS)GetProcAddress(gdi32Handle, "D3DKMTQueryStatistics");
if (queryD3DKMTStatistics && GetDXGIAdapter(&DXGIAdapter)) {
// Most of this block is understood thanks to wj32's work on Process Hacker
DXGI_ADAPTER_DESC adapterDesc;
D3DKMTQS queryStatistics;
DXGIAdapter->GetDesc(&adapterDesc);
DXGIAdapter->Release();
memset(&queryStatistics, 0, sizeof(D3DKMTQS));
queryStatistics.Type = D3DKMTQS_PROCESS;
queryStatistics.AdapterLuid = adapterDesc.AdapterLuid;
queryStatistics.hProcess = ProcessHandle;
if (NT_SUCCESS(queryD3DKMTStatistics(&queryStatistics))) {
committedBytesUsed = queryStatistics.QueryResult.ProcessInfo.SystemMemory.BytesAllocated;
}
memset(&queryStatistics, 0, sizeof(D3DKMTQS));
queryStatistics.Type = D3DKMTQS_ADAPTER;
queryStatistics.AdapterLuid = adapterDesc.AdapterLuid;
if (NT_SUCCESS(queryD3DKMTStatistics(&queryStatistics))) {
ULONG i;
ULONG segmentCount = queryStatistics.QueryResult.AdapterInfo.NbSegments;
for (i = 0; i < segmentCount; i++) {
memset(&queryStatistics, 0, sizeof(D3DKMTQS));
queryStatistics.Type = D3DKMTQS_SEGMENT;
queryStatistics.AdapterLuid = adapterDesc.AdapterLuid;
queryStatistics.QuerySegment.SegmentId = i;
if (NT_SUCCESS(queryD3DKMTStatistics(&queryStatistics))) {
bool aperture;
// SegmentInformation has a different definition in Win7 than later versions
if (winVers < gfxWindowsPlatform::kWindows8)
aperture = queryStatistics.QueryResult.SegmentInfoWin7.Aperture;
else
aperture = queryStatistics.QueryResult.SegmentInfoWin8.Aperture;
memset(&queryStatistics, 0, sizeof(D3DKMTQS));
queryStatistics.Type = D3DKMTQS_PROCESS_SEGMENT;
queryStatistics.AdapterLuid = adapterDesc.AdapterLuid;
queryStatistics.hProcess = ProcessHandle;
queryStatistics.QueryProcessSegment.SegmentId = i;
if (NT_SUCCESS(queryD3DKMTStatistics(&queryStatistics))) {
if (aperture)
sharedBytesUsed += queryStatistics.QueryResult
.ProcessSegmentInfo
.BytesCommitted;
else
dedicatedBytesUsed += queryStatistics.QueryResult
.ProcessSegmentInfo
.BytesCommitted;
}
}
}
}
}
FreeLibrary(gdi32Handle);
#define REPORT(_path, _amount, _desc) \
do { \
nsresult rv; \
rv = aCb->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path), \
nsIMemoryReporter::KIND_OTHER, \
nsIMemoryReporter::UNITS_BYTES, _amount, \
NS_LITERAL_CSTRING(_desc), aClosure); \
NS_ENSURE_SUCCESS(rv, rv); \
} while (0)
REPORT("gpu-committed", committedBytesUsed,
"Memory committed by the Windows graphics system.");
REPORT("gpu-dedicated", dedicatedBytesUsed,
//.........这里部分代码省略.........