Example #1
0
int main(int argc, char** argv)
{
	IDXGIFactory1* factory = 0;
	CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&factory);

	IDXGIAdapter* adapter = NULL;
	for (unsigned int index = 0; SUCCEEDED(factory->EnumAdapters(index, &adapter)); ++index)
	{
		DXGI_ADAPTER_DESC ad = {};
		adapter->GetDesc(&ad);

		if (ad.VendorId == 0x1414 && ad.DeviceId == 0x8c)
			continue; // Skip Microsoft Basic Render Driver

		printf("// GPU %d: %S (Vendor %04x Device %04x)\n", index, ad.Description, ad.VendorId, ad.DeviceId);

		if (argc == 1)
		{
			testCache(adapter);
		}
		else if (argc > 1 && strcmp(argv[1], "--") == 0)
		{
			testCacheSequence(adapter, argc, argv);
		}
		else
		{
			testCacheMeshes(adapter, argc, argv);
		}
	}
}
Example #2
0
void DesktopDuplication::init()
{
	IDXGIFactory1* dxgiFactory = nullptr;
	CHECKED(hr, CreateDXGIFactory1(__uuidof(IDXGIFactory1), reinterpret_cast<void**>(&dxgiFactory)));

	IDXGIAdapter1* dxgiAdapter = nullptr;
	CHECKED(hr, dxgiFactory->EnumAdapters1(adapter, &dxgiAdapter));
	dxgiFactory->Release();

	CHECKED(hr, D3D11CreateDevice(dxgiAdapter,
		D3D_DRIVER_TYPE_UNKNOWN,
		NULL,
		NULL,
		NULL,
		NULL,
		D3D11_SDK_VERSION,
		&d3dDevice,
		NULL,
		&d3dContext));

	IDXGIOutput* dxgiOutput = nullptr;
	CHECKED(hr, dxgiAdapter->EnumOutputs(output, &dxgiOutput));
	dxgiAdapter->Release();

	IDXGIOutput1* dxgiOutput1 = nullptr;
	CHECKED(hr, dxgiOutput->QueryInterface(__uuidof(dxgiOutput1), reinterpret_cast<void**>(&dxgiOutput1)));
	dxgiOutput->Release();

	IDXGIDevice* dxgiDevice = nullptr;
	CHECKED(hr, d3dDevice->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast<void**>(&dxgiDevice)));

	CHECKED(hr, dxgiOutput1->DuplicateOutput(dxgiDevice, &outputDuplication));
	dxgiOutput1->Release();
	dxgiDevice->Release();
}
Example #3
0
static inline void EnumD3DAdapters(
		bool (*callback)(void*, const char*, uint32_t),
		void *param)
{
	ComPtr<IDXGIFactory1> factory;
	ComPtr<IDXGIAdapter1> adapter;
	HRESULT hr;
	UINT i = 0;

	IID factoryIID = (GetWinVer() >= 0x602) ? dxgiFactory2 :
		__uuidof(IDXGIFactory1);

	hr = CreateDXGIFactory1(factoryIID, (void**)factory.Assign());
	if (FAILED(hr))
		throw HRError("Failed to create DXGIFactory", hr);

	while (factory->EnumAdapters1(i++, adapter.Assign()) == S_OK) {
		DXGI_ADAPTER_DESC desc;
		char name[512] = "";

		hr = adapter->GetDesc(&desc);
		if (FAILED(hr))
			continue;

		/* ignore microsoft's 'basic' renderer' */
		if (desc.VendorId == 0x1414 && desc.DeviceId == 0x8c)
			continue;

		os_wcs_to_utf8(desc.Description, 0, name, sizeof(name));

		if (!callback(param, name, i - 1))
			break;
	}
}
Example #4
0
IDXGIAdapter* spoutDirectX::GetAdapterPointer(int index)
{
	// printf("spoutDirectX::GetAdapterPointer(%d)\n", index);

	// Enum Adapters first : multiple video cards
	IDXGIFactory1*	_dxgi_factory1;
	if ( FAILED( CreateDXGIFactory1( __uuidof(IDXGIFactory1), (void**)&_dxgi_factory1 ) ) )	{
		printf( "    Could not create CreateDXGIFactory1\n" );
		return nullptr;
	}

	IDXGIAdapter* adapter1_ptr = nullptr;
	for ( UINT32 i = 0; _dxgi_factory1->EnumAdapters( i, &adapter1_ptr ) != DXGI_ERROR_NOT_FOUND; i++ )	{
		if ( index == (int)i ) {
			// printf("   Adapter %d matches\n", i);
			// Now we have the requested adapter, but does it support the required extensions
			_dxgi_factory1->Release();
			return adapter1_ptr;
		}
		else {
			// printf("   Adapter %d found\n", i);
		}
		adapter1_ptr->Release();
	}

	// printf("   Adapter %d not found\n", index);

	_dxgi_factory1->Release();

	return nullptr;
}
bool CDuplicateOutputDx11::GetSpecificAdapter(int idAdapter, IDXGIAdapter** pAdapter)
{
	HRESULT err = S_OK;

	if (!pAdapter)
	{
		return false;
	}

	REFIID iidVal = __uuidof(IDXGIFactory1);
	UINT adapterID = 0;	// adapter index
	IDXGIFactory1* pFactory = NULL;
	if (FAILED(err = CreateDXGIFactory1(iidVal, (void**)&pFactory)))
	{
		return 	false;
	}
	UINT i = 0;
	UINT adapterDeviceID = idAdapter;		// if device id equal zero, use the first device

	DXGI_ADAPTER_DESC dxgiDesc;
	IDXGIAdapter1 *giAdapter = NULL;
	if (pFactory->EnumAdapters1(i, &giAdapter) != S_OK)
	{
		return false;
	}
	if (pFactory)pFactory->Release();
	*pAdapter = giAdapter;
	return true;
}
Example #6
0
// Get an adapter name
bool spoutDirectX::GetAdapterName(int index, char *adaptername, int maxchars)
{
	IDXGIFactory1* _dxgi_factory1;
	IDXGIAdapter* adapter1_ptr = nullptr;
	UINT32 i;

	if ( FAILED( CreateDXGIFactory1( __uuidof(IDXGIFactory1), (void**)&_dxgi_factory1 ) ) )
		return false;
	
	for ( i = 0; _dxgi_factory1->EnumAdapters( i, &adapter1_ptr ) != DXGI_ERROR_NOT_FOUND; i++ ) {
		if((int)i == index) {
			DXGI_ADAPTER_DESC	desc;
			adapter1_ptr->GetDesc( &desc );
			adapter1_ptr->Release();
			size_t charsConverted = 0;
			wcstombs_s(&charsConverted, adaptername, maxchars, desc.Description, maxchars-1);
			// Is the adapter compatible ?
			// TODO : test for Intel graphics version ?
			// 11.08.15 - removed for use with Intel HD4400/5000 graphics
			// if(strstr(adaptername, "Intel")) {
				// printf("Intel graphics not supported\n");
				// return false;
			// }
			_dxgi_factory1->Release();
			return true;
		}
	}

	_dxgi_factory1->Release();

	return false;
}
Example #7
0
bool spoutDirectX::GetAdapterInfo(char *adapter, char *display, int maxchars)
{
	IDXGIFactory1* _dxgi_factory1;
	IDXGIAdapter* adapter1_ptr = nullptr;
	UINT32 i;
	size_t charsConverted = 0;
	
	// Enum Adapters first : multiple video cards
	if ( FAILED( CreateDXGIFactory1( __uuidof(IDXGIFactory1), (void**)&_dxgi_factory1 ) ) )
		return false;

	for ( i = 0; _dxgi_factory1->EnumAdapters( i, &adapter1_ptr ) != DXGI_ERROR_NOT_FOUND; i++ )	{

		DXGI_ADAPTER_DESC	desc;
		adapter1_ptr->GetDesc( &desc );

		// Return the current adapter - max of 2 assumed
		wcstombs_s(&charsConverted, adapter, maxchars, desc.Description, maxchars-1);

		IDXGIOutput*	p_output = nullptr;
		for ( UINT32 j = 0; adapter1_ptr->EnumOutputs( j, &p_output ) != DXGI_ERROR_NOT_FOUND; j++ ) {
			DXGI_OUTPUT_DESC	desc_out;
			p_output->GetDesc( &desc_out );
			if(desc_out.AttachedToDesktop)
				wcstombs_s(&charsConverted, display, maxchars, desc.Description, maxchars-1);
			if( p_output )
				p_output->Release();
		}
	}

	_dxgi_factory1->Release();

	return true;
}
Example #8
0
// Get an adapter name
bool spoutDirectX::GetAdapterName(int index, char *adaptername, int maxchars)
{
	IDXGIFactory1* _dxgi_factory1;
	IDXGIAdapter* adapter1_ptr = nullptr;
	UINT32 i;

	if ( FAILED( CreateDXGIFactory1( __uuidof(IDXGIFactory1), (void**)&_dxgi_factory1 ) ) )
		return false;
	
	for ( i = 0; _dxgi_factory1->EnumAdapters( i, &adapter1_ptr ) != DXGI_ERROR_NOT_FOUND; i++ ) {
		if((int)i == index) {
			DXGI_ADAPTER_DESC	desc;
			adapter1_ptr->GetDesc( &desc );
			adapter1_ptr->Release();
			size_t charsConverted = 0;
			wcstombs_s(&charsConverted, adaptername, maxchars, desc.Description, maxchars-1);
			// Is the adapter compatible ? TODO
			_dxgi_factory1->Release();
			return true;
		}
	}

	_dxgi_factory1->Release();

	return false;
}
CD3DRenderer::CD3DRenderer(HWND& window)
{
	m_hWnd = window;
	if(FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&m_pdxgiFactory)))
		g_pDebug->printError("Failed to create DXGI Factory.");

	IDXGIAdapter1 * pAdapter;

	for (UINT i = 0;
		m_pdxgiFactory->EnumAdapters1(i, &pAdapter) != DXGI_ERROR_NOT_FOUND;
		++i)
		m_vAdapters.push_back(pAdapter);
	
	IDXGIOutput *pOutput;
	m_vAdapters[m_uiCurrentAdapter]->EnumOutputs(0, &pOutput);
	
	UINT modeCount;
	pOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &modeCount, nullptr);
	DXGI_MODE_DESC *descArr = new DXGI_MODE_DESC[modeCount];
	pOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &modeCount, descArr);
	for (UINT i = 0; i < modeCount; i++)
	{
		if (descArr[i].RefreshRate.Numerator / descArr[i].RefreshRate.Denominator <= 60)
			m_vAdapterModes.push_back(descArr[i]);
	}
	pOutput->Release();
	delete[] descArr;
}
BOOL CALLBACK create_device(PINIT_ONCE ignored, void *ignored2,
    void **ignored3) {
  debug_log("creating device");
  HRESULT hr;
  hr = CreateDXGIFactory1(__uuidof(IDXGIFactory2), (void **)&dxgi_factory);
  assert(hr == S_OK);
  hr = dxgi_factory->EnumAdapters1(0, &dxgi_adapter);
  assert(hr == S_OK);
  hr = dxgi_adapter->EnumOutputs(0, &dxgi_output);
  assert(hr == S_OK);
  hr = dxgi_output->QueryInterface(__uuidof(IDXGIOutput1),
      (void **)&dxgi_output1);
  assert(hr == S_OK);
  const D3D_FEATURE_LEVEL levels[] = { D3D_FEATURE_LEVEL_11_0 };
  D3D_FEATURE_LEVEL out_level;
  UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#ifndef NDEBUG
  flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
  hr = D3D11CreateDevice(dxgi_adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, flags,
      levels, 1, D3D11_SDK_VERSION, &device, &out_level, &context);
  assert(hr == S_OK);
  hr = dxgi_output1->DuplicateOutput(device, &dxgi_output_duplication);
  assert(hr == S_OK);
  InitializeCriticalSection(&directx_critical_section);
  return TRUE;
}
Example #11
0
void Direct3DManager::InitializeDeviceResources()
{
	
#if defined(_DEBUG)
	// If the project is in a debug build, enable debugging via SDK Layers.
{
	ID3D12Debug *debugController;
	if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController))))
	{
		debugController->EnableDebugLayer();
	}

	debugController->Release();
	debugController = NULL;
}
#endif

	Direct3DUtils::ThrowIfHRESULTFailed(CreateDXGIFactory1(IID_PPV_ARGS(&mDXGIFactory)));

	// Create the Direct3D 12 API device object
	Direct3DUtils::ThrowIfHRESULTFailed(D3D12CreateDevice(
		nullptr,						// Specify nullptr to use the default adapter.
		D3D_FEATURE_LEVEL_11_0,			// Minimum feature level this app can support.
		IID_PPV_ARGS(&mDevice)		// Returns the Direct3D device created.
		));

	mContextManager = new Direct3DContextManager(mDevice);
}
static HRESULT find_output()
{
	CComPtr<IDXGIFactory1> pFactory;
	HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void **)(&pFactory));
	for (UINT i = 0; ; i++) {
		CComPtr<IDXGIAdapter1> pAdapter;
		if (S_OK != (hr = pFactory->EnumAdapters1(i, &pAdapter))) {
			break;
		}

		aslog::info(L"Found adapter %d", i);

		for (UINT j = 0; ; j++) {
			CComPtr<IDXGIOutput> pOutput;
			if (S_OK != (hr = pAdapter->EnumOutputs(j, &pOutput))) {
				break;
			}

			aslog::info(L"Found output %d-%d", i, j);
			DXGI_OUTPUT_DESC desc;
			pOutput->GetDesc(&desc);
			aslog::info(L"Output %d-%d name: %s", i, j, desc.DeviceName);
			aslog::info(L"Output %d-%d attached to desktop: %s", i, j, desc.AttachedToDesktop ? L"true" : L"false");

			g_pAdapter = pAdapter;
			g_pOutput = pOutput;
			hr = D3D11CreateDevice(pAdapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, D3D11_CREATE_DEVICE_DEBUG, NULL, 0, D3D11_SDK_VERSION, &g_pDevice, NULL, &g_pContext);
			return hr;
		}
	}
	return hr;
}
Example #13
0
void GetDisplayDevices(DeviceOutputs &deviceList)
{
    HRESULT err;

    deviceList.ClearData();

#ifdef USE_DXGI1_2
    REFIID iidVal = OSGetVersion() >= 8 ? __uuidof(IDXGIFactory2) : __uuidof(IDXGIFactory1);
#else
    REFIIF iidVal = __uuidof(IDXGIFactory1);
#endif

    IDXGIFactory1 *factory;
    if(SUCCEEDED(err = CreateDXGIFactory1(iidVal, (void**)&factory)))
    {
        UINT i=0;
        IDXGIAdapter1 *giAdapter;

        while(factory->EnumAdapters1(i++, &giAdapter) == S_OK)
        {
            Log(TEXT("------------------------------------------"));

            DXGI_ADAPTER_DESC adapterDesc;
            if(SUCCEEDED(err = giAdapter->GetDesc(&adapterDesc)))
            {
                if (adapterDesc.DedicatedVideoMemory != 0) {
                    DeviceOutputData &deviceData = *deviceList.devices.CreateNew();
                    deviceData.strDevice = adapterDesc.Description;

                    UINT j=0;
                    IDXGIOutput *giOutput;
                    while(giAdapter->EnumOutputs(j++, &giOutput) == S_OK)
                    {
                        DXGI_OUTPUT_DESC outputDesc;
                        if(SUCCEEDED(giOutput->GetDesc(&outputDesc)))
                        {
                            if(outputDesc.AttachedToDesktop)
                            {
                                deviceData.monitorNameList << outputDesc.DeviceName;

                                MonitorInfo &monitorInfo = *deviceData.monitors.CreateNew();
                                monitorInfo.hMonitor = outputDesc.Monitor;
                                mcpy(&monitorInfo.rect, &outputDesc.DesktopCoordinates, sizeof(RECT));
                            }
                        }

                        giOutput->Release();
                    }
                }
            }
            else
                AppWarning(TEXT("Could not query adapter %u"), i);

            giAdapter->Release();
        }

        factory->Release();
    }
}
std::unique_ptr< WindowsAdapter > CreateWindowsAdapter( const int id ) noexcept {
	ComPtr< IDXGIFactory1 > factory;
	auto hresult = CreateDXGIFactory1( __uuidof( IDXGIFactory1 ), reinterpret_cast< void** >( &factory ) );
	if ( FAILED( hresult ) ) {
		return nullptr;
	}
	return CreateAdapter( factory, id );
}
Example #15
0
HRESULT WINAPI HookDXGIFactory(REFIID riid, void **ppFactory)
{
	// We need shared texture support for OpenVR, so force DXGI 1.0 games to use DXGI 1.1
	IDXGIFactory1* pDXGIFactory;
	HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void **)&pDXGIFactory);
	if (FAILED(hr))
		return hr;
	return pDXGIFactory->QueryInterface(riid, ppFactory);
}
Example #16
0
// LJ DEBUG
bool spoutDirectX::FindNVIDIA(int &nAdapter)
{
	IDXGIFactory1* _dxgi_factory1;
	IDXGIAdapter* adapter1_ptr = nullptr;
	DXGI_ADAPTER_DESC desc;
	// DXGI_OUTPUT_DESC desc_out;
	UINT32 i;
	bool bFound = false;

	if ( FAILED( CreateDXGIFactory1( __uuidof(IDXGIFactory1), (void**)&_dxgi_factory1 ) ) )
		return false;

	for ( i = 0; _dxgi_factory1->EnumAdapters( i, &adapter1_ptr ) != DXGI_ERROR_NOT_FOUND; i++ )	{
		adapter1_ptr->GetDesc( &desc );
		printf( "Adapter(%d) : %S\n", i, desc.Description );
		/*
		IDXGIOutput* p_output = nullptr;
		if(adapter1_ptr->EnumOutputs(0, &p_output ) == DXGI_ERROR_NOT_FOUND) {
			printf("  No outputs\n");
			continue;
		}

		for ( UINT32 j = 0; adapter1_ptr->EnumOutputs( j, &p_output ) != DXGI_ERROR_NOT_FOUND; j++ ) {
			p_output->GetDesc( &desc_out );
			// printf( "  Output : %d\n", j );
			// printf( "    Name %S\n", desc_out.DeviceName );
			// printf( "    Attached to desktop : (%d) %s\n", desc_out.AttachedToDesktop, desc_out.AttachedToDesktop ? "yes" : "no" );
			// printf( "    Rotation : %d\n", desc_out.Rotation );
			// printf( "    Left     : %d\n", desc_out.DesktopCoordinates.left );
			// printf( "    Top      : %d\n", desc_out.DesktopCoordinates.top );
			// printf( "    Right    : %d\n", desc_out.DesktopCoordinates.right );
			// printf( "    Bottom   : %d\n", desc_out.DesktopCoordinates.bottom );
			if( p_output )
				p_output->Release();
		}
		*/

		if(wcsstr(desc.Description, L"NVIDIA")) {
			// printf("Found NVIDIA adapter %d (%S)\n", i, desc.Description);
			bFound = true;
			break;
		}

	}

	_dxgi_factory1->Release();

	if(bFound) {
		printf("Found NVIDIA adapter %d (%S)\n", i, desc.Description);
		nAdapter = i;
		return true;
	}

	return false;

}
Example #17
0
// Get the number of graphics adapters in the system
int spoutDirectX::GetNumAdapters()
{
	IDXGIFactory1* _dxgi_factory1;
	IDXGIAdapter* adapter1_ptr = nullptr;
	UINT32 i;

	// printf("spoutDirectX::GetNumAdapters\n");

	// Enum Adapters first : multiple video cards
	if ( FAILED( CreateDXGIFactory1( __uuidof(IDXGIFactory1), (void**)&_dxgi_factory1 ) ) )
		return 0;

	for ( i = 0; _dxgi_factory1->EnumAdapters( i, &adapter1_ptr ) != DXGI_ERROR_NOT_FOUND; i++ )	{
		// DXGI_ADAPTER_DESC	desc;
		// adapter1_ptr->GetDesc( &desc );
		// printf( "Adapter : %S\n", desc.Description );
		// adapter1_ptr->Release();

		// printf( "bdd_spout : D3D11 Adapter %d found\n", i );
		DXGI_ADAPTER_DESC	desc;
		adapter1_ptr->GetDesc( &desc );
		printf( "Adapter(%d) : %S\n", i, desc.Description );
		printf( "  Vendor Id : %d\n", desc.VendorId );
		// printf( "  Dedicated System Memory : %.0f MiB\n", (float)desc.DedicatedSystemMemory / (1024.f * 1024.f) );
		// printf( "  Dedicated Video Memory : %.0f MiB\n", (float)desc.DedicatedVideoMemory / (1024.f * 1024.f) );
		// printf( "  Shared System Memory : %.0f MiB\n", (float)desc.SharedSystemMemory / (1024.f * 1024.f) );
		
		IDXGIOutput* p_output = nullptr;
		if(adapter1_ptr->EnumOutputs(0, &p_output ) == DXGI_ERROR_NOT_FOUND) {
			printf("  No outputs\n");
		}

		for ( UINT32 j = 0; adapter1_ptr->EnumOutputs( j, &p_output ) != DXGI_ERROR_NOT_FOUND; j++ ) {
			DXGI_OUTPUT_DESC	desc_out;
			p_output->GetDesc( &desc_out );
			printf( "  Output : %d\n", j );
			printf( "    Name %S\n", desc_out.DeviceName );
			printf( "    Attached to desktop : (%d) %s\n", desc_out.AttachedToDesktop, desc_out.AttachedToDesktop ? "yes" : "no" );
			printf( "    Rotation : %d\n", desc_out.Rotation );
			printf( "    Left     : %d\n", desc_out.DesktopCoordinates.left );
			printf( "    Top      : %d\n", desc_out.DesktopCoordinates.top );
			printf( "    Right    : %d\n", desc_out.DesktopCoordinates.right );
			printf( "    Bottom   : %d\n", desc_out.DesktopCoordinates.bottom );
			if( p_output )
				p_output->Release();

		}
	}

	_dxgi_factory1->Release();

	return (int)i;

}
Example #18
0
/// Overriden in derived class to initialize the graphics required for a render loop. The render loop acts as a message pump to the user clients.
/// \return True if success, false if failure
bool DX12Player::InitializeGraphics()
{
    ID3D12Device* graphicsDevice = nullptr;

    UINT frameCount = 2;

    // Initialize all pipeline components necessary to render a frame.
    /// Invoking these calls will allow the DXGI/DX12Server plugins to be injected into our player application.

    // @TODO: In the future, the following commands will invoked by loaded a capture file,
    // initializing, and executing all captured calls. Spinning on the target frame will beat
    // the DX12Server's message loop, allowing communicate with GPUPerfServer.
    IDXGIFactory4* factory = nullptr;
    ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));

    ThrowIfFailed(D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&graphicsDevice)));

    // Describe and create the command queue.
    D3D12_COMMAND_QUEUE_DESC queueDesc = {};
    queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
    queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;

    ID3D12CommandQueue* commandQueue = nullptr;
    ThrowIfFailed(graphicsDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&commandQueue)));

    // Describe and create the swap chain.
    DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
    swapChainDesc.BufferCount = frameCount;
    swapChainDesc.BufferDesc.Width = m_pPlayerWindow->GetWindowWidth();
    swapChainDesc.BufferDesc.Height = m_pPlayerWindow->GetWindowHeight();
    swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;

    // The window handle must be set before being used here.
    swapChainDesc.OutputWindow = m_pPlayerWindow->GetWindowHandle();
    swapChainDesc.SampleDesc.Count = 1;
    swapChainDesc.Windowed = TRUE;

    HRESULT res = factory->CreateSwapChain(commandQueue, &swapChainDesc, (IDXGISwapChain**)&m_swapchain);

    ThrowIfFailed(res);

    if (res != S_OK)
    {
        return false;
    }
    else
    {
        return true;
    }

}
Example #19
0
HRESULT AppTest::CreateDeviceAndSwapChain(IDXGIAdapter * adapter,
										  D3D_DRIVER_TYPE driverType, 
										  D3D_FEATURE_LEVEL minFeatureLevel, 
										  CONST DXGI_SWAP_CHAIN_DESC * swapChainDesc, 
										  REFIID riidSwapChain, 
										  void ** ppSwapChain, 
										  REFIID riidDevice, 
										  void ** ppDevice, 
										  REFIID riidQueue,
										  void ** ppQueue)
{
	ComPtr<ID3D12Device> device;
	ComPtr<IDXGIFactory> dxgiFactory;
	ComPtr<IDXGISwapChain> swapChain;
	ComPtr<ID3D12CommandQueue> queue;

	HRESULT hr = D3D12CreateDevice(adapter, minFeatureLevel, IID_PPV_ARGS(device.GetAddressOf()));

	if (FAILED(hr))
		return hr;

	D3D12_COMMAND_QUEUE_DESC queueDesc;
	ZeroMemory(&queueDesc, sizeof(queueDesc));
	queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
	queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
	hr = device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(queue.GetAddressOf()));

	hr = CreateDXGIFactory1(IID_PPV_ARGS(dxgiFactory.GetAddressOf()));
	if (FAILED(hr))
		return hr;

	DXGI_SWAP_CHAIN_DESC localSwapChainDesc = *swapChainDesc;
	hr = dxgiFactory->CreateSwapChain(queue.Get(), &localSwapChainDesc, &swapChain);
	if (FAILED(hr))
		return hr;

	hr = device.Get()->QueryInterface(riidDevice, ppDevice);
	if (FAILED(hr))
		return hr;

	hr = queue.Get()->QueryInterface(riidQueue, ppQueue);
	if (FAILED(hr))
		return hr;

	hr = swapChain.Get()->QueryInterface(riidSwapChain, ppSwapChain);
	if (FAILED(hr))
	{
		reinterpret_cast<IUnknown*>(*ppDevice)->Release();
		return hr;
	}

	return S_OK;
}
Example #20
0
void LogVideoCardStats()
{
    HRESULT err;

#ifdef USE_DXGI1_2
    REFIID iidVal = OSGetVersion() >= 8 ? __uuidof(IDXGIFactory2) : __uuidof(IDXGIFactory1);
#else
    REFIIF iidVal = __uuidof(IDXGIFactory1);
#endif

    IDXGIFactory1 *factory;
    if(SUCCEEDED(err = CreateDXGIFactory1(iidVal, (void**)&factory)))
    {
        UINT i=0;
        IDXGIAdapter1 *giAdapter;

        while(factory->EnumAdapters1(i++, &giAdapter) == S_OK)
        {
            DXGI_ADAPTER_DESC adapterDesc;
            if(SUCCEEDED(err = giAdapter->GetDesc(&adapterDesc)))
            {
                if (!(adapterDesc.VendorId == 0x1414 && adapterDesc.DeviceId == 0x8c)) { // Ignore Microsoft Basic Render Driver
                    Log(TEXT("------------------------------------------"));
                    Log(TEXT("Adapter %u"), i);
                    Log(TEXT("  Video Adapter: %s"), adapterDesc.Description);
                    Log(TEXT("  Video Adapter Dedicated Video Memory: %u"), adapterDesc.DedicatedVideoMemory);
                    Log(TEXT("  Video Adapter Shared System Memory: %u"), adapterDesc.SharedSystemMemory);

                    UINT j = 0;
                    IDXGIOutput *output;
                    while(SUCCEEDED(giAdapter->EnumOutputs(j++, &output)))
                    {
                        DXGI_OUTPUT_DESC desc;
                        if(SUCCEEDED(output->GetDesc(&desc)))
                            Log(TEXT("  Video Adapter Output %u: pos={%d, %d}, size={%d, %d}, attached=%s"), j,
                                desc.DesktopCoordinates.left, desc.DesktopCoordinates.top,
                                desc.DesktopCoordinates.right-desc.DesktopCoordinates.left, desc.DesktopCoordinates.bottom-desc.DesktopCoordinates.top,
                                desc.AttachedToDesktop ? L"true" : L"false");
                        output->Release();
                    }
                }
            }
            else
                AppWarning(TEXT("Could not query adapter %u"), i);

            giAdapter->Release();
        }

        factory->Release();
    }
}
void gs_device::InitFactory(uint32_t adapterIdx, IDXGIAdapter1 **padapter)
{
	HRESULT hr;
	IID factoryIID = (GetWinVer() >= 0x602) ? dxgiFactory2 :
		__uuidof(IDXGIFactory1);

	hr = CreateDXGIFactory1(factoryIID, (void**)factory.Assign());
	if (FAILED(hr))
		throw UnsupportedHWError("Failed to create DXGIFactory", hr);

	hr = factory->EnumAdapters1(adapterIdx, padapter);
	if (FAILED(hr))
		throw UnsupportedHWError("Failed to enumerate DXGIAdapter", hr);
}
Example #22
0
    bool Device::apiInit(const Desc& desc)
    {
        DeviceApiData* pData = new DeviceApiData;
        mpApiData = pData;

        if (desc.enableDebugLayer)
        {
            ID3D12DebugPtr pDebug;
            if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&pDebug))))
            {
                pDebug->EnableDebugLayer();
            }
        }

        // Create the DXGI factory
        d3d_call(CreateDXGIFactory1(IID_PPV_ARGS(&mpApiData->pDxgiFactory)));

        mApiHandle = createDevice(mpApiData->pDxgiFactory, getD3DFeatureLevel(desc.apiMajorVersion, desc.apiMinorVersion), desc.createDeviceFunc, mRgb32FloatSupported);
        if (mApiHandle == nullptr)
        {
            return false;
        }

        for (uint32_t i = 0; i < kQueueTypeCount; i++)
        {
            for (uint32_t j = 0; j < desc.cmdQueues[i]; j++)
            {
                // Create the command queue
                D3D12_COMMAND_QUEUE_DESC cqDesc = {};
                cqDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
                cqDesc.Type = getApiCommandQueueType((LowLevelContextData::CommandQueueType)i);

                ID3D12CommandQueuePtr pQueue;
                if (FAILED(mApiHandle->CreateCommandQueue(&cqDesc, IID_PPV_ARGS(&pQueue))))
                {
                    logError("Failed to create command queue");
                    return nullptr;
                }

                mCmdQueues[i].push_back(pQueue);
            }
        }

        uint64_t freq;
        d3d_call(getCommandQueueHandle(LowLevelContextData::CommandQueueType::Direct, 0)->GetTimestampFrequency(&freq));
        mGpuTimestampFrequency = 1000.0 / (double)freq;

        return true;
    }
Example #23
0
	IDXGIAdapter1	*D3D11Renderer::GetPrimaryAdaptor()
	{
		IDXGIFactory1	*factory = 0;

		if (CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void **)&factory) == S_OK)
		{
			IDXGIAdapter1	*adapter = 0;
				
			factory->EnumAdapters1(0, &adapter);
			memory::SafeRelease(&factory);
			memory::SafeRelease(&adapter);
			return adapter;
		}
		memory::SafeRelease(&factory);
		return 0;
	}
Example #24
0
	void	D3D11Renderer::EnumerateDisplayModes()
	{
		IDXGIFactory1	*factory = 0;

		if (CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void **)&factory) == S_OK)
		{
			IDXGIAdapter1	*adapter = 0;
			for (UINT i = 0; factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND; i++)
			{
				DXGI_ADAPTER_DESC1 ad;
				adapter->GetDesc1(&ad);

				char description[128];
				size_t n;
				wcstombs_s(&n, description, ad.Description, 128);

				ATOM_LOG("-------------------------------------------------------------------------------\n");
				ATOM_LOG("[info]: adapter[%d]: %s\n", i, description);
				ATOM_LOG("[info]: - revision: %d\n", i, ad.Revision);
				ATOM_LOG("[info]: - video memory: %d\n", i, ad.DedicatedVideoMemory / 1024 / 1024);
				ATOM_LOG("[info]: - system memory: %d\n", i, ad.DedicatedSystemMemory / 1024 / 1024);
				ATOM_LOG("[info]: - shared system memory: %d\n", i, ad.SharedSystemMemory / 1024 / 1024);

				IDXGIOutput	*output = 0;
				for (UINT j = 0; adapter->EnumOutputs(j, &output) != DXGI_ERROR_NOT_FOUND; j++)
				{
					UINT			modesCount;
					DXGI_FORMAT		format = g_settings.format;

					output->GetDisplayModeList(format, 0, &modesCount, 0);
					DXGI_MODE_DESC	*modeDescs = new DXGI_MODE_DESC[modesCount];
					output->GetDisplayModeList(format, 0, &modesCount, modeDescs);

					ATOM_LOG("[info]: - output %d display modes(%d)\n", j, modesCount);
					for (UINT k = 0; k < modesCount; k++)
					{
						ATOM_LOG("[info]: -- mode[%d]: %d * %d", k, modeDescs[k].Width, modeDescs[k].Height);
						ATOM_LOG(", refresh rate: %d/%d\n", modeDescs[i].RefreshRate.Numerator, modeDescs[i].RefreshRate.Denominator);
					}
					delete[] modeDescs;
					memory::SafeRelease(&output);
				}
				memory::SafeRelease(&adapter);
			}
		}
		memory::SafeRelease(&factory);
	}
    bool SystemCheck::CheckVRAMSize()
    {
        HRESULT hr;
        D3D_FEATURE_LEVEL FeatureLevel;

        CComPtr<IDXGIFactory1> DXGIFactory;

        hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&DXGIFactory);
        if(SUCCEEDED(hr))
        {
            CComPtr<IDXGIAdapter1> Adapter;

            hr = DXGIFactory->EnumAdapters1(0, &Adapter);
            if(SUCCEEDED(hr))
            {
                CComPtr<ID3D11Device> Device;
                CComPtr<ID3D11DeviceContext> DeviceContext;

                hr = D3D11CreateDevice(Adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr,
                    D3D11_CREATE_DEVICE_BGRA_SUPPORT, nullptr, 0, D3D11_SDK_VERSION,
                    &Device, &FeatureLevel, &DeviceContext);

                if(SUCCEEDED(hr))
                {
                    DXGI_ADAPTER_DESC adapterDesc;
                    Adapter->GetDesc(&adapterDesc);

                    std::wstring Description = adapterDesc.Description;
                    INT64 VideoRam = adapterDesc.DedicatedVideoMemory;
                    INT64 SystemRam = adapterDesc.DedicatedSystemMemory;
                    INT64 SharedRam = adapterDesc.SharedSystemMemory;

                    std::wcout << "***************** GRAPHICS ADAPTER DETAILS ***********************" << endl;;
                    std::wcout << "Adapter Description: " << Description << endl;
                    std::wcout << "Dedicated Video RAM: " << VideoRam << endl;
                    std::wcout << "Dedicated System RAM: " << SystemRam << endl;
                    std::wcout << "Shared System RAM: " << SharedRam << endl;
                    std::wcout << "PCI ID: " << Description << endl;
                    std::wcout << "Feature Level: " << FeatureLevel << endl;
                }
            }
        }    

        return true;
    }
Example #26
0
/**
 * コンストラクタ
 *
 * @param hwnd					ウィンドウハンドル
 * @param w						バックバッファの幅
 * @param h						バックバッファの高さ
 * @param full_screen			フルスクリーンフラグ
 * @param adapter_format		未使用
 * @param depth_stencil_format	未使用
 * @param multi_sample_count	マルチサンプリングのサンプル数
 * @param multi_sample_quality	マルチサンプリングのクオリティ
 */
Direct3D11::Direct3D11( HWND hwnd, int w, int h, bool full_screen, const char* /* adapter_format */, const char* /* depth_stencil_format */, int multi_sample_count, int multi_sample_quality )
	: device_( 0 )
	, immediate_context_( 0 )
	, swap_chain_( 0 )
	
	, back_buffer_texture_( 0 )
	, back_buffer_view_( 0 )

	, depth_stencil_texture_( 0 )
	, depth_stencil_view_( 0 )

	, device_10_( 0 )
	, back_buffer_surface_( 0 )
	, text_texture_( 0 )
	, text_view_( 0 )
	, text_texture_mutex_11_( 0 )
	, text_texture_mutex_10_( 0 )
{
	common::log( "log/d3d11.log", "init", false );

	IDXGIFactory1* dxgi_factory = 0;
	DIRECT_X_FAIL_CHECK( CreateDXGIFactory1( __uuidof( IDXGIFactory1 ), reinterpret_cast< void** >( & dxgi_factory ) ) );

	log_all_adapter_desc( dxgi_factory );

	DIRECT_X_FAIL_CHECK( dxgi_factory->EnumAdapters1( 0, & dxgi_adapter_ ) );

	create_device();

	log_feature_level();

	create_swap_chain( dxgi_factory, hwnd, w, h, full_screen, multi_sample_count, multi_sample_quality );

	DIRECT_X_RELEASE( dxgi_factory );

	create_back_buffer_view();
	create_back_buffer_surface();

	create_depth_stencil_view();
	
	setup_viewport();

	sprite_ = new Sprite( this );
	effect_ = new Effect( this );
}
Example #27
0
std::vector<IDXGIAdapter*> EnumerateDXGIAdapters() {
  IDXGIAdapter * adaptor; 
  std::vector <IDXGIAdapter*> adaptors; 
  IDXGIFactory1* factory = NULL; 

  // Create a DXGIFactory object.
  if(FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1) ,(void**)&factory))) {
    return adaptors;
  }

  for (auto i = 0; factory->EnumAdapters(i, &adaptor) != DXGI_ERROR_NOT_FOUND; ++i)  {
    adaptors.push_back(adaptor); 
  } 

  SafeRelease(&factory);

  return adaptors;
}
Example #28
0
	DXGI_RATIONAL	D3D11Renderer::GetDefaultRefreshRate()
	{
		DXGI_RATIONAL	refreshRate = {59, 1};
		IDXGIFactory1	*factory = 0;

		if (CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void **)&factory) == S_OK)
		{
			IDXGIAdapter1	*adapter = 0;
			for (UINT i = 0; factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND; i++)
			{
				DXGI_ADAPTER_DESC1 ad;
				IDXGIOutput	*output = 0;

				adapter->GetDesc1(&ad);
				for (UINT j = 0; adapter->EnumOutputs(j, &output) != DXGI_ERROR_NOT_FOUND; j++)
				{
					UINT			modesCount;
					DXGI_FORMAT		format = g_settings.format;

					output->GetDisplayModeList(format, 0, &modesCount, 0);
					DXGI_MODE_DESC	*modeDescs = new DXGI_MODE_DESC[modesCount];
					output->GetDisplayModeList(format, 0, &modesCount, modeDescs);
					for (UINT k = 0; k < modesCount; k++)
					{
						if (modeDescs[k].Width == (UINT)g_settings.width &&
							modeDescs[k].Height == (UINT)g_settings.height)
						{
							refreshRate = modeDescs[i].RefreshRate;
							delete[] modeDescs;
							memory::SafeRelease(&output);
							memory::SafeRelease(&adapter);
							memory::SafeRelease(&factory);
							return refreshRate;
						}
					}
					delete[] modeDescs;
					memory::SafeRelease(&output);
				}
				memory::SafeRelease(&adapter);
			}
		}
		memory::SafeRelease(&factory);
		return refreshRate;
	}
std::unique_ptr< WindowsAdapter > CreateWindowsAdapter( const WindowsAdapterCapabilities& capabilities ) noexcept {
	ComPtr< IDXGIFactory1 > factory;
	auto hresult = CreateDXGIFactory1( __uuidof( IDXGIFactory1 ), reinterpret_cast< void** >( &factory ) );
	if ( FAILED( hresult ) ) {
		return nullptr;
	}
	int id = 0;
	auto adapter = CreateAdapter( factory, id );
	while ( adapter != nullptr ) {
		// check capabilities
		if ( adapter->CheckCapabilities( capabilities ) ) {
			return adapter;
		}
		// next adapter
		id += 1;
		adapter = CreateAdapter( factory, id );
	}
	return nullptr;
}
Example #30
0
bool RenderCore::EnumerateDisplayAdapters(std::vector<IDXGIAdapter1 *> *dxgiAdapters)
{
	IDXGIAdapter1 *pAdapter;
	IDXGIFactory1 *pFactory = nullptr;
	HRESULT hr;

	hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory);
	if (FAILED(hr)) {
		return false;
	}
	
	for (UINT i = 0; pFactory->EnumAdapters1(i, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++i) {
		dxgiAdapters->push_back(pAdapter);
		//m_VideoAdapterList.push_back(pAdapter);
	}

	if (pFactory) {
		pFactory->Release();
	}

	return true;
};