MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / runGraphicsTest

Function runGraphicsTest

cpp/4_CUDA_Libraries/oceanFFT/oceanFFT.cpp:257–328  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////////// Run test ///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

255//! Run test
256////////////////////////////////////////////////////////////////////////////////
257void 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);

Callers 1

mainFunction · 0.70

Calls 11

checkCmdLineFlagFunction · 0.85
findCudaDeviceFunction · 0.85
generate_h0Function · 0.85
sdkCreateTimerFunction · 0.85
sdkStartTimerFunction · 0.85
sdkGetTimerValueFunction · 0.85
createMeshPositionVBOFunction · 0.85
createMeshIndexBufferFunction · 0.85
runCudaFunction · 0.85
initGLFunction · 0.70
createVBOFunction · 0.70

Tested by

no test coverage detected