diff --git a/intern/cycles/device/metal/device_impl.mm b/intern/cycles/device/metal/device_impl.mm index c0c5f2e93d2..8b2949fb02f 100644 --- a/intern/cycles/device/metal/device_impl.mm +++ b/intern/cycles/device/metal/device_impl.mm @@ -345,7 +345,9 @@ string MetalDevice::preprocess_source(MetalPipelineType pso_type, case METAL_GPU_APPLE: global_defines += "#define __KERNEL_METAL_APPLE__\n"; # ifdef WITH_NANOVDB - global_defines += "#define WITH_NANOVDB\n"; + if (DebugFlags().metal.use_nanovdb) { + global_defines += "#define WITH_NANOVDB\n"; + } # endif break; } diff --git a/intern/cycles/device/metal/kernel.mm b/intern/cycles/device/metal/kernel.mm index c917d2b1bea..ed65345a41d 100644 --- a/intern/cycles/device/metal/kernel.mm +++ b/intern/cycles/device/metal/kernel.mm @@ -681,7 +681,7 @@ void MetalKernelPipeline::compile() __block bool compilation_finished = false; __block string error_str; - if (loading_existing_archive) { + if (loading_existing_archive || !DebugFlags().metal.use_async_pso_creation) { /* Use the blocking variant of newComputePipelineStateWithDescriptor if an archive exists on * disk. It should load almost instantaneously, and will fail gracefully when loading a * corrupt archive (unlike the async variant). */ @@ -694,29 +694,6 @@ void MetalKernelPipeline::compile() error_str = err ? err : "nil"; } else { - /* TODO / MetalRT workaround: - * Workaround for a crash when addComputePipelineFunctionsWithDescriptor is called *after* - * newComputePipelineStateWithDescriptor with linked functions (i.e. with MetalRT enabled). - * Ideally we would like to call newComputePipelineStateWithDescriptor (async) first so we - * can bail out if needed, but we can stop the crash by flipping the order when there are - * linked functions. However when addComputePipelineFunctionsWithDescriptor is called first - * it will block while it builds the pipeline, offering no way of bailing out. */ - auto addComputePipelineFunctionsWithDescriptor = [&]() { - if (creating_new_archive && ShaderCache::running) { - NSError *error; - if (![archive addComputePipelineFunctionsWithDescriptor:computePipelineStateDescriptor - error:&error]) - { - NSString *errStr = [error localizedDescription]; - metal_printf("Failed to add PSO to archive:\n%s\n", - errStr ? [errStr UTF8String] : "nil"); - } - } - }; - if (linked_functions) { - addComputePipelineFunctionsWithDescriptor(); - } - /* Use the async variant of newComputePipelineStateWithDescriptor if no archive exists on * disk. This allows us to respond to app shutdown. */ [mtlDevice @@ -744,10 +721,16 @@ void MetalKernelPipeline::compile() while (ShaderCache::running && !compilation_finished) { std::this_thread::sleep_for(std::chrono::milliseconds(5)); } + } - /* Add pipeline into the new archive (unless we did it earlier). */ - if (pipeline && !linked_functions) { - addComputePipelineFunctionsWithDescriptor(); + if (creating_new_archive && pipeline) { + /* Add pipeline into the new archive. */ + NSError *error; + if (![archive addComputePipelineFunctionsWithDescriptor:computePipelineStateDescriptor + error:&error]) + { + NSString *errStr = [error localizedDescription]; + metal_printf("Failed to add PSO to archive:\n%s\n", errStr ? [errStr UTF8String] : "nil"); } } diff --git a/intern/cycles/util/debug.cpp b/intern/cycles/util/debug.cpp index 6425cafeb41..aa484bcbf06 100644 --- a/intern/cycles/util/debug.cpp +++ b/intern/cycles/util/debug.cpp @@ -72,6 +72,12 @@ void DebugFlags::Metal::reset() if (auto str = getenv("CYCLES_METAL_LOCAL_ATOMIC_SORT")) use_local_atomic_sort = (atoi(str) != 0); + + if (auto str = getenv("CYCLES_METAL_NANOVDB")) + use_nanovdb = (atoi(str) != 0); + + if (auto str = getenv("CYCLES_METAL_ASYNC_PSO_CREATION")) + use_async_pso_creation = (atoi(str) != 0); } DebugFlags::OptiX::OptiX() diff --git a/intern/cycles/util/debug.h b/intern/cycles/util/debug.h index 9efbdceaefe..4af3db1e54e 100644 --- a/intern/cycles/util/debug.h +++ b/intern/cycles/util/debug.h @@ -100,6 +100,12 @@ class DebugFlags { /* Whether local atomic sorting is enabled or not. */ bool use_local_atomic_sort = true; + + /* Whether nanovdb is enabled or not. */ + bool use_nanovdb = true; + + /* Whether async PSO creation is enabled or not. */ + bool use_async_pso_creation = true; }; /* Get instance of debug flags registry. */