Merge branch 'blender-v3.6-release'

This commit is contained in:
Sergey Sharybin 2023-05-30 11:47:35 +02:00
commit 5a44922937
4 changed files with 25 additions and 28 deletions

View File

@ -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;
}

View File

@ -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");
}
}

View File

@ -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()

View File

@ -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. */