Skip to content

Commit

Permalink
v1.1.1 | 2024/01/07 22:42 | Super Screenshots were added, but probabl…
Browse files Browse the repository at this point in the history
…y not implemented in the greatest way. I will need to rebuild how Render Tasks are handled and sent. Also decreased the defaults for the Super Screenshot. Given how long my machine took to render 3840x2160 16s 65536i, it is probably best to lower the defaults to 1920x1080 9s 16384i so the average user can render the default Super Screenshot just fine.
  • Loading branch information
ZERICO2005 committed Jan 8, 2024
1 parent ee7de14 commit 8fa0b26
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 38 deletions.
6 changes: 3 additions & 3 deletions src/Program_Def.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** Author: zerico2005 (2023)
** Author: zerico2005 (2023-2024)
** Project: ABS-Fractal-Explorer
** License: MIT License
** A copy of the MIT License should be included with
Expand All @@ -20,10 +20,10 @@
//#define MONOCHROME_MODE

#define PROGRAM_NAME "ABS-Fractal-Explorer"
#define PROGRAM_DATE "2023/12/28" /* YYYY/MM/DD */
#define PROGRAM_DATE "2024/01/07" /* YYYY/MM/DD */
#define PROGRAM_V_MAJOR 1
#define PROGRAM_V_MINOR 1
#define PROGRAM_V_PATCH 0
#define PROGRAM_V_PATCH 1
#define PROGRAM_V_TAG "Alpha"
#define PROGRAM_VERSION STR_N(PROGRAM_V_MAJOR) "." STR_N(PROGRAM_V_MINOR) "." STR_N(PROGRAM_V_PATCH) " " PROGRAM_V_TAG

Expand Down
115 changes: 112 additions & 3 deletions src/engine.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** Author: zerico2005 (2023)
** Author: zerico2005 (2023-2024)
** Project: ABS-Fractal-Explorer
** License: MIT License
** A copy of the MIT License should be included with
Expand All @@ -14,6 +14,8 @@
#include "programData.h"
#include "imageBuffer.h"

#include "fileManager.h"

#include "fracMulti.h"
#include "fracCL.h"

Expand Down Expand Up @@ -41,6 +43,108 @@ int setup_fracExp(int argc, char* argv[]) {
return 0;
}

int super_render_code(std::atomic<bool>& ABORT_RENDERING) {
static uint32_t image_file_format = Image_File_Format::PNG;
static uint8_t image_quality = 8;
static Render_Data image_render_data = {0};
static Fractal_Data image_fractal_data = {0};
static BufferBox image_box = {0};
if (receive_Image_Render(&image_fractal_data,&image_render_data,&image_file_format,&image_quality)) {
memset(&image_box,0,sizeof(BufferBox));
image_box.resX = image_render_data.resX;
image_box.resY = image_render_data.resY;
image_box.channels = image_render_data.channels;
image_box.padding = image_render_data.padding;
image_box.vram = nullptr;
size_t image_box_size = getBufferBoxSize(&image_box);
if (image_box_size < 16) {
printError("Super Screenshot has invalid resolution parameters");
return -1;
} else if (image_box_size > (size_t)INT32_MAX) {
printError("Super Screenshot is too large, invalid resolution parameters");
return -1;
}
image_box.vram = (uint8_t*)malloc(image_box_size);
if (image_box.vram == nullptr) {
printError("Unable to allocate memory for super screenshot");
return -1;
}
memset(image_box.vram,0,image_box_size);

printf("\n\nRendering Super Screenshot:");
printf("\n\t%ux%u %u samples",image_box.resX,image_box.resY,image_render_data.sample * image_render_data.sample);
if (image_fractal_data.type_value == Fractal_ABS_Mandelbrot) {
printf(", %u iterations",image_fractal_data.type.abs_mandelbrot.maxItr);
} else if (image_fractal_data.type_value == Fractal_Polar_Mandelbrot) {
printf(", %u iterations",image_fractal_data.type.polar_mandelbrot.maxItr);
}
switch(image_render_data.rendering_method) {
case Rendering_Method::CPU_Rendering:
printf("\n\tFP%u CPU rendering, %u threads",image_render_data.CPU_Precision,image_render_data.CPU_Threads);
break;
case Rendering_Method::GPU_Rendering:
printf("\n\tFP%u GPU rendering",image_render_data.GPU_Precision);
break;
};
printf("\n\tClick \"Abort Rendering\" (or use task manager) to cancel.");
fflush(stdout);
uint64_t image_stopwatch = getNanoTime();
switch(image_render_data.rendering_method) {
case Rendering_Method::CPU_Rendering:
if (image_fractal_data.type.abs_mandelbrot.polarMandelbrot == true) {
renderCPU_Polar_Mandelbrot(&image_box,image_render_data,image_fractal_data.type.abs_mandelbrot,ABORT_RENDERING, primaryRender.CPU_Threads);
} else {
renderCPU_ABS_Mandelbrot(&image_box,image_render_data,image_fractal_data.type.abs_mandelbrot,ABORT_RENDERING, primaryRender.CPU_Threads);
}
break;
case Rendering_Method::GPU_Rendering:
renderOpenCL_ABS_Mandelbrot(&image_box,image_render_data,image_fractal_data.type.abs_mandelbrot,ABORT_RENDERING);
break;
default:
printfInterval(0.5,"Error: Super Screenshot, unknown rendering method %u",image_render_data.rendering_method);
return -1;
};
uint64_t image_render_time = getNanoTime() - image_stopwatch;
uint32_t time_mili = (uint32_t)(image_render_time / (((uint64_t)1000000)) % (uint64_t)1000);
uint32_t time_seconds = (uint32_t)((image_render_time / ((uint64_t)1000000 * (uint64_t)1000)) % (uint64_t)60);
uint32_t time_minutes = (uint32_t)((image_render_time / ((uint64_t)1000000 * (uint64_t)1000 * (uint64_t)60)) % (uint64_t)60);
uint32_t time_hours = (uint32_t)(image_render_time / ((uint64_t)1000000 * (uint64_t)1000 * (uint64_t)60 * (uint64_t)60));
printFlush("\n\tRendered in: %02u:%02u:%02u.%03u",time_hours,time_minutes,time_seconds,time_mili);
printFlush("\n\tSaving Super Screenshot");
{
uint64_t curTime = getNanoTime();
curTime /= 1000;
char id_number[64]; memset(id_number,'\0',sizeof(id_number));
if (image_fractal_data.type_value == Fractal_ABS_Mandelbrot) {
snprintf(id_number,sizeof(id_number),"_id-%llu",image_fractal_data.type.abs_mandelbrot.formula);
} else if (image_fractal_data.type_value == Fractal_Polar_Mandelbrot) {
snprintf(id_number,sizeof(id_number),"_id-%llu",image_fractal_data.type.polar_mandelbrot.formula);
}
size_t size = snprintf(nullptr,0,"Super_%s%s_(%llu)",FractalTypeFileText[image_fractal_data.type_value],id_number,curTime);
size++;
char* name = (char*)calloc(size,sizeof(char));
snprintf(name,size,"Super_%s%s_(%llu)",FractalTypeFileText[image_fractal_data.type_value],id_number,curTime);
char path[] = "./";
switch(image_file_format) {
case Image_File_Format::PNG:
valueLimit(image_quality,1,9);
writePNGImage(&image_box,path,name,image_quality);
break;
case Image_File_Format::JPG:
valueLimit(image_quality,30,100);
writeJPGImage(&image_box,path,name,image_quality);
break;
default:
image_file_format = Image_File_Format::PNG;
image_quality = 8;
writePNGImage(&image_box,path,name,image_quality);
};
}
FREE(image_box.vram);
}
return 0;
}

int render_Engine(std::atomic<bool>& QUIT_FLAG, std::atomic<bool>& ABORT_RENDERING, std::mutex& Key_Function_Mutex) {
if (currentBuf == nullptr || currentBuf->vram == nullptr || currentBuf->allocated() == false) {
return -1;
Expand All @@ -54,14 +158,14 @@ int render_Engine(std::atomic<bool>& QUIT_FLAG, std::atomic<bool>& ABORT_RENDERI
//printfInterval(0.4,"\nr: %.6lf i: %.6lf zoom: 10^%.4lf maxItr: %u formula: %llu",FRAC.r,FRAC.i,FRAC.zoom,FRAC.maxItr,FRAC.formula);
#undef FRAC
switch(primaryRender.rendering_method) {
case 0:
case Rendering_Method::CPU_Rendering:
if (fracData.type.abs_mandelbrot.polarMandelbrot == true) {
renderCPU_Polar_Mandelbrot(&renderBox,primaryRender,fracData.type.abs_mandelbrot,ABORT_RENDERING, primaryRender.CPU_Threads);
} else {
renderCPU_ABS_Mandelbrot(&renderBox,primaryRender,fracData.type.abs_mandelbrot,ABORT_RENDERING, primaryRender.CPU_Threads);
}
break;
case 1:
case Rendering_Method::GPU_Rendering:
renderOpenCL_ABS_Mandelbrot(&renderBox,primaryRender,fracData.type.abs_mandelbrot,ABORT_RENDERING);
break;
default:
Expand Down Expand Up @@ -121,7 +225,11 @@ int start_Engine(std::atomic<bool>& QUIT_FLAG, std::atomic<bool>& ABORT_RENDERIN
}
if (render_update_timecode == read_Update_Timecode() && ABORT_RENDERING == false) {
clear_Update_Level();
super_render_code(ABORT_RENDERING);
} else {
reset_Image_Render();
}

while (fracTime.timerReset() == false) {
if (read_Abort_Render_Ongoing() == true) {
write_Abort_Render_Ongoing(false);
Expand All @@ -138,6 +246,7 @@ int init_Engine(std::atomic<bool>& QUIT_FLAG, std::atomic<bool>& ABORT_RENDERING
}
queryOpenCL_GPU();
clear_Cycle_Buffers();
reset_Image_Render();
write_Engine_Ready(true);
while (read_Render_Ready() == false) {
if (QUIT_FLAG == true) {
Expand Down
51 changes: 49 additions & 2 deletions src/programData.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** Author: zerico2005 (2023)
** Author: zerico2005 (2023-2024)
** Project: ABS-Fractal-Explorer
** License: MIT License
** A copy of the MIT License should be included with
Expand Down Expand Up @@ -321,4 +321,51 @@ void setRenderDelta(fp64 t) {
fp64 getRenderDelta() {
std::lock_guard<std::mutex> lock(pDat_Request_Mutex);
return renderDelta;
}
}

/* Image Render */
std::mutex pDat_Image_Render_Mutex;
Fractal_Data pDat_Image_Render_Fractal;
Render_Data pDat_Image_Render_Data;
bool pDat_Image_Render_Ready = false;
uint32_t pDat_Image_File_Format = 0;
uint8_t pDat_Image_Quality = 8;

void reset_Image_Render() {
std::lock_guard<std::mutex> lock(pDat_Image_Render_Mutex);
pDat_Image_Render_Ready = false;
memset(&pDat_Image_Render_Fractal,0,sizeof(Fractal_Data));
memset(&pDat_Image_Render_Data,0,sizeof(Render_Data));
}

void send_Image_Render(
const Fractal_Data* frac, const Render_Data* super,
uint32_t image_file_format, uint8_t image_quality
) {
if (frac == nullptr || super == nullptr) {
return;
}
std::lock_guard<std::mutex> lock(pDat_Image_Render_Mutex);
pDat_Image_Render_Ready = false;
pDat_Image_Render_Fractal = *frac;
pDat_Image_Render_Data = *super;
pDat_Image_Render_Ready = true;
}

bool receive_Image_Render(
Fractal_Data* frac, Render_Data* super, uint32_t* image_file_format, uint8_t* image_quality
) {
if (frac == nullptr || super == nullptr || image_file_format == nullptr || image_quality == nullptr) {
return false;
}
std::lock_guard<std::mutex> lock(pDat_Image_Render_Mutex);
if (pDat_Image_Render_Ready == false) {
return false;
}
*frac = pDat_Image_Render_Fractal;
*super = pDat_Image_Render_Data;
*image_file_format = pDat_Image_File_Format;
*image_quality = pDat_Image_Quality;
pDat_Image_Render_Ready = false;
return true;
}
15 changes: 14 additions & 1 deletion src/programData.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** Author: zerico2005 (2023)
** Author: zerico2005 (2023-2024)
** Project: ABS-Fractal-Explorer
** License: MIT License
** A copy of the MIT License should be included with
Expand Down Expand Up @@ -50,6 +50,7 @@ struct Render_Task {
}; typedef Render_Task Render_Task;

/* Update Level */

namespace Change_Level {
enum Change_Level_Enum {
Nothing, // Image buffer is perfect
Expand All @@ -65,6 +66,7 @@ struct Render_Task {
Change_Level_Count
};
};

// Used to deterimine if rendering should pause, continue, or reset
int read_Update_Level();
uint64_t read_Update_Timecode();
Expand Down Expand Up @@ -112,4 +114,15 @@ int write_Image_Buffers(ImageBuffer* primary);
void setRenderDelta(fp64 t);
fp64 getRenderDelta();

/* Image Render */
void reset_Image_Render();
void send_Image_Render(
const Fractal_Data* frac, const Render_Data* super,
uint32_t image_file_format, uint8_t image_quality
);
bool receive_Image_Render(
Fractal_Data* frac, Render_Data* super,
uint32_t* image_file_format, uint8_t* image_quality
);

#endif /* PROGRAMDATA_H */
Loading

0 comments on commit 8fa0b26

Please sign in to comment.