Blender GPU / CPU Render (#81)

* Add script to get GPU information from Blender

* Change run_python_script to allow it to run without a project file

* Simplify run_python_script code

* Fix mistake

* Add system_info to engine classes and api_server. /api/renderer_info now supports standard and full response modes.

* Get full renderer_info response for add job UI

* Enable setting specific Blender render_device using args

* Add Blender render device options to UI
This commit is contained in:
2024-08-03 18:26:56 -05:00
committed by GitHub
parent 9bc490acae
commit ef4fc0e42e
8 changed files with 107 additions and 42 deletions

View File

@@ -56,25 +56,27 @@ class Blender(BaseRenderEngine):
else:
raise FileNotFoundError(f'Project file not found: {project_path}')
def run_python_script(self, project_path, script_path, timeout=None):
if os.path.exists(project_path) and os.path.exists(script_path):
try:
return subprocess.run([self.renderer_path(), '-b', project_path, '--python', script_path],
capture_output=True, timeout=timeout)
except Exception as e:
logger.warning(f"Error running python script in blender: {e}")
pass
elif not os.path.exists(project_path):
def run_python_script(self, script_path, project_path=None, timeout=None):
if project_path and not os.path.exists(project_path):
raise FileNotFoundError(f'Project file not found: {project_path}')
elif not os.path.exists(script_path):
raise FileNotFoundError(f'Python script not found: {script_path}')
raise Exception("Uncaught exception")
try:
command = [self.renderer_path(), '-b', '--python', script_path]
if project_path:
command.insert(2, project_path)
return subprocess.run(command, capture_output=True, timeout=timeout)
except Exception as e:
logger.exception(f"Error running python script in blender: {e}")
def get_project_info(self, project_path, timeout=10):
scene_info = {}
try:
script_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'scripts', 'get_file_info.py')
results = self.run_python_script(project_path, system_safe_path(script_path), timeout=timeout)
results = self.run_python_script(project_path=project_path, script_path=system_safe_path(script_path),
timeout=timeout)
result_text = results.stdout.decode()
for line in result_text.splitlines():
if line.startswith('SCENE_DATA:'):
@@ -92,7 +94,8 @@ class Blender(BaseRenderEngine):
try:
logger.info(f"Starting to pack Blender file: {project_path}")
script_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'scripts', 'pack_project.py')
results = self.run_python_script(project_path, system_safe_path(script_path), timeout=timeout)
results = self.run_python_script(project_path=project_path, script_path=system_safe_path(script_path),
timeout=timeout)
result_text = results.stdout.decode()
dir_name = os.path.dirname(project_path)
@@ -144,12 +147,20 @@ class Blender(BaseRenderEngine):
return options
def get_detected_gpus(self):
# no longer works on 4.0
engine_output = subprocess.run([self.renderer_path(), '-E', 'help'], timeout=SUBPROCESS_TIMEOUT,
capture_output=True).stdout.decode('utf-8')
gpu_names = re.findall(r"DETECTED GPU: (.+)", engine_output)
return gpu_names
def system_info(self):
return {'render_devices': self.get_render_devices()}
def get_render_devices(self):
script_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'scripts', 'get_system_info.py')
results = self.run_python_script(script_path=script_path)
output = results.stdout.decode()
match = re.search(r"GPU DATA:(\[[\s\S]*\])", output)
if match:
gpu_data_json = match.group(1)
gpus_info = json.loads(gpu_data_json)
return gpus_info
else:
logger.error("GPU data not found in the output.")
def supported_render_engines(self):
engine_output = subprocess.run([self.renderer_path(), '-E', 'help'], timeout=SUBPROCESS_TIMEOUT,
@@ -163,5 +174,5 @@ class Blender(BaseRenderEngine):
if __name__ == "__main__":
x = Blender.get_detected_gpus()
x = Blender().get_render_devices()
print(x)