//-------------------------------------------------------------------------------------- // Entry point to the program //-------------------------------------------------------------------------------------- int __cdecl wmain() { // Enable run-time memory check for debug builds. #if defined(DEBUG) | defined(_DEBUG) _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); #endif // Generate a random list of numbers to sort // Not intended for production code srand( GetTickCount() ); std::generate( data.begin(), data.end(), SampleRand ); // Create the device HRESULT hr = InitDevice(); if ( FAILED (hr) ) { if ( hr == DXUTERR_NODIRECT3D11 ) { OSVERSIONINFOEX osv; memset( &osv, 0, sizeof(osv) ); osv.dwOSVersionInfoSize = sizeof(osv); GetVersionEx( (LPOSVERSIONINFO)&osv ); if ( ( osv.dwMajorVersion > 6 ) || ( osv.dwMajorVersion == 6 && osv.dwMinorVersion >= 1 ) || ( osv.dwMajorVersion == 6 && osv.dwMinorVersion == 0 && osv.dwBuildNumber > 6002 ) ) { MessageBox( 0, L"Direct3D 11 components were not found.", L"Error", MB_ICONEXCLAMATION ); // This should not happen, but is here for completeness as the system could be // corrupted or some future OS version could pull D3D11.DLL for some reason } else if ( osv.dwMajorVersion == 6 && osv.dwMinorVersion == 0 && osv.dwBuildNumber == 6002 ) { MessageBox( 0, L"Direct3D 11 components were not found, but are available for"\ L" this version of Windows.\n"\ L"For details see Microsoft Knowledge Base Article #971644\n"\ L"http://support.microsoft.com/default.aspx/kb/971644/", L"Error", MB_ICONEXCLAMATION ); } else if ( osv.dwMajorVersion == 6 && osv.dwMinorVersion == 0 ) { MessageBox( 0, L"Direct3D 11 components were not found. Please install the latest Service Pack.\n"\ L"For details see Microsoft Knowledge Base Article #935791\n"\ L" http://support.microsoft.com/default.aspx/kb/935791", L"Error", MB_ICONEXCLAMATION ); } else { MessageBox( 0, L"Direct3D 11 is not supported on this OS.", L"Error", MB_ICONEXCLAMATION ); } } printf( "Failed to create the device. Exiting.\n" ); return 1; } // Create the buffers and shaders if( FAILED( CreateResources() ) ) { printf( "Failed to create resources. Exiting.\n" ); return 1; } printf( "Sorting %u Elements\n", NUM_ELEMENTS ); // GPU Bitonic Sort printf( "Starting GPU Bitonic Sort...\n" ); GPUSort(); printf( "...GPU Bitonic Sort Finished\n" ); // Sort the data on the CPU to compare for correctness printf( "Starting CPU Sort...\n" ); CPUSort(); printf( "...CPU Sort Finished\n" ); // Compare the results for correctness bool bComparisonSucceeded = true; for( UINT i = 0 ; i < NUM_ELEMENTS ; ++i ) { if( data[i] != results[i] ) { bComparisonSucceeded = false; break; } } printf( "Comparison %s\n", (bComparisonSucceeded)? "Succeeded" : "FAILED" ); // Cleanup the resources SAFE_RELEASE( g_pReadBackBuffer ); SAFE_RELEASE( g_pBuffer2UAV ); SAFE_RELEASE( g_pBuffer1UAV ); SAFE_RELEASE( g_pBuffer2SRV ); SAFE_RELEASE( g_pBuffer1SRV ); SAFE_RELEASE( g_pBuffer2 ); SAFE_RELEASE( g_pBuffer1 ); SAFE_RELEASE( g_pCB ); SAFE_RELEASE( g_pComputeShaderTranspose ); SAFE_RELEASE( g_pComputeShaderBitonic ); SAFE_RELEASE( g_pd3dImmediateContext ); SAFE_RELEASE( g_pd3dDevice ); return 0; }
//-------------------------------------------------------------------------------------- // Entry point to the program //-------------------------------------------------------------------------------------- int __cdecl wmain() { // Enable run-time memory check for debug builds. #if defined(DEBUG) | defined(_DEBUG) _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); #endif // Generate a random list of numbers to sort // Not intended for production code srand(GetTickCount()); std::generate(data.begin(), data.end(), SampleRand); // Create the device HRESULT hr = InitDevice(); if (FAILED(hr)) { if (hr == DXUTERR_NODIRECT3D) { MessageBox(0, L"Direct3D 11 components were not found.\n" L"For details see Microsoft Knowledge Base\n" L"https://support.microsoft.com/", L"Error", MB_ICONEXCLAMATION); } printf("Failed to create the device. Exiting.\n"); return 1; } // Create the buffers and shaders if (FAILED(CreateResources())) { printf("Failed to create resources. Exiting.\n"); return 1; } printf("Sorting %u Elements\n", NUM_ELEMENTS); // GPU Bitonic Sort printf("Starting GPU Bitonic Sort...\n"); GPUSort(); printf("...GPU Bitonic Sort Finished\n"); // Sort the data on the CPU to compare for correctness printf("Starting CPU Sort...\n"); CPUSort(); printf("...CPU Sort Finished\n"); // Compare the results for correctness bool bComparisonSucceeded = true; for (UINT i = 0; i < NUM_ELEMENTS; ++i) { if (data[i] != results[i]) { bComparisonSucceeded = false; break; } } printf("Comparison %s\n", (bComparisonSucceeded) ? "Succeeded" : "FAILED"); // Cleanup the resources SAFE_RELEASE(g_pReadBackBuffer); SAFE_RELEASE(g_pBuffer2UAV); SAFE_RELEASE(g_pBuffer1UAV); SAFE_RELEASE(g_pBuffer2SRV); SAFE_RELEASE(g_pBuffer1SRV); SAFE_RELEASE(g_pBuffer2); SAFE_RELEASE(g_pBuffer1); SAFE_RELEASE(g_pCB); SAFE_RELEASE(g_pComputeShaderTranspose); SAFE_RELEASE(g_pComputeShaderBitonic); SAFE_RELEASE(g_pd3dImmediateContext); SAFE_RELEASE(g_pd3dDevice); return 0; }