/////////////////////////////////////////////////////////////////////////// Run test ///////////////////////////////////////////////////////////////////////////
| 255 | //! Run test |
| 256 | //////////////////////////////////////////////////////////////////////////////// |
| 257 | void runGraphicsTest(int argc, char **argv) |
| 258 | { |
| 259 | #if defined(__linux__) |
| 260 | setenv("DISPLAY", ":0", 0); |
| 261 | #endif |
| 262 | |
| 263 | printf("[%s] ", sSDKsample); |
| 264 | printf("\n"); |
| 265 | |
| 266 | if (checkCmdLineFlag(argc, (const char **)argv, "device")) { |
| 267 | printf("[%s]\n", argv[0]); |
| 268 | printf(" Does not explicitly support -device=n in OpenGL mode\n"); |
| 269 | printf(" To use -device=n, the sample must be running w/o OpenGL\n\n"); |
| 270 | printf(" > %s -device=n -qatest\n", argv[0]); |
| 271 | printf("exiting...\n"); |
| 272 | |
| 273 | exit(EXIT_SUCCESS); |
| 274 | } |
| 275 | |
| 276 | // First initialize OpenGL context, so we can properly set the GL for CUDA. |
| 277 | // This is necessary in order to achieve optimal performance with OpenGL/CUDA |
| 278 | // interop. |
| 279 | if (false == initGL(&argc, argv)) { |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | findCudaDevice(argc, (const char **)argv); |
| 284 | |
| 285 | // create FFT plan |
| 286 | checkCudaErrors(cufftPlan2d(&fftPlan, meshSize, meshSize, CUFFT_C2C)); |
| 287 | |
| 288 | // allocate memory |
| 289 | int spectrumSize = spectrumW * spectrumH * sizeof(float2); |
| 290 | checkCudaErrors(cudaMalloc((void **)&d_h0, spectrumSize)); |
| 291 | h_h0 = (float2 *)malloc(spectrumSize); |
| 292 | generate_h0(h_h0); |
| 293 | checkCudaErrors(cudaMemcpy(d_h0, h_h0, spectrumSize, cudaMemcpyHostToDevice)); |
| 294 | |
| 295 | int outputSize = meshSize * meshSize * sizeof(float2); |
| 296 | checkCudaErrors(cudaMalloc((void **)&d_ht, outputSize)); |
| 297 | checkCudaErrors(cudaMalloc((void **)&d_slope, outputSize)); |
| 298 | |
| 299 | sdkCreateTimer(&timer); |
| 300 | sdkStartTimer(&timer); |
| 301 | prevTime = sdkGetTimerValue(&timer); |
| 302 | |
| 303 | // create vertex buffers and register with CUDA |
| 304 | createVBO(&heightVertexBuffer, meshSize * meshSize * sizeof(float)); |
| 305 | checkCudaErrors( |
| 306 | cudaGraphicsGLRegisterBuffer(&cuda_heightVB_resource, heightVertexBuffer, cudaGraphicsMapFlagsWriteDiscard)); |
| 307 | |
| 308 | createVBO(&slopeVertexBuffer, outputSize); |
| 309 | checkCudaErrors( |
| 310 | cudaGraphicsGLRegisterBuffer(&cuda_slopeVB_resource, slopeVertexBuffer, cudaGraphicsMapFlagsWriteDiscard)); |
| 311 | |
| 312 | // create vertex and index buffer for mesh |
| 313 | createMeshPositionVBO(&posVertexBuffer, meshSize, meshSize); |
| 314 | createMeshIndexBuffer(&indexBuffer, meshSize, meshSize); |
no test coverage detected