RayTracing.
[GPU.git] / WCudaMSE / Student_Cuda_Image / src / cpp / core / mainFreeGL.cpp
1 #include <iostream>
2 #include <stdlib.h>
3 #include <string.h>
4 using namespace std;
5
6 #include "Device.h"
7 #include "cudaTools.h"
8 #include "Chronos.h"
9
10 #include "RayTracingProvider.h"
11 #include "RayTracingParams.h"
12
13 /*----------------------------------------------------------------------*\
14 |* Declaration *|
15 \*---------------------------------------------------------------------*/
16
17 /*--------------------------------------*\
18 |* Imported *|
19 \*-------------------------------------*/
20
21 extern int rippling0FreeGL(int itmax); // bas technique
22
23 /*--------------------------------------*\
24 |* Public *|
25 \*-------------------------------------*/
26
27 int mainFreeGL(void);
28
29 /*--------------------------------------*\
30 |* Private *|
31 \*-------------------------------------*/
32
33 /*----------------------------------------------------------------------*\
34 |* Implementation *|
35 \*---------------------------------------------------------------------*/
36
37 void run(uchar4* ptrDevPixels, int dw, int dh, int dg, int db, int nbFrame)
38 {
39 cout << "Raytracing Without GL ";
40 #if CURRENT_MEMORY_MODEL == MEMORY_MODEL_GLOBAL
41 cout << "(Global memory)" << endl;
42 #elif CURRENT_MEMORY_MODEL == MEMORY_MODEL_CONSTANT
43 cout << "(Constant memory)" << endl;
44 #elif CURRENT_MEMORY_MODEL == MEMORY_MODEL_SHARED
45 cout << "(Shared memory)" << endl;
46 #endif
47
48 cout << "Nb frames: " << nbFrame << endl;
49
50 RayTracing* rayTracing = RayTracingProvider::create(dw, dh, dg, db);
51
52 Chronos chronos;
53 chronos.start();
54
55 for (int i = 0; i < nbFrame; i++)
56 rayTracing->runGPU(ptrDevPixels);
57
58 HANDLE_ERROR(cudaDeviceSynchronize());
59
60 chronos.stop();
61
62 cout << "Time: " << chronos << endl;
63 cout << "-------------------" << endl;
64 }
65
66 /*--------------------------------------*\
67 |* Public *|
68 \*-------------------------------------*/
69
70 int mainFreeGL(void)
71 {
72 const int NB_FRAME_TO_RENDER = 100;
73 const int dw = 16 * 50;
74 const int dh = 16 * 50;
75
76 // dg : 8 -> 128.
77 const int dgStart = 8;
78 const int dgStop = 128;
79
80 // db : 8 -> 32
81 const int dbStart = 8;
82 const int dbStop = 32;
83
84 uchar4* ptrDevPixels;
85 HANDLE_ERROR(cudaMalloc(&ptrDevPixels, dw * dh * sizeof(uchar4)));
86
87 run(ptrDevPixels, dw, dh, 32, 32, NB_FRAME_TO_RENDER);
88 return EXIT_SUCCESS;
89
90 for (int dg = dgStart; dg <= dgStop; dg *= 2)
91 for (int db = dbStart; db <= dbStop; db *= 2)
92 run(ptrDevPixels, dw, dh, dg, db, NB_FRAME_TO_RENDER);
93
94 return EXIT_SUCCESS;
95 }
96
97 /*--------------------------------------*\
98 |* Private *|
99 \*-------------------------------------*/
100
101 /*----------------------------------------------------------------------*\
102 |* End *|
103 \*---------------------------------------------------------------------*/
104