diff --git a/__init__.py b/__init__.py index c3251d8..ac9df0d 100644 --- a/__init__.py +++ b/__init__.py @@ -261,21 +261,55 @@ def make_directories(save_path): return Blend_My_NFTs_Output, batch_json_save_path, nftBatch_save_path -def run_as_headless(): +def force_optix_or_cuda(): """ - For use when running from the command line. + Force OptiX or CUDA. Preferably OptiX """ - # force CUDA device usage with cycles renderer + # Force Optix device usage with cycles renderer cprefs = bpy.context.preferences.addons['cycles'].preferences + bpy.context.preferences.addons['cycles'].preferences.compute_device_type = 'OPTIX' + bpy.context.preferences.addons['cycles'].preferences.refresh_devices() + print(bpy.context.preferences.addons['cycles'].preferences.devices.keys()) + + for key in bpy.context.preferences.addons['cycles'].preferences.devices.keys(): + bpy.context.preferences.addons['cycles'].preferences.devices[key].use = True + + bpy.context.scene.cycles.device = 'GPU' + + if cprefs.get_num_gpu_devices() > 0: + print('Using {} OptiX GPUs for rendering!'.format(cprefs.get_num_gpu_devices())) + return + + print("no luck with OptiX! let's try CUDA instead!", end="\n") + cprefs.compute_device_type = 'CUDA' - cprefs.get_devices() + cprefs.refresh_devices() print(cprefs.devices.keys()) for key in cprefs.devices.keys(): cprefs.devices[key].use = True - print('Using {} devices for rendering!'.format(cprefs.get_num_gpu_devices())) + bpy.context.scene.cycles.device = 'GPU' + + if cprefs.get_num_gpu_devices() > 0: + print('Using {} CUDA GPUs for rendering!'.format(cprefs.get_num_gpu_devices())) + return + + + print("you're doomed! no CUDA or OptiX GPUs found!", end="\n") + bpy.context.scene.render.engine = 'CYCLES' + bpy.context.scene.cycles.device = 'CPU' + print("enjoy slow CPU ;)", end="\n") + +def run_as_headless(): + """ + For use when running from the command line. + """ + + # if user want's the Eevee pass this + if bpy.context.scene.render.engine == 'CYCLES': + force_optix_or_cuda() # def dumpSettings(settings): # output = ( diff --git a/main/headless_util.py b/main/headless_util.py index 415ae91..5e1f801 100644 --- a/main/headless_util.py +++ b/main/headless_util.py @@ -57,7 +57,7 @@ def get_python_args(): required=False, help="Use pre-existing batch data for rendering" ) - + parser.add_argument("--logic-file", dest="logic_file", metavar='FILE', @@ -71,4 +71,12 @@ def get_python_args(): required=False, help="Resume failed batch" ) + + parser.add_argument("--cycles-device", + dest="cycles-device", + choices=["OPTIX", "CUDA"], + required=False, + help="set cycles device to either OptiX or CUDA" + ) + return parser.parse_args(argv), parser