mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
fix darkcult: add -Pn parallel rendering mode.
This commit is contained in:
parent
66bcd78e9f
commit
e17e0913c5
2 changed files with 115 additions and 28 deletions
54
tools/darkroom/darkcult.py
Executable file
54
tools/darkroom/darkcult.py
Executable file
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import os
|
||||
import subprocess
|
||||
import multiprocessing
|
||||
|
||||
def compile(command):
|
||||
sys.stdout.write(".")
|
||||
sys.stdout.flush()
|
||||
return subprocess.call(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
|
||||
if __name__=="__main__":
|
||||
argv = sys.argv
|
||||
argc = len(argv)
|
||||
|
||||
src = argv[1]
|
||||
stagedir = argv[2]
|
||||
output = argv[3]
|
||||
compiler = argv[4]
|
||||
width = int(argv[5])
|
||||
height = int(argv[6])
|
||||
tile_width = int(argv[7])
|
||||
tile_height = int(argv[8])
|
||||
compile_options = argv[9]
|
||||
darkcult_cpp = argv[10]
|
||||
max_procs = int(argv[11])
|
||||
|
||||
commands = []
|
||||
for y in range(0, height, tile_height):
|
||||
for x in range(0, width, tile_width):
|
||||
bin = "%s/%d/%d.out" % (stagedir, y, x)
|
||||
out = "%s/%d/%d.ppm" % (stagedir, y, x)
|
||||
command = "%s -o %s" \
|
||||
" %s" \
|
||||
" -DDARKROOM_SOURCE=\'\"%s\"\'" \
|
||||
" -DDARKROOM_TOTAL_WIDTH=%d -DDARKROOM_TOTAL_HEIGHT=%d" \
|
||||
" -DDARKROOM_TILE_WIDTH=%d -DDARKROOM_TILE_HEIGHT=%d" \
|
||||
" -DDARKROOM_OFFSET_X=%d -DDARKROOM_OFFSET_Y=%d" \
|
||||
" %s" \
|
||||
" && %s > %s" \
|
||||
% (compiler, bin,
|
||||
compile_options,
|
||||
src,
|
||||
width, height,
|
||||
tile_width, tile_height,
|
||||
x, y,
|
||||
darkcult_cpp,
|
||||
bin, out
|
||||
)
|
||||
commands.append(command);
|
||||
|
||||
pool = multiprocessing.Pool(max_procs)
|
||||
sys.exit(any(pool.map(compile, commands)))
|
|
@ -21,10 +21,13 @@ declare -a user_macros
|
|||
user_macros=()
|
||||
declare -a include_paths
|
||||
include_paths=()
|
||||
max_procs=1
|
||||
force=0
|
||||
use_help=0
|
||||
darkcult_cpp=$(cd $(dirname $0); pwd)/darkcult.cpp
|
||||
darkcult_py=$(cd $(dirname $0); pwd)/darkcult.py
|
||||
|
||||
args=`getopt -o s:S:o:C:w:h:W:H:D:I:f -l source:,stagedir:,output:,compiler:,width:,height:,tile-width:,tile-height:,define:,include:,force,help -- "$@"`
|
||||
args=`getopt -o s:S:o:C:w:h:W:H:D:I:P:f -l source:,stagedir:,output:,compiler:,width:,height:,tile-width:,tile-height:,define:,include:,max-procs:,force,help -- "$@"`
|
||||
if [ "$?" -ne 0 ]; then
|
||||
echo >&2 "error: options parse error. See 'darkcult.sh --help'"
|
||||
exit 1
|
||||
|
@ -42,6 +45,7 @@ while [ -n "$1" ]; do
|
|||
-H|--tile-height) tile_height=$2; shift 2;;
|
||||
-D|--define) user_macros=(${user_macros[@]} "$2"); shift 2;;
|
||||
-I|--include) include_paths=(${include_paths[@]} "$2"); shift 2;;
|
||||
-P|--max_procs) max_procs=$2; shift 2;;
|
||||
-f|--force) force=1; shift;;
|
||||
--help) use_help=1; shift;;
|
||||
--) shift; break;;
|
||||
|
@ -80,6 +84,9 @@ if [ ${use_help} -ne 0 ]; then
|
|||
echo ""
|
||||
echo " -I, --include=<dir> Add system include path."
|
||||
echo ""
|
||||
echo " -P, --max-procs=<value> The maximum number of process use."
|
||||
echo " Default; 1"
|
||||
echo ""
|
||||
echo " -f, --force Allow overwrite of <stagedir>."
|
||||
echo ""
|
||||
echo " --help This message."
|
||||
|
@ -101,6 +108,7 @@ fi
|
|||
if [ ${#include_paths[*]} -gt 0 ]; then
|
||||
echo " include-paths = (${include_paths[*]})"
|
||||
fi
|
||||
echo " max-procs = ${max_procs}"
|
||||
echo " force = ${force}"
|
||||
|
||||
if [ ! -f "${src}" -a ! -f "$(cd $(dirname $0); pwd)/${src}" ]; then
|
||||
|
@ -127,26 +135,32 @@ for include_path in ${include_paths}; do
|
|||
include_options="${include_options} -I${include_path}"
|
||||
done
|
||||
|
||||
for ((y=0; y<height; y+=tile_height)); do
|
||||
mkdir -p ${stagedir}/${y}/
|
||||
done
|
||||
|
||||
compile_options=-std=c++11 ${define_options} ${include_options}
|
||||
|
||||
echo "rendering:"
|
||||
start=${SECONDS}
|
||||
|
||||
for ((y=0; y<height; y+=tile_height)); do
|
||||
if [ ${max_procs} -eq 1 ]; then
|
||||
for ((y=0; y<height; y+=tile_height)); do
|
||||
echo " y = (${y}/${height})..."
|
||||
y_start=${SECONDS}
|
||||
|
||||
mkdir -p ${stagedir}/${y}/
|
||||
echo -n " x = "
|
||||
for ((x=0; x<width; x+=tile_width)); do
|
||||
echo -n "(${x}/${height})..."
|
||||
binname=${y}/${x}.out
|
||||
bin=${stagedir}/${binname}
|
||||
${compiler} -o ${bin} -std=c++11 \
|
||||
${define_options} ${include_options} \
|
||||
${compiler} -o ${bin} \
|
||||
${compile_options} \
|
||||
-DDARKROOM_SOURCE="\"${src}\"" \
|
||||
-DDARKROOM_TOTAL_WIDTH=${width} -DDARKROOM_TOTAL_HEIGHT=${height} \
|
||||
-DDARKROOM_TILE_WIDTH=${tile_width} -DDARKROOM_TILE_HEIGHT=${tile_height} \
|
||||
-DDARKROOM_OFFSET_X=${x} -DDARKROOM_OFFSET_Y=${y} \
|
||||
$(cd $(dirname $0); pwd)/darkcult.cpp
|
||||
${darkcult_cpp}
|
||||
if [ $? -ne 0 ]; then
|
||||
echo ""
|
||||
echo >&2 "error: compile(${binname}) failed."
|
||||
|
@ -156,19 +170,38 @@ for ((y=0; y<height; y+=tile_height)); do
|
|||
done
|
||||
echo ""
|
||||
|
||||
let "y_elapsed=${SECONDS}-${y_start}"
|
||||
echo " elapsed = ${y_elapsed}s"
|
||||
done
|
||||
else
|
||||
echo " processing in parallel mode."
|
||||
echo -n " "
|
||||
python "${darkcult_py}" \
|
||||
"${src}" "${stagedir}" "${output}" "${compiler}" \
|
||||
"${width}" "${height}" \
|
||||
"${tile_width}" "${tile_height}" \
|
||||
"${compile_options}" "${darkcult_cpp}" \
|
||||
"${max_procs}"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo ""
|
||||
echo >&2 "error: compile failed."
|
||||
exit 1
|
||||
fi
|
||||
echo ""
|
||||
fi
|
||||
|
||||
let "elapsed=${SECONDS}-${start}"
|
||||
echo " elapsed(total) = ${elapsed}s"
|
||||
|
||||
for ((y=0; y<height; y+=tile_height)); do
|
||||
pushd ${stagedir}/${y}/ > /dev/null
|
||||
# convert +append $(ls *.ppm | sort -n) ../${y}.ppm
|
||||
pnmcat -lr $(ls *.ppm | sort -n) > ../${y}.ppm
|
||||
popd > /dev/null
|
||||
|
||||
let "y_elapsed=${SECONDS}-${y_start}"
|
||||
echo " elapsed = ${y_elapsed}s"
|
||||
done
|
||||
pushd ${stagedir} > /dev/null
|
||||
#convert -append $(ls *.ppm | sort -n) ${output}
|
||||
pnmcat -tb $(ls *.ppm | sort -n) > ${output}
|
||||
popd > /dev/null
|
||||
|
||||
let "elapsed=${SECONDS}-${start}"
|
||||
echo " elapsed(total) = ${elapsed}s"
|
||||
echo "finished."
|
||||
|
|
Loading…
Reference in a new issue