From 2a21675b01cabf1de764d36f883b19b63a6be16e Mon Sep 17 00:00:00 2001 From: Valtteri Koskivuori Date: Tue, 10 Dec 2019 16:38:20 +0200 Subject: [PATCH] Ports: C-ray rendering engine --- Ports/c-ray/package.sh | 17 ++++++ Ports/c-ray/patches/add-dummy-configure.patch | 3 + Ports/c-ray/patches/disable-checkbuf.patch | 23 ++++++++ Ports/c-ray/patches/enable-own-asprintf.patch | 19 ++++++ Ports/c-ray/patches/fix-linkage.patch | 30 ++++++++++ .../patches/lower-hdr-json-settings.patch | 26 +++++++++ .../patch-renderthread-and-main-loop.patch | 58 +++++++++++++++++++ 7 files changed, 176 insertions(+) create mode 100755 Ports/c-ray/package.sh create mode 100644 Ports/c-ray/patches/add-dummy-configure.patch create mode 100644 Ports/c-ray/patches/disable-checkbuf.patch create mode 100644 Ports/c-ray/patches/enable-own-asprintf.patch create mode 100644 Ports/c-ray/patches/fix-linkage.patch create mode 100644 Ports/c-ray/patches/lower-hdr-json-settings.patch create mode 100644 Ports/c-ray/patches/patch-renderthread-and-main-loop.patch diff --git a/Ports/c-ray/package.sh b/Ports/c-ray/package.sh new file mode 100755 index 0000000000..27148b357b --- /dev/null +++ b/Ports/c-ray/package.sh @@ -0,0 +1,17 @@ +#!/bin/bash ../.port_include.sh +port=c-ray +version=git +workdir=c-ray-master +useconfigure=true +curlopts="-L" +files="https://github.com/vkoskiv/c-ray/archive/master.tar.gz c-ray-git.tar.gz" +configopts="-DCMAKE_TOOLCHAIN_FILE=$SERENITY_ROOT/Toolchain/CMakeToolchain.txt -DNO_SDL2=True" + +configure() { + run cmake $configopts +} + +install() { + mkdir -p $SERENITY_ROOT/Root/home/anon/c-ray + cp -r c-ray-master/* $SERENITY_ROOT/Root/home/anon/c-ray +} diff --git a/Ports/c-ray/patches/add-dummy-configure.patch b/Ports/c-ray/patches/add-dummy-configure.patch new file mode 100644 index 0000000000..80f1456b76 --- /dev/null +++ b/Ports/c-ray/patches/add-dummy-configure.patch @@ -0,0 +1,3 @@ +diff --git a/configure b/configure +new file mode 100644 +index 0000000..e69de29 diff --git a/Ports/c-ray/patches/disable-checkbuf.patch b/Ports/c-ray/patches/disable-checkbuf.patch new file mode 100644 index 0000000000..eea4156855 --- /dev/null +++ b/Ports/c-ray/patches/disable-checkbuf.patch @@ -0,0 +1,23 @@ +diff --git a/src/utils/filehandler.c b/src/utils/filehandler.c +index 99638f3..feded8f 100644 +--- a/src/utils/filehandler.c ++++ b/src/utils/filehandler.c +@@ -162,7 +162,7 @@ char *loadFile(char *inputFileName, size_t *bytes) { + //Wait for 2 secs and abort if nothing is coming in from stdin + void checkBuf() { + #ifndef WINDOWS +- fd_set set; ++ /*fd_set set; + struct timeval timeout; + int rv; + FD_ZERO(&set); +@@ -176,7 +176,8 @@ void checkBuf() { + logr(error, "No input found after %i seconds. Hint: Try `./bin/c-ray input/scene.json`.\n", timeout.tv_sec); + } else { + return; +- } ++ }*/ ++ return; + #endif + } + diff --git a/Ports/c-ray/patches/enable-own-asprintf.patch b/Ports/c-ray/patches/enable-own-asprintf.patch new file mode 100644 index 0000000000..9263dd815d --- /dev/null +++ b/Ports/c-ray/patches/enable-own-asprintf.patch @@ -0,0 +1,19 @@ +diff --git a/src/libraries/asprintf.h b/src/libraries/asprintf.h +index 70a95ac..0e46c3c 100644 +--- a/src/libraries/asprintf.h ++++ b/src/libraries/asprintf.h +@@ -33,7 +33,6 @@ int vscprintf(const char *format, va_list ap) { + * GNU-C-compatible compilers implement these with the same names, thus we + * don't have to do anything + */ +-#ifdef _MSC_VER + int cray_vasprintf(char **strp, const char *format, va_list ap) { + int len = vscprintf(format, ap); + if (len == -1) +@@ -57,6 +56,5 @@ int asprintf(char **strp, const char *format, ...) { + va_end(ap); + return retval; + } +-#endif + + #endif // ASPRINTF_H diff --git a/Ports/c-ray/patches/fix-linkage.patch b/Ports/c-ray/patches/fix-linkage.patch new file mode 100644 index 0000000000..986cdd3868 --- /dev/null +++ b/Ports/c-ray/patches/fix-linkage.patch @@ -0,0 +1,30 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 5ccce96..1db6074 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -58,7 +58,7 @@ if (NOT NO_SDL2) + if (MSVC) + target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARY}) + else() +- target_link_libraries(${PROJECT_NAME} -lpthread -lm ${SDL2_LIBRARY}) ++ target_link_libraries(${PROJECT_NAME} -lSDL2 -lgui -ldraw -lipc -lcore -lpthread -lm -lstdc++) + endif() + add_definitions(-DUI_ENABLED) + else() +@@ -66,7 +66,7 @@ if (NOT NO_SDL2) + if (MSVC) + target_link_libraries(${PROJECT_NAME}) + else() +- target_link_libraries(${PROJECT_NAME} -lpthread -lm) ++ target_link_libraries(${PROJECT_NAME} -lgui -ldraw -lipc -lcore -lpthread -lm -lstdc++) + endif() + endif() + else() +@@ -75,6 +75,6 @@ else() + if (MSVC) + target_link_libraries(${PROJECT_NAME}) + else() +- target_link_libraries(${PROJECT_NAME} -lpthread -lm) ++ target_link_libraries(${PROJECT_NAME} -lgui -ldraw -lipc -lcore -lpthread -lm -lstdc++) + endif() + endif() diff --git a/Ports/c-ray/patches/lower-hdr-json-settings.patch b/Ports/c-ray/patches/lower-hdr-json-settings.patch new file mode 100644 index 0000000000..d0db6253f3 --- /dev/null +++ b/Ports/c-ray/patches/lower-hdr-json-settings.patch @@ -0,0 +1,26 @@ +diff --git a/input/hdr.json b/input/hdr.json +index c3fd066..ebd69da 100644 +--- a/input/hdr.json ++++ b/input/hdr.json +@@ -2,8 +2,8 @@ + "version": 1.0, + "renderer": { + "threadCount": 0, +- "sampleCount": 250, +- "bounces": 30, ++ "sampleCount": 1, ++ "bounces": 2, + "antialiasing": true, + "tileWidth": 64, + "tileHeight": 64, +@@ -39,8 +39,8 @@ + "outputFileName": "rendered", + "fileType": "png", + "count": 0, +- "width": 1280, +- "height": 800, ++ "width": 300, ++ "height": 200, + "ambientColor": { + "hdr": "input/HDRs/rooitou_park_1k.hdr", + "offset": 0, diff --git a/Ports/c-ray/patches/patch-renderthread-and-main-loop.patch b/Ports/c-ray/patches/patch-renderthread-and-main-loop.patch new file mode 100644 index 0000000000..e55aad3e78 --- /dev/null +++ b/Ports/c-ray/patches/patch-renderthread-and-main-loop.patch @@ -0,0 +1,58 @@ +diff --git a/src/renderer/renderer.c b/src/renderer/renderer.c +index 835d99b..aa06055 100644 +--- a/src/renderer/renderer.c ++++ b/src/renderer/renderer.c +@@ -20,8 +20,8 @@ + #include "../utils/loaders/textureloader.h" + + //Main thread loop speeds +-#define paused_msec 100 +-#define active_msec 16 ++#define paused_msec 800 ++#define active_msec 400 + + /// @todo Use defaultSettings state struct for this. + /// @todo Clean this up, it's ugly. +@@ -47,7 +47,6 @@ void render(struct renderer *r) { + //Main loop (input) + bool threadsHaveStarted = false; + float avgRayTime = 0.0f; +- int pauser = 0; + float finalAvg = 0.0f; + int ctr = 1; + while (r->state.isRendering) { +@@ -66,25 +65,6 @@ void render(struct renderer *r) { + sleepMSec(paused_msec); + } + +- //Run the sample printing about 4x/s +- if (pauser == 280 / active_msec) { +- long remainingSampleCount = ((r->state.tileCount - r->state.finishedTileCount) * r->prefs.tileWidth * r->prefs.tileHeight * r->prefs.sampleCount); +- double sps = (1000000.0f/finalAvg) * r->prefs.threadCount; +- long usecTillFinished = remainingSampleCount * finalAvg; +- char rem[32]; +- smartTime((0.001 * usecTillFinished) / r->prefs.threadCount, rem); +- float completion = ((float)r->state.finishedTileCount / r->state.tileCount) * 100; +- logr(info, "[%s%.0f%%%s] μs/ray: %.02f, etf: %s, %.02lfMs/s %s \r", +- KBLU, +- KNRM, +- completion, +- finalAvg, +- rem, +- 0.000001*sps, +- r->state.threadStates[0].paused ? "[PAUSED]" : ""); +- pauser = 0; +- } +- pauser++; + + if (!threadsHaveStarted) { + threadsHaveStarted = true; +@@ -286,7 +266,7 @@ void *renderThread(void *arg) { + //No more tiles to render, exit thread. (render done) + tinfo->threadComplete = true; + tinfo->currentTileNum = -1; +- return 0; ++ pthread_exit((void*) arg); //for Serenity, return 0 didn't work + } + + struct renderer *newRenderer() {