Implement GPU backend detection for Blender compatibility
- Added functionality to detect GPU backends (HIP and NVIDIA) during runner registration, enhancing compatibility for Blender versions below 4.x. - Introduced a new method, DetectAndStoreGPUBackends, to download the latest Blender and run a detection script, storing the results for future rendering decisions. - Updated rendering logic to force CPU rendering when HIP is detected on systems with Blender < 4.x, ensuring stability and compatibility. - Enhanced the Context structure to include flags for GPU detection status, improving error handling and rendering decisions based on GPU availability.
This commit is contained in:
@@ -11,3 +11,6 @@ var UnhideObjects string
|
||||
//go:embed scripts/render_blender.py.template
|
||||
var RenderBlenderTemplate string
|
||||
|
||||
//go:embed scripts/detect_gpu_backends.py
|
||||
var DetectGPUBackends string
|
||||
|
||||
|
||||
39
pkg/scripts/scripts/detect_gpu_backends.py
Normal file
39
pkg/scripts/scripts/detect_gpu_backends.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# Minimal script to detect HIP (AMD) and NVIDIA (CUDA/OptiX) backends for Cycles.
|
||||
# Run with: blender -b --python detect_gpu_backends.py
|
||||
# Prints HAS_HIP and/or HAS_NVIDIA to stdout, one per line.
|
||||
import sys
|
||||
|
||||
def main():
|
||||
try:
|
||||
prefs = bpy.context.preferences
|
||||
if not hasattr(prefs, 'addons') or 'cycles' not in prefs.addons:
|
||||
return
|
||||
cprefs = prefs.addons['cycles'].preferences
|
||||
has_hip = False
|
||||
has_nvidia = False
|
||||
for device_type in ('HIP', 'CUDA', 'OPTIX'):
|
||||
try:
|
||||
cprefs.compute_device_type = device_type
|
||||
cprefs.refresh_devices()
|
||||
devs = []
|
||||
if hasattr(cprefs, 'get_devices'):
|
||||
devs = cprefs.get_devices()
|
||||
elif hasattr(cprefs, 'devices') and cprefs.devices:
|
||||
devs = list(cprefs.devices) if hasattr(cprefs.devices, '__iter__') else [cprefs.devices]
|
||||
if devs:
|
||||
if device_type == 'HIP':
|
||||
has_hip = True
|
||||
if device_type in ('CUDA', 'OPTIX'):
|
||||
has_nvidia = True
|
||||
except Exception:
|
||||
pass
|
||||
if has_hip:
|
||||
print('HAS_HIP', flush=True)
|
||||
if has_nvidia:
|
||||
print('HAS_NVIDIA', flush=True)
|
||||
except Exception as e:
|
||||
print('ERROR', str(e), file=sys.stderr, flush=True)
|
||||
sys.exit(1)
|
||||
|
||||
import bpy
|
||||
main()
|
||||
Reference in New Issue
Block a user