Update to support additional blender scenes

This commit is contained in:
Nikolas
2024-08-26 16:48:45 -07:00
parent 83ecfb4ea7
commit 9d40cbaa93
3 changed files with 141 additions and 15 deletions

View File

@@ -1,6 +1,5 @@
"""Blender render test script"""
from blender_utils import \
download_barbershop_scene, find_blender, run_blender_render
from blender_utils import find_blender, run_blender_render, download_scene
from argparse import ArgumentParser
import logging
import os.path
@@ -26,9 +25,20 @@ console.setFormatter(formatter)
logging.getLogger('').addHandler(console)
VALID_DEVICES = ["CPU", "CUDA", "OPTIX", "HIP", "ONEAPI", "METAL"]
BENCHMARK_CONFIG = {
"Barbershop": "barbershop_interior.blend",
"Monster": "monster_under_the_bed_sss_demo_by_metin_seven.blend",
"Junkshop": "Junkshop.blend",
"BMW": "bmw27_cpu.blend",
}
parser = ArgumentParser()
parser.add_argument("-d", "--device", dest="device",
help="device", metavar="device", required=True)
parser.add_argument(
"--benchmark", dest="benchmark", help="Benchmark test type", metavar="benchmark", required=True)
args = parser.parse_args()
@@ -37,26 +47,30 @@ if args.device not in VALID_DEVICES:
sys.exit(1)
executable_path, version = find_blender()
download_barbershop_scene()
benchmark = args.benchmark
logging.info(f"The selected scene is {benchmark}")
download_scene(benchmark)
try:
logging.info('Starting benchmark!')
start_time = time.time()
benchmark= BENCHMARK_CONFIG[args.benchmark]
score = run_blender_render(
executable_path, LOG_DIRECTORY, args.device.upper())
executable_path, LOG_DIRECTORY, args.device.upper(), benchmark)
end_time = time.time()
logging.info('Finished rendering barbership in %d seconds', (end_time - start_time))
logging.info(f'Finished rendering {args.benchmark} in %d seconds', (end_time - start_time))
if score is None:
logging.error("No duration was found in the log to use as the score")
sys.exit(1)
report = {
"test": f"Blender Barbershop Render {args.device.upper()}",
"test": f"Blender {args.benchmark} Render {args.device.upper()}",
"score": score,
"unit": "seconds",
"version": version,
"device": args.device,
"benchmark": args.benchmark,
"start_time": seconds_to_milliseconds(start_time),
"end_time": seconds_to_milliseconds(end_time)
}

View File

@@ -10,13 +10,49 @@ import sys
import requests
# pylint: disable=no-name-in-module
from win32api import LOWORD, HIWORD, GetFileVersionInfo
from argparse import ArgumentParser
from zipfile import ZipFile
BENCHMARK_CONFIG = {
"Barbershop": "barbershop_interior.blend",
"Monster": "monster_under_the_bed_sss_demo_by_metin_seven.blend",
"Junkshop": "Junkshop.blend",
"BMW": "bmw27_cpu.blend",
}
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
parser = ArgumentParser()
parser.add_argument("-d", "--device", dest="device",
help="device", metavar="device", required=True)
parser.add_argument(
"--benchmark", dest="benchmark", help="Benchmark test type", metavar="benchmark", required=True)
args = parser.parse_args()
benchmark = args.benchmark
def download_scene(benchmark):
if benchmark == "Barbershop":
download_barbershop_scene()
if benchmark == "Monster":
download_monster_scene()
if benchmark == "Junkshop":
download_junkshop_scene()
if benchmark == "BMW":
download_bmw_scene()
def copy_from_network_drive():
"""Download barbershop from network drive"""
source = r"\\Labs\labs\03_ProcessingFiles\Blender Render\barbershop_interior.blend"
sourcepath = r'\\Labs\labs\03_ProcessingFiles\Blender Render'
sourcefile = BENCHMARK_CONFIG[args.benchmark]
source = os.path.join(sourcepath, sourcefile)
root_dir = os.path.dirname(os.path.realpath(__file__))
destination = os.path.join(root_dir, "barbershop_interior.blend")
destination = os.path.join(root_dir, sourcefile)
shutil.copyfile(source, destination)
logging.info(f"Copying file from {source}")
def download_barbershop_scene():
"""Downloads blender scene to render"""
@@ -27,6 +63,8 @@ def download_barbershop_scene():
try:
if os.path.isfile(dest_path) is not True:
copy_from_network_drive()
else:
logging.info('Barbershop already downloaded')
except Exception:
logging.info("Could not copy barbershop blend file from network share")
if os.path.isfile(dest_path) is not True:
@@ -35,7 +73,73 @@ def download_barbershop_scene():
download_url, allow_redirects=True, timeout=120)
with open(dest_path, 'wb') as file:
file.write(response.content)
logging.info('Barbershop already downloaded')
def download_bmw_scene():
"""Downloads blender scene to render"""
blend_file_name = BENCHMARK_CONFIG[args.benchmark]
download_url = f"https://download.blender.org/demo/test/BMW27_2.blend.zip"
zip_file = "BMW27_2.blend.zip"
root_dir = os.path.dirname(os.path.realpath(__file__))
dest_path = os.path.join(root_dir, blend_file_name)
zip_extract = os.path.join(root_dir, zip_file)
try:
if os.path.isfile(dest_path) is not True:
copy_from_network_drive()
else:
logging.info('BMW already downloaded')
except Exception:
logging.info("Could not copy BMW blend file from network share")
if os.path.isfile(dest_path) is not True:
logging.info("Downloading BMW scene from internet")
response = requests.get(download_url, allow_redirects=True, timeout=120)
with open(zip_extract, 'wb') as file:
file.write(response.content)
with ZipFile(zip_extract, 'r') as zip_object:
zip_object.extract("bmw27/bmw27_cpu.blend", path=root_dir)
def download_monster_scene():
"""Downloads blender scene to render"""
blend_file_name = BENCHMARK_CONFIG[args.benchmark]
download_url = f"https://download.blender.org/demo/cycles/{blend_file_name}"
root_dir = os.path.dirname(os.path.realpath(__file__))
dest_path = os.path.join(root_dir, blend_file_name)
try:
if os.path.isfile(dest_path) is not True:
copy_from_network_drive()
else:
logging.info('Monster already downloaded')
except Exception:
logging.info("Could not copy monster blend file from network share")
if os.path.isfile(dest_path) is not True:
logging.info("Downloading monster scene from internet")
response = requests.get(
download_url, allow_redirects=True, timeout=120)
with open(dest_path, 'wb') as file:
file.write(response.content)
def download_junkshop_scene():
"""Downloads blender scene to render"""
blend_file_name = "Blender 2.blend"
download_url = f"https://storage.googleapis.com/5649de716dcaf85da2faee95/_%2F35a35553b3dd4f8c8fb5a6ccc5065ff1.blend?GoogleAccessId=956532172770-27ie9eb8e4u326l89p7b113gcb04cdgd%40developer.gserviceaccount.com&Expires=1722324107&Signature=M0Im7Y61zF81JvFobeb1ZzOY%2FQP23Pbu%2B%2BjRjSPpyzfxDWaEgAKsceevZ5XV0OjJ2LDli2C6Bp%2BXhNvO8XfNLrTtCiPeFLHc02Bhm7T0%2B3FzpMmfauuCBvP0MKqMZGeMHD1z4ci7OFfsfsXYXBCuFx1FxaMNgZpkrv16gK13Hu%2BkhnIQUuR8q1iHHecXTUodRTfo2r6fQf8Y%2B9g4ysGuMMMY3o4SYZVE%2Flw0VdDMtjCIvc00uOwWM%2Fdyvt%2BDEbM9aEvD4yK2Iep0eMDRaPSE3xFAXcXgYHIZhB9zznVxHBeO6NKati%2F%2FZ08U%2Fu%2B3BIviu4SGYdrl86sPrDvCiKeG%2Bg%3D%3D"
root_dir = os.path.dirname(os.path.realpath(__file__))
dest_path = os.path.join(root_dir, blend_file_name)
try:
if os.path.isfile(dest_path) is not True:
copy_from_network_drive()
else:
logging.info('Barbershop already downloaded')
except Exception:
logging.info("Could not copy barbershop blend file from network share")
if os.path.isfile(dest_path) is not True:
logging.info("Downloading barbershop scene from internet")
response = requests.get(
download_url, allow_redirects=True, timeout=120)
with open(dest_path, 'wb') as file:
file.write(response.content)
def time_to_seconds(time_string):
"""convert string to duration in seconds"""
@@ -47,12 +151,13 @@ def time_to_seconds(time_string):
seconds = (time_obj.hour * 3600) + (time_obj.minute * 60) + time_obj.second + (time_obj.microsecond / 1e6)
return seconds
def run_blender_render(executable_path: str, log_directory: str, device: str) -> str:
def run_blender_render(executable_path: str, log_directory: str, device: str, benchmark: str) -> str:
"""Execute the blender render of barbershop, returns the duration as string"""
blend_log = os.path.join(log_directory, "blender.log")
root_dir = os.path.dirname(os.path.realpath(__file__))
blend_path = os.path.join(root_dir, "barbershop_interior.blend")
cmd_line = f"{executable_path} -b -E CYCLES -y {blend_path} -f 1 -- --cycles-device {device} --cycles-print-stats"
blend_path = os.path.join(root_dir, benchmark)
cmd_line = f"\"{executable_path}\" -b -E CYCLES -y \"{blend_path}\" -f 1 -- --cycles-device {device} --cycles-print-stats"
with open(blend_log,'w' , encoding="utf-8") as f_obj:
subprocess.run(cmd_line, stdout=f_obj, text=True, check=True)
@@ -95,5 +200,3 @@ def find_blender():
version = f"{HIWORD (version_ms)}.{LOWORD (version_ms)}.{HIWORD (version_ls)}.{LOWORD (version_ls)}"
return executable_path, version
copy_from_network_drive()

View File

@@ -1,4 +1,4 @@
friendly_name: "Blender Barbershop"
friendly_name: "Blender Render"
executable: "blender.py"
process_name: "blender.exe"
disable_presentmon: true
@@ -8,3 +8,12 @@ options:
- name: device
type: select
values: ["CPU", "CUDA", "OPTIX", "HIP", "ONEAPI", "METAL"]
- name: benchmark
type: select
values:
- "Barbershop"
- "Monster"
- "Classroom"
- "Junkshop"
- "BMW"
tooltip: Select which Blender scene to render