[Bf-blender-cvs] [e270a198a54] master: Cycles: Markup to disable specialisation of kernel data fields (Metal)
Michael Jones
noreply at git.blender.org
Thu Jan 19 18:57:43 CET 2023
Commit: e270a198a548fcacc9dfecbda29c55fe7a05b5c9
Author: Michael Jones
Date: Thu Jan 19 17:57:26 2023 +0000
Branches: master
https://developer.blender.org/rBe270a198a548fcacc9dfecbda29c55fe7a05b5c9
Cycles: Markup to disable specialisation of kernel data fields (Metal)
This patch adds markup to specify that certain kernel data constants should not be specialised. Currently it is used for `tabulated_sobol_sequence_size` and `sobol_index_mask` which change frequently based on the aa sample count, trash the shader cache, and have little bearing on performance.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D16968
===================================================================
M intern/cycles/device/metal/device_impl.mm
M intern/cycles/device/metal/kernel.mm
M intern/cycles/kernel/data_template.h
===================================================================
diff --git a/intern/cycles/device/metal/device_impl.mm b/intern/cycles/device/metal/device_impl.mm
index 87614f656c3..917945fbdb6 100644
--- a/intern/cycles/device/metal/device_impl.mm
+++ b/intern/cycles/device/metal/device_impl.mm
@@ -327,10 +327,19 @@ void MetalDevice::make_source(MetalPipelineType pso_type, const uint kernel_feat
# define KERNEL_STRUCT_BEGIN(name, parent) \
string_replace_same_length(source, "kernel_data." #parent ".", "kernel_data_" #parent "_");
+ bool next_member_is_specialized = true;
+
+# define KERNEL_STRUCT_MEMBER_DONT_SPECIALIZE next_member_is_specialized = false;
+
/* Add constants to md5 so that 'get_best_pipeline' is able to return a suitable match. */
# define KERNEL_STRUCT_MEMBER(parent, _type, name) \
- baked_constants += string(#parent "." #name "=") + \
- to_string(_type(launch_params.data.parent.name)) + "\n";
+ if (next_member_is_specialized) { \
+ baked_constants += string(#parent "." #name "=") + \
+ to_string(_type(launch_params.data.parent.name)) + "\n"; \
+ } else { \
+ string_replace(source, "kernel_data_" #parent "_" #name, "kernel_data." #parent ".__unused_" #name); \
+ next_member_is_specialized = true; \
+ }
# include "kernel/data_template.h"
diff --git a/intern/cycles/device/metal/kernel.mm b/intern/cycles/device/metal/kernel.mm
index 48bdf2f0ef1..febce2840ea 100644
--- a/intern/cycles/device/metal/kernel.mm
+++ b/intern/cycles/device/metal/kernel.mm
@@ -460,13 +460,17 @@ static MTLFunctionConstantValues *GetConstantValues(KernelData const *data = nul
if (!data) {
data = &zero_data;
}
- int zero_int = 0;
- [constant_values setConstantValue:&zero_int type:MTLDataType_int atIndex:Kernel_DummyConstant];
+ [constant_values setConstantValue:&zero_data type:MTLDataType_int atIndex:Kernel_DummyConstant];
+
+ bool next_member_is_specialized = true;
+
+# define KERNEL_STRUCT_MEMBER_DONT_SPECIALIZE next_member_is_specialized = false;
# define KERNEL_STRUCT_MEMBER(parent, _type, name) \
- [constant_values setConstantValue:&data->parent.name \
+ [constant_values setConstantValue:next_member_is_specialized ? (void*)&data->parent.name : (void*)&zero_data \
type:MTLDataType_##_type \
- atIndex:KernelData_##parent##_##name];
+ atIndex:KernelData_##parent##_##name]; \
+ next_member_is_specialized = true;
# include "kernel/data_template.h"
diff --git a/intern/cycles/kernel/data_template.h b/intern/cycles/kernel/data_template.h
index ddc462e02f6..dceae4b77c1 100644
--- a/intern/cycles/kernel/data_template.h
+++ b/intern/cycles/kernel/data_template.h
@@ -10,6 +10,10 @@
#ifndef KERNEL_STRUCT_MEMBER
# define KERNEL_STRUCT_MEMBER(parent, type, name)
#endif
+#ifndef KERNEL_STRUCT_MEMBER_DONT_SPECIALIZE
+# define KERNEL_STRUCT_MEMBER_DONT_SPECIALIZE
+#endif
+
/* Background. */
@@ -179,8 +183,8 @@ KERNEL_STRUCT_MEMBER(integrator, float, sample_clamp_indirect)
KERNEL_STRUCT_MEMBER(integrator, int, use_caustics)
/* Sampling pattern. */
KERNEL_STRUCT_MEMBER(integrator, int, sampling_pattern)
-KERNEL_STRUCT_MEMBER(integrator, int, tabulated_sobol_sequence_size)
-KERNEL_STRUCT_MEMBER(integrator, int, sobol_index_mask)
+KERNEL_STRUCT_MEMBER_DONT_SPECIALIZE KERNEL_STRUCT_MEMBER(integrator, int, tabulated_sobol_sequence_size)
+KERNEL_STRUCT_MEMBER_DONT_SPECIALIZE KERNEL_STRUCT_MEMBER(integrator, int, sobol_index_mask)
KERNEL_STRUCT_MEMBER(integrator, float, scrambling_distance)
/* Volume render. */
KERNEL_STRUCT_MEMBER(integrator, int, use_volumes)
More information about the Bf-blender-cvs
mailing list