Example #1
0
//-----------------------------------------------------------------------------
GpuPtr Helper::getGpu(int index)
{
    // Check it against selection criteria.
    pair_int gpuBlock = selectDeviceAndBlock(index);
    if (-1 == gpuBlock.first) return GpuPtr();

    scoped_lock lock(mutex);

    // First check to see if this GPU device has been initialized.
    DevicePtr device;
    DevicelPtrMap::iterator dit = devPtrMap.find(gpuBlock.first);
    if (dit == devPtrMap.end())
    {
        device.reset(new Device(gpuBlock.first));
        // Double check to make sure our device is OK
        if (-1 == device->ID()) return GpuPtr();
        devPtrMap.insert(std::make_pair(gpuBlock.first, device));
    }
    else
    {
        device = dit->second;
        // Make sure we activate this per-thread.
        device->setDevice();
    }

    // Now that we have a device, get the block implementation handle.
    GpuPtr impl;
    GpuPtrMap::iterator it = gpuPtrMap.find(index);
    if (it == gpuPtrMap.end())
    {
        impl.reset(new Gpu(device));
        gpuPtrMap.insert(std::make_pair(index, impl));
    }
    else
    {
        impl = it->second;
    }

    if (!atExitRegistered)
    {
        atexit(Helper::destroy);
        atExitRegistered = true;
    }
    return impl;
}
Example #2
0
	bool Create(HWND hWnd)
	{
		// デバイスとスワップチェーンの作成。
		RECT rectClient;
		GetClientRect(hWnd, &rectClient);

		DXGI_SWAP_CHAIN_DESC sd;
		ZeroMemory(&sd, sizeof(sd));
		sd.BufferCount = 1;
		sd.BufferDesc.Width = rectClient.right - rectClient.left;
		sd.BufferDesc.Height = rectClient.bottom - rectClient.top;
		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 = hWnd;
		sd.SampleDesc.Count = 1;
		sd.SampleDesc.Quality = 0;//1;
		sd.Windowed = TRUE;
		sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
			
		D3D_FEATURE_LEVEL featureLevel;
		
		IDXGISwapChain* pSwapChainTmp;
		ID3D11Device* pDeviceTmp;
		ID3D11DeviceContext* pDeviceContextTmp;
		HRESULT hr = D3D11CreateDeviceAndSwapChain(NULL	// pAdapter
			, D3D_DRIVER_TYPE_HARDWARE	// DriverType
			, NULL	// Software
			, 0	// Flags
			, NULL	// pFeatureLevels
			, 0// FeatureLevels
			, D3D11_SDK_VERSION
			, &sd
			, &pSwapChainTmp
			, &pDeviceTmp
			, &featureLevel
			, &pDeviceContextTmp
			);
		if (FAILED(hr))
		{
			DebugTraceHresult(hr);
			return false;
		}
		_pSwapChain.reset(pSwapChainTmp, &SafeRelease<SwapChainPtr::element_type>);
		_pDevice.reset(pDeviceTmp, &SafeRelease<DevicePtr::element_type>);
		_pDeviceContext.reset(pDeviceContextTmp, &SafeRelease<DeviceContextPtr::element_type>);

		switch (featureLevel)
		{
		case D3D_FEATURE_LEVEL_11_0:	DebugTrace(_T("D3D_FEATURE_LEVEL_11_0")); break;
		case D3D_FEATURE_LEVEL_10_0:	DebugTrace(_T("D3D_FEATURE_LEVEL_10_0")); break;
		case D3D_FEATURE_LEVEL_10_1:	DebugTrace(_T("D3D_FEATURE_LEVEL_10_1")); break;
		case D3D_FEATURE_LEVEL_9_3:		DebugTrace(_T("D3D_FEATURE_LEVEL_9_3")); break;
		case D3D_FEATURE_LEVEL_9_2:		DebugTrace(_T("D3D_FEATURE_LEVEL_9_2")); break;
		case D3D_FEATURE_LEVEL_9_1:		DebugTrace(_T("D3D_FEATURE_LEVEL_9_1")); break;
		default:						DebugTrace(_T("Unknown")); break;
		}
		
		return true;
	}