View Single Post
Old 14th March 2009, 04:07   #299  |  Link
squid_80
Registered User
 
Join Date: Dec 2004
Location: Melbourne, AU
Posts: 1,963
Slightly tweaked code from nvidia's videodecode sample that makes sure a CUDA compatible device is used:
Code:
// Initialize Direct3D
void
initializeD3D(HWND hWnd) 
{
    // Create the D3D object.
    gpD3D = Direct3DCreate9(D3D_SDK_VERSION);
    assert(gpD3D != 0);

    // Get primary display identifier
    D3DADAPTER_IDENTIFIER9 adapterId;
    
    // Find the first CUDA capable device
    unsigned int adapter;
    for(adapter = 0; adapter < gpD3D->GetAdapterCount(); adapter++)
    {
        CUdevice device;
        gpD3D->GetAdapterIdentifier(adapter, 0, &adapterId);
        if (cuD3D9GetDevice(&device, adapterId.DeviceName) == CUDA_SUCCESS)
			break;
    }

    if (adapter == gpD3D->GetAdapterCount())
    {
	// no CUDA device found
	return;
    }

    // Create the D3D Display Device
    RECT                  rc;       
    GetClientRect(hWnd, &rc);
    D3DDISPLAYMODE        d3ddm;    
    gpD3D->GetAdapterDisplayMode(adapter, &d3ddm);
    D3DPRESENT_PARAMETERS d3dpp;    
    ZeroMemory(&d3dpp, sizeof(d3dpp));

    d3dpp.Windowed               = true; // fullscreen or windowed?
    d3dpp.BackBufferCount        = 1;
    d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;
    d3dpp.hDeviceWindow          = hWnd;
    d3dpp.BackBufferWidth	     = rc.right  - rc.left;
    d3dpp.BackBufferHeight       = rc.bottom - rc.top;
    d3dpp.BackBufferFormat       = d3ddm.Format;
    d3dpp.FullScreen_RefreshRateInHz = 0; // set to 60 for fullscreen, and also don't forget to set Windowed to FALSE
    d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE; // D3DPRESENT_DONOTWAIT;
    
    HRESULT eResult = gpD3D->CreateDevice(adapter, D3DDEVTYPE_HAL, hWnd,
                                           D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED,
                                           &d3dpp, &gpD3DDevice);
    assert(S_OK == eResult);
}
squid_80 is offline