Browse Source

added flag for showing debugs for the tick function

IverMartinson 8 months ago
parent
commit
cb62863273

BIN
builds/final binaries/librasteriver.so


BIN
builds/final binaries/main.bin


+ 4 - 3
src/RasterIver/headers/rasteriver.h

@@ -56,9 +56,10 @@ typedef enum {
     RI_FLAG_CLEAN_POLYGONS      = 5,
     RI_FLAG_CLEAN_POLYGONS      = 5,
     RI_FLAG_POPULATE_POLYGONS   = 6,
     RI_FLAG_POPULATE_POLYGONS   = 6,
     RI_FLAG_BE_MASTER_RENDERER  = 7,
     RI_FLAG_BE_MASTER_RENDERER  = 7,
-    RI_FLAG_DEBUG_FRAME  = 8,
-    RI_FLAG_SHOW_FRAME  = 9,
-    RI_FLAG_SHOW_INFO  = 10,
+    RI_FLAG_DEBUG_FRAME         = 8,
+    RI_FLAG_SHOW_FRAME          = 9,
+    RI_FLAG_SHOW_INFO           = 10,
+    RI_FLAG_DEBUG_TICK          = 11,
 } RI_flag_enum;
 } RI_flag_enum;
 
 
 RI_result   RI_Init();
 RI_result   RI_Init();

+ 43 - 18
src/RasterIver/source code/rasteriver.c

@@ -39,6 +39,7 @@ int be_master_renderer = 0;
 int debug_frame = 0;
 int debug_frame = 0;
 int show_frame = 0;
 int show_frame = 0;
 int show_info = 0;
 int show_info = 0;
+int debug_tick = 0;
 
 
 Uint64 start_time;
 Uint64 start_time;
 double frame_time_ms;
 double frame_time_ms;
@@ -71,7 +72,6 @@ cl_device_id device;
 RI_uint number_of_platforms, number_of_devices;
 RI_uint number_of_platforms, number_of_devices;
 
 
 cl_int error;
 cl_int error;
-
 cl_context context;
 cl_context context;
 cl_command_queue queue;
 cl_command_queue queue;
 
 
@@ -118,6 +118,27 @@ RI_result debug(int verbose, char *string, ...)
     return RI_SUCCESS;
     return RI_SUCCESS;
 }
 }
 
 
+RI_result debug_tick_func(int verbose, char *string, ...)
+{
+    if (!show_debug || (verbose && !debug_verbose) || !debug_tick){
+        return RI_ERROR;
+    }
+
+    va_list args;
+    va_start(args, string);
+
+    char prefix[100] = "[RasterIver] ";
+
+    strcat(prefix, string);
+
+    vprintf(prefix, args);
+    printf("\n");
+
+    va_end(args);
+
+    return RI_SUCCESS;
+}
+
 RI_result erchk_func(cl_int error, int line, char *file)
 RI_result erchk_func(cl_int error, int line, char *file)
 {
 {
     if (error != CL_SUCCESS)
     if (error != CL_SUCCESS)
@@ -209,6 +230,10 @@ RI_result RI_SetFlag(RI_flag RI_FlagToSet, int RI_Value)
         show_info = RI_Value;
         show_info = RI_Value;
         break;
         break;
 
 
+    case RI_FLAG_DEBUG_TICK:
+        debug_tick = RI_Value;
+        break;
+
     default:
     default:
         return RI_INVALID_FLAG;
         return RI_INVALID_FLAG;
     }
     }
@@ -608,13 +633,13 @@ RI_result RI_Tick(){
         start_time = SDL_GetPerformanceCounter();
         start_time = SDL_GetPerformanceCounter();
     }
     }
     
     
-    debug(1, "Ticking...");
+    debug_tick_func(1, "Ticking...");
     
     
     if (running)
     if (running)
     {
     {
         if (frame_buffer == NULL)
         if (frame_buffer == NULL)
         {
         {
-            debug(0, "Frame Buffer is not Allocated");
+            debug_tick_func(0, "Frame Buffer is not Allocated");
             return RI_ERROR;
             return RI_ERROR;
         }
         }
 
 
@@ -635,41 +660,41 @@ RI_result RI_Tick(){
                 erchk(clEnqueueWriteBuffer(queue, object_memory_buffer, CL_TRUE, 0, sizeof(int) * object_size * object_count, objects, 0, NULL, NULL));
                 erchk(clEnqueueWriteBuffer(queue, object_memory_buffer, CL_TRUE, 0, sizeof(int) * object_size * object_count, objects, 0, NULL, NULL));
                 erchk(clFinish(queue));
                 erchk(clFinish(queue));
 
 
-                debug(1, "Wrote Objects Buffer");
+                debug_tick_func(1, "Wrote Objects Buffer");
             }
             }
 
 
             if (num_verticies > 0){
             if (num_verticies > 0){
                 erchk(clEnqueueWriteBuffer(queue, verticies_memory_buffer, CL_TRUE, 0, sizeof(float) * 3 * num_verticies, verticies, 0, NULL, NULL));
                 erchk(clEnqueueWriteBuffer(queue, verticies_memory_buffer, CL_TRUE, 0, sizeof(float) * 3 * num_verticies, verticies, 0, NULL, NULL));
                 erchk(clFinish(queue));
                 erchk(clFinish(queue));
 
 
-                debug(1, "Wrote Verticies Buffer");
+                debug_tick_func(1, "Wrote Verticies Buffer");
             }
             }
 
 
             if (num_normals > 0){
             if (num_normals > 0){
                 erchk(clEnqueueWriteBuffer(queue, normals_memory_buffer, CL_TRUE, 0, sizeof(float) * 3 * num_normals, normals, 0, NULL, NULL));
                 erchk(clEnqueueWriteBuffer(queue, normals_memory_buffer, CL_TRUE, 0, sizeof(float) * 3 * num_normals, normals, 0, NULL, NULL));
                 erchk(clFinish(queue));
                 erchk(clFinish(queue));
 
 
-                debug(1, "Wrote Normals Buffer");
+                debug_tick_func(1, "Wrote Normals Buffer");
             }
             }
 
 
             if (num_uvs > 0){
             if (num_uvs > 0){
                 erchk(clEnqueueWriteBuffer(queue, uvs_memory_buffer, CL_TRUE, 0, sizeof(float) * 3 * num_uvs, uvs, 0, NULL, NULL));
                 erchk(clEnqueueWriteBuffer(queue, uvs_memory_buffer, CL_TRUE, 0, sizeof(float) * 3 * num_uvs, uvs, 0, NULL, NULL));
                 erchk(clFinish(queue));
                 erchk(clFinish(queue));
 
 
-                debug(1, "Wrote UVS Buffer");
+                debug_tick_func(1, "Wrote UVS Buffer");
             }
             }
 
 
             if (num_faces > 0){
             if (num_faces > 0){
                 erchk(clEnqueueWriteBuffer(queue, triangles_memory_buffer, CL_TRUE, 0, sizeof(int) * 9 * num_faces, triangles, 0, NULL, NULL));
                 erchk(clEnqueueWriteBuffer(queue, triangles_memory_buffer, CL_TRUE, 0, sizeof(int) * 9 * num_faces, triangles, 0, NULL, NULL));
                 erchk(clFinish(queue));
                 erchk(clFinish(queue));
 
 
-                debug(1, "Wrote Triangles Buffer");
+                debug_tick_func(1, "Wrote Triangles Buffer");
             }
             }
 
 
             erchk(clEnqueueFillBuffer(queue, output_memory_buffer, &pattern, sizeof(RI_uint), 0, sizeof(RI_uint) * width * height, 0, NULL, NULL));
             erchk(clEnqueueFillBuffer(queue, output_memory_buffer, &pattern, sizeof(RI_uint), 0, sizeof(RI_uint) * width * height, 0, NULL, NULL));
             erchk(clFinish(queue));
             erchk(clFinish(queue));
 
 
-            debug(1, "Cleared Frame Buffer");
+            debug_tick_func(1, "Cleared Frame Buffer");
 
 
             size_t local_size_2d[2] = {sqrt(local_size), sqrt(local_size)};
             size_t local_size_2d[2] = {sqrt(local_size), sqrt(local_size)};
 
 
@@ -680,12 +705,12 @@ RI_result RI_Tick(){
 
 
             erchk(clEnqueueReadBuffer(queue, output_memory_buffer, CL_TRUE, 0, sizeof(RI_uint) * width * height, frame_buffer, 0, NULL, NULL));
             erchk(clEnqueueReadBuffer(queue, output_memory_buffer, CL_TRUE, 0, sizeof(RI_uint) * width * height, frame_buffer, 0, NULL, NULL));
             erchk(clFinish(queue));
             erchk(clFinish(queue));
-            debug(1, "Read Frame Buffer");
+            debug_tick_func(1, "Read Frame Buffer");
         }
         }
         else{
         else{
             if (polygons == NULL)
             if (polygons == NULL)
             {
             {
-                debug(0, "Polygons is not Allocated");
+                debug_tick_func(0, "Polygons is not Allocated");
                 return RI_ERROR;
                 return RI_ERROR;
             }
             }
             
             
@@ -696,7 +721,7 @@ RI_result RI_Tick(){
                     }
                     }
                 }
                 }
                 
                 
-                debug(1, "Highest Z: %f", highest_z);
+                debug_tick_func(1, "Highest Z: %f", highest_z);
             }
             }
 
 
             erchk(clSetKernelArg(compiled_kernel_non_master, 0, sizeof(cl_mem), &input_memory_buffer));
             erchk(clSetKernelArg(compiled_kernel_non_master, 0, sizeof(cl_mem), &input_memory_buffer));
@@ -710,12 +735,12 @@ RI_result RI_Tick(){
             erchk(clEnqueueWriteBuffer(queue, input_memory_buffer, CL_TRUE, 0, sizeof(float) * 3 * 3 * polygon_count, polygons, 0, NULL, NULL));
             erchk(clEnqueueWriteBuffer(queue, input_memory_buffer, CL_TRUE, 0, sizeof(float) * 3 * 3 * polygon_count, polygons, 0, NULL, NULL));
             erchk(clFinish(queue));
             erchk(clFinish(queue));
 
 
-            debug(1, "Wrote Polygon Buffer");
+            debug_tick_func(1, "Wrote Polygon Buffer");
 
 
             erchk(clEnqueueFillBuffer(queue, output_memory_buffer, &pattern, sizeof(RI_uint), 0, sizeof(RI_uint) * width * height, 0, NULL, NULL));
             erchk(clEnqueueFillBuffer(queue, output_memory_buffer, &pattern, sizeof(RI_uint), 0, sizeof(RI_uint) * width * height, 0, NULL, NULL));
             erchk(clFinish(queue));
             erchk(clFinish(queue));
 
 
-            debug(1, "Cleared Frame Buffer");
+            debug_tick_func(1, "Cleared Frame Buffer");
 
 
             size_t local_size_2d[2] = {sqrt(local_size), sqrt(local_size)};
             size_t local_size_2d[2] = {sqrt(local_size), sqrt(local_size)};
 
 
@@ -727,7 +752,7 @@ RI_result RI_Tick(){
 
 
             erchk(clEnqueueReadBuffer(queue, output_memory_buffer, CL_TRUE, 0, sizeof(RI_uint) * width * height, frame_buffer, 0, NULL, NULL));
             erchk(clEnqueueReadBuffer(queue, output_memory_buffer, CL_TRUE, 0, sizeof(RI_uint) * width * height, frame_buffer, 0, NULL, NULL));
             erchk(clFinish(queue));
             erchk(clFinish(queue));
-            debug(1, "Read Frame Buffer");
+            debug_tick_func(1, "Read Frame Buffer");
         }
         }
 
 
         SDL_Event event;
         SDL_Event event;
@@ -766,7 +791,7 @@ RI_result RI_Tick(){
         }
         }
 
 
         if (debug_frame){
         if (debug_frame){
-            debug(0, "Frame: %d", frame);
+            debug_tick_func(0, "Frame: %d", frame);
         }
         }
         
         
         if (show_frame){
         if (show_frame){
@@ -825,10 +850,10 @@ RI_result RI_Tick(){
         }
         }
         
         
         if (debug_fps){
         if (debug_fps){
-            debug(0, "FPS: %lf (%d polygons, %d pixels)", fps, polygon_count, width * height);
+            debug_tick_func(0, "FPS: %lf (%d polygons, %d pixels)", fps, polygon_count, width * height);
         }
         }
 
 
-        debug(1, "Ticked");
+        debug_tick_func(1, "Ticked");
         
         
         return RI_SUCCESS;
         return RI_SUCCESS;
     }
     }

+ 2 - 1
src/launch program/main.c

@@ -10,7 +10,8 @@ int main(){
     srand(time(NULL));                                                         
     srand(time(NULL));                                                         
 
 
     RI_SetFlag(RI_FLAG_DEBUG, 1);
     RI_SetFlag(RI_FLAG_DEBUG, 1);
-    RI_SetFlag(RI_FLAG_DEBUG_VERBOSE, 0);
+    RI_SetFlag(RI_FLAG_DEBUG_VERBOSE, 1);
+    RI_SetFlag(RI_FLAG_DEBUG_TICK, 0);
     RI_SetFlag(RI_FLAG_DEBUG_FPS, 0);
     RI_SetFlag(RI_FLAG_DEBUG_FPS, 0);
     RI_SetFlag(RI_FLAG_SHOW_FPS, 1);
     RI_SetFlag(RI_FLAG_SHOW_FPS, 1);
     RI_SetFlag(RI_FLAG_SHOW_FRAME, 1);
     RI_SetFlag(RI_FLAG_SHOW_FRAME, 1);