예제 #1
0
void InitGpuInfo()
{
	DXUTDeviceSettings setting =  DXUTGetDeviceSettings();
	CD3D9Enumeration* pd3dEnum = DXUTGetD3D9Enumeration();
	CD3D9EnumAdapterInfo* info = pd3dEnum->GetAdapterInfo( setting.d3d9.AdapterOrdinal );
	
#ifdef UNICODE
	MultiByteToWideChar(CP_ACP, 0, info->AdapterIdentifier.Description, -1, gEnv->pSystemInfo->gpuDesc, 255);
#else
	_tcscpy( gEnv->pSystemInfo->gpuDesc, info->AdapterIdentifier.Description );
#endif
	
	gEnv->pSystemInfo->gpuVendorID = info->AdapterIdentifier.VendorId;
}
HRESULT CVolumeRaycasting::OnResetDevice(LPDIRECT3DDEVICE9 pD3DDevice)
{
	CObject::OnResetDevice( pD3DDevice );

	m_fxShader = CShaderManager::GetInstance()->GetShader( m_hShader );
	
	if(!m_pVolume || !m_fxShader) return E_FAIL;

	HRESULT hr;
	D3DPRESENT_PARAMETERS pp = DXUTGetDeviceSettings().d3d9.pp;

	SAFE_RELEASE( m_pBack );
	V_RETURN( D3DXCreateTexture(m_pD3DDevice, pp.BackBufferWidth, pp.BackBufferHeight, 1, D3DUSAGE_RENDERTARGET, pp.BackBufferFormat, D3DPOOL_DEFAULT, &m_pBack));

	SAFE_RELEASE( m_pFront );
	V_RETURN( D3DXCreateTexture(m_pD3DDevice, pp.BackBufferWidth, pp.BackBufferHeight, 1, D3DUSAGE_RENDERTARGET, pp.BackBufferFormat, D3DPOOL_DEFAULT, &m_pFront));

	int iWidth = m_pVolume->m_iWidth, iHeight = m_pVolume->m_iHeight, iDepth = m_pVolume->m_iDepth;

	float maxSize = (float)max(iWidth, max(iHeight, iDepth));
	D3DXVECTOR3 stepSize(1.0f  / (iWidth * (maxSize / iWidth)),
						   1.0f / (iHeight * (maxSize / iHeight)),
						   1.0f / (iDepth * (maxSize / iDepth)));


	float mStepScale = 0.5;

	stepSize = stepSize * mStepScale;
	m_fxShader->SetFloatArray("SampleDist", (const FLOAT*)&stepSize, 3);
	m_fxShader->SetFloat("ActualSampleDist", mStepScale);
	m_fxShader->SetInt("Iterations", (int)(maxSize * (1.0f / mStepScale) * 2.0f));

	//calculate the scale factor
	//volumes are not always perfect cubes. so we need to scale our cube
	//by the sizes of the volume. Also, scalar data is not always sampled
	//at equidistant steps. So we also need to scale the cube model by mRatios.
	D3DXVECTOR4 ratios( iWidth / maxSize, iHeight / maxSize, iDepth / maxSize, 1.0f);
	m_fxShader->SetFloatArray("ScaleFactor", (const FLOAT*)&ratios, 4);
	m_fxShader->SetTexture( "Volume", m_pVolume->m_pVolumeTexture );
	m_fxShader->SetTexture( "Transfer", m_pVolume->m_pTransferFunction );


	return D3D_OK;
}
예제 #3
0
//--------------------------------------------------------------------------------------
HRESULT CD3D11Enumeration::EnumerateDevices( _In_ CD3D11EnumAdapterInfo* pAdapterInfo )
{
    HRESULT hr;
    DXUTDeviceSettings deviceSettings = DXUTGetDeviceSettings();
    const D3D_DRIVER_TYPE devTypeArray[] =
    {
        D3D_DRIVER_TYPE_HARDWARE,
        D3D_DRIVER_TYPE_WARP,
        D3D_DRIVER_TYPE_REFERENCE
    };
    const UINT devTypeArrayCount = sizeof( devTypeArray ) / sizeof( devTypeArray[0] );

    // Enumerate each Direct3D device type
    for( UINT iDeviceType = 0; iDeviceType < devTypeArrayCount; iDeviceType++ )
    {
        CD3D11EnumDeviceInfo* pDeviceInfo = new (std::nothrow) CD3D11EnumDeviceInfo;
        if( !pDeviceInfo )
            return E_OUTOFMEMORY;

        // Fill struct w/ AdapterOrdinal and D3D_DRIVER_TYPE
        pDeviceInfo->AdapterOrdinal = pAdapterInfo->AdapterOrdinal;
        pDeviceInfo->DeviceType = devTypeArray[iDeviceType];

        D3D_FEATURE_LEVEL FeatureLevels[] =
        {
            D3D_FEATURE_LEVEL_11_1,
            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 NumFeatureLevels = ARRAYSIZE( FeatureLevels );

        // Call D3D11CreateDevice to ensure that this is a D3D11 device.
        ID3D11Device* pd3dDevice = nullptr;
        ID3D11DeviceContext* pd3dDeviceContext = nullptr;
        IDXGIAdapter* pAdapter = nullptr;
        hr = DXUT_Dynamic_D3D11CreateDevice( pAdapter,
                                             devTypeArray[iDeviceType],
                                             ( HMODULE )0,
                                             0,
                                             FeatureLevels,
                                             NumFeatureLevels,
                                             D3D11_SDK_VERSION,
                                             &pd3dDevice,
                                             &pDeviceInfo->MaxLevel,
                                             &pd3dDeviceContext );

        if ( hr == E_INVALIDARG )
        {
            // DirectX 11.0 runtime will not recognize FL 11.1, so try without it
            hr = DXUT_Dynamic_D3D11CreateDevice( pAdapter,
                                                 devTypeArray[iDeviceType],
                                                 ( HMODULE )0,
                                                 0,
                                                 &FeatureLevels[1],
                                                 NumFeatureLevels - 1,
                                                 D3D11_SDK_VERSION,
                                                 &pd3dDevice,
                                                 &pDeviceInfo->MaxLevel,
                                                 &pd3dDeviceContext );
        }

        if( FAILED( hr ) || pDeviceInfo->MaxLevel < deviceSettings.MinimumFeatureLevel)
        {
            delete pDeviceInfo;
            continue;
        }
        
        if (m_forceFL == 0 || m_forceFL == pDeviceInfo->MaxLevel)
        { 
            pDeviceInfo->SelectedLevel = pDeviceInfo->MaxLevel;
        }
        else if (m_forceFL > pDeviceInfo->MaxLevel)
        {
            delete pDeviceInfo;
            SAFE_RELEASE( pd3dDevice );
            SAFE_RELEASE( pd3dDeviceContext );        
            continue;
        }
        else
        {
            // A device was created with a higher feature level that the user-specified feature level.
            SAFE_RELEASE( pd3dDevice );
            SAFE_RELEASE( pd3dDeviceContext );
            D3D_FEATURE_LEVEL rtFL;
            hr = DXUT_Dynamic_D3D11CreateDevice( pAdapter,
                                                 devTypeArray[iDeviceType],
                                                 ( HMODULE )0,
                                                 0,
                                                 &m_forceFL,
                                                 1,
                                                 D3D11_SDK_VERSION,
                                                 &pd3dDevice,
                                                 &rtFL,
                                                 &pd3dDeviceContext );

            if( SUCCEEDED( hr ) && rtFL == m_forceFL )
            {
                pDeviceInfo->SelectedLevel = m_forceFL;
            }
            else
            {
                delete pDeviceInfo;
                if ( SUCCEEDED(hr) )
                {
                    SAFE_RELEASE( pd3dDevice );
                    SAFE_RELEASE( pd3dDeviceContext );
                }
                continue;
            }
        }

        IDXGIDevice1* pDXGIDev = nullptr;
        hr = pd3dDevice->QueryInterface( __uuidof( IDXGIDevice1 ), ( LPVOID* )&pDXGIDev );
        if( SUCCEEDED( hr ) && pDXGIDev )
        {
            SAFE_RELEASE( pAdapterInfo->m_pAdapter );
            pDXGIDev->GetAdapter( &pAdapterInfo->m_pAdapter );
        }
        SAFE_RELEASE( pDXGIDev );

        D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS ho;
        hr = pd3dDevice->CheckFeatureSupport(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &ho, sizeof(ho));
        if ( FAILED(hr) )
            memset( &ho, 0, sizeof(ho) );

        pDeviceInfo->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x = ho.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x; 
        SAFE_RELEASE( pd3dDeviceContext );             
        SAFE_RELEASE( pd3dDevice );
        pAdapterInfo->deviceInfoList.push_back( pDeviceInfo );
    }

    return S_OK;
}
예제 #4
0
//--------------------------------------------------------------------------------------
// Create any D3D11 resources that aren't dependant on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc,
                                     void* pUserContext )
{
    HRESULT hr; 

    static bool bFirstOnCreateDevice = true;

    // Warn the user that in order to support CS4x, a non-hardware device has been created, continue or quit?
    if ( DXUTGetDeviceSettings().d3d11.DriverType != D3D_DRIVER_TYPE_HARDWARE && bFirstOnCreateDevice )
    {
        if ( MessageBox( 0, L"CS4x capability is missing. "\
                            L"In order to continue, a non-hardware device has been created, "\
                            L"it will be very slow, continue?", L"Warning", MB_ICONEXCLAMATION | MB_YESNO ) != IDYES )
            return E_FAIL;
    }

    bFirstOnCreateDevice = false;

    ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();
    V_RETURN( g_DialogResourceManager.OnD3D11CreateDevice( pd3dDevice, pd3dImmediateContext ) );
    V_RETURN( g_D3DSettingsDlg.OnD3D11CreateDevice( pd3dDevice ) );
    V_RETURN( g_Tessellator.OnD3D11CreateDevice( pd3dDevice ) );
    g_pTxtHelper = new CDXUTTextHelper( pd3dDevice, pd3dImmediateContext, &g_DialogResourceManager, 15 );

    // find the file
    WCHAR str[MAX_PATH];
    V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"BaseMesh.obj" ) );

    std::wifstream ifs( str );
    WCHAR line[256] = {0};
    CGrowableArray<D3DXVECTOR4> initdata;

    // Parse the .obj file. Both triangle faces and quad faces are supported.
    // Only v and f tags are processed, other tags like vn, vt etc are ignored.
    {
        CGrowableArray<D3DXVECTOR4> v;

        while ( ifs >> line )
        {
            if ( 0 == wcscmp( line, L"#" ) ) 
                ifs.getline( line, 255 );
            else
            if ( 0 == wcscmp( line, L"v" ) )
            {
                D3DXVECTOR4 pos;
                ifs >> pos.x >> pos.y >> pos.z;
                pos.w = 1;
                v.Add( pos );
            }
        }

        ifs.clear( 0 );
        ifs.seekg( 0 );
        while ( ifs >> line )
        {
            if ( 0 == wcscmp( line, L"#" ) ) 
                ifs.getline( line, 255 );
            else
            if ( 0 == wcscmp( line, L"f" ) )
            {
                ifs.getline( line, 255 );
                std::wstringstream ss(line);
                int idx[4], i = 0;
                while ( ss >> line )
                {
                    std::wstringstream ss(line);
                    ss >> idx[i++];
                }
                
                initdata.Add( v[idx[0]-1] ); initdata.Add( v[idx[1]-1] ); initdata.Add( v[idx[2]-1] );
                if ( i >= 4 ) // quad face?
                {
                    initdata.Add( v[idx[2]-1] ); initdata.Add( v[idx[3]-1] ); initdata.Add( v[idx[0]-1] );
                }
            }
        }        
예제 #5
0
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
{
    // Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

	Initialize();

    // Set DXUT callbacks
    DXUTSetCallbackDeviceChanging( ModifyDeviceSettings );
    DXUTSetCallbackMsgProc( MsgProc );
    DXUTSetCallbackKeyboard( OnKeyboard );
	DXUTSetCallbackMouse( OnMouse, true );
	DXUTSetCallbackD3D11DeviceAcceptable( IsD3D11DeviceAcceptable );
    DXUTSetCallbackD3D11DeviceCreated( OnD3D11CreateDevice );
    DXUTSetCallbackD3D11SwapChainResized( OnD3D11ResizedSwapChain );
    DXUTSetCallbackD3D11FrameRender( OnD3D11FrameRender );
    DXUTSetCallbackD3D11SwapChainReleasing( OnD3D11ReleasingSwapChain );
    DXUTSetCallbackD3D11DeviceDestroyed( OnD3D11DestroyDevice );

    InitApp();

	if (gMultithreaded)
	{
		InitWin32Threads();
	}

    DXUTInit( true, true, NULL );
    DXUTSetCursorSettings( true, true );
    DXUTCreateWindow( L"ISPC HDR Texture Compressor" );

	// Try to create a device with DX11 feature set
    DXUTCreateDevice (D3D_FEATURE_LEVEL_11_0, true, 1280, 1024 );

	BOOL DX11Available = false;

	// If we don't have an adequate driver, then we revert to DX10 feature set...
	DXUTDeviceSettings settings = DXUTGetDeviceSettings();
	if(settings.d3d11.DriverType == D3D_DRIVER_TYPE_UNKNOWN || settings.d3d11.DriverType == D3D_DRIVER_TYPE_NULL) {
		DXUTCreateDevice(D3D_FEATURE_LEVEL_10_1, true, 1280, 1024);

		// !HACK! Force enumeration here in order to relocate hardware with new feature level
		DXUTGetD3D11Enumeration(true);
		DXUTCreateDevice(D3D_FEATURE_LEVEL_10_1, true, 1280, 1024);

		const TCHAR *noDx11msg = _T("Your hardware does not seem to support DX11. BC7 Compression is disabled.");
		MessageBox(NULL, noDx11msg, _T("Error"), MB_OK);
	}
	else
	{
		DX11Available = true;
	}
	
	FillProfiles(DX11Available);

    DXUTMainLoop();

	// Destroy all of the threads...
	DestroyThreads();

    return DXUTGetExitCode();
}
예제 #6
0
void MagnifyTool::CreateDepthStencil( ID3D10Device* pd3dDevice, IDXGISwapChain *pSwapChain, 
		const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
    DXGI_FORMAT DepthFormat;
    HRESULT hr;

    SAFE_RELEASE( m_pDepthStencil );
    SAFE_RELEASE( m_pDSV );
    SAFE_RELEASE( m_pRState );

    switch( DXUTGetDeviceSettings().d3d10.AutoDepthStencilFormat )
    {
        case DXGI_FORMAT_D32_FLOAT:
            DepthFormat = DXGI_FORMAT_R32_TYPELESS;
            break;

        case DXGI_FORMAT_D24_UNORM_S8_UINT:
            DepthFormat = DXGI_FORMAT_R24G8_TYPELESS;
            break;

        case DXGI_FORMAT_D16_UNORM:
            DepthFormat = DXGI_FORMAT_R16_TYPELESS;
            break;

        default:
            DepthFormat = DXGI_FORMAT_UNKNOWN;
            break;
    }
    assert( DepthFormat != DXGI_FORMAT_UNKNOWN );

    // Create depth stencil texture
    D3D10_TEXTURE2D_DESC descDepth;
    descDepth.Width = pBackBufferSurfaceDesc->Width;
    descDepth.Height = pBackBufferSurfaceDesc->Height;
    descDepth.MipLevels = 1;
    descDepth.ArraySize = 1;
    descDepth.Format = DepthFormat;
    descDepth.SampleDesc.Count = DXUTGetDeviceSettings().d3d10.sd.SampleDesc.Count;
    descDepth.SampleDesc.Quality = DXUTGetDeviceSettings().d3d10.sd.SampleDesc.Quality;
    descDepth.Usage = D3D10_USAGE_DEFAULT;
    descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL;

    if( ( descDepth.SampleDesc.Count == 1 ) || DXUTGetD3D10Device1() )
    {
        descDepth.BindFlags |= D3D10_BIND_SHADER_RESOURCE;
    }

    descDepth.CPUAccessFlags = 0;
    descDepth.MiscFlags = 0;
    hr = pd3dDevice->CreateTexture2D( &descDepth, NULL, &m_pDepthStencil );
    assert( D3D_OK == hr );
       
    // Create the depth stencil view
    D3D10_DEPTH_STENCIL_VIEW_DESC descDSV;
    descDSV.Format = DXUTGetDeviceSettings().d3d10.AutoDepthStencilFormat;
    if( descDepth.SampleDesc.Count > 1 )
    {
        descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2DMS;
    }
    else
    {
        descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
    }
    descDSV.Texture2D.MipSlice = 0;

    hr = pd3dDevice->CreateDepthStencilView( m_pDepthStencil, &descDSV, &m_pDSV );
    assert( D3D_OK == hr );
      
    // Create a default rasterizer state that enables MSAA
    D3D10_RASTERIZER_DESC RSDesc;
    RSDesc.FillMode = D3D10_FILL_SOLID;
    RSDesc.CullMode = D3D10_CULL_BACK;
    RSDesc.FrontCounterClockwise = FALSE;
    RSDesc.DepthBias = 0;
    RSDesc.SlopeScaledDepthBias = 0.0f;
    RSDesc.DepthBias = 0;
    RSDesc.DepthClipEnable = TRUE;
    RSDesc.ScissorEnable = FALSE;
    RSDesc.AntialiasedLineEnable = FALSE;
    if( descDepth.SampleDesc.Count > 1 )
    {
        RSDesc.MultisampleEnable = TRUE;
    }
    else
    {
        RSDesc.MultisampleEnable = FALSE;
    }

    hr = pd3dDevice->CreateRasterizerState( &RSDesc, &m_pRState );
    assert( D3D_OK == hr );

    pd3dDevice->RSSetState( m_pRState );

    // Get the current render and depth targets, so we can later revert to these.
    ID3D10RenderTargetView *pRenderTargetView;
    DXUTGetD3D10Device()->OMGetRenderTargets( 1, &pRenderTargetView, NULL );

    // Bind our render target view to the OM stage.
    DXUTGetD3D10Device()->OMSetRenderTargets( 1, (ID3D10RenderTargetView* const*)&pRenderTargetView, m_pDSV );

    // Decrement the counter on these resources
    SAFE_RELEASE( pRenderTargetView );
}