MSL requires that constant address space literals be declared at program scope. This patch moves the blackbody_table_r/g/b and cie_colour_match constants into separate files so they can be declared at the appropriate scope.
Ref T92212
Differential D13241
Cycles: Declare constants at program scope on Metal Authored by Michael Jones (michael_jones) on Nov 16 2021, 2:39 PM.
Details MSL requires that constant address space literals be declared at program scope. This patch moves the blackbody_table_r/g/b and cie_colour_match constants into separate files so they can be declared at the appropriate scope. Ref T92212
Diff Detail
Event TimelineComment Actions Assuming it works for other platforms, I think it would be neater to just move the constants to program scope and avoid the conditional includes. I'm open to suggestions! Comment Actions I think we can indeed have these at program scope for all devices. These were actually at program scope until recently, so should be fine. rB76de3ac4ce43: Cleanup: Remove data duplication from various lookup tables in Cycles. These are small tables so I'm not particularly concerned about duplication. Comment Actions Would MSL support these defined globally but as inline constexpr instead of static? That would also remove the duplication that occurs if these headers are used in multiple TUs. Comment Actions Specifying inline is a no-op in MSL and gives a warning ("inline variables are a C++17 extension"), however MSL does require that any program scope variable must reside in constant address space. We should probably hide the qualifiers behind a macro which can be defined on a per-platform basis. Comment Actions The previous constants' locations (as in rB76de3ac4ce43: Cleanup: Remove data duplication from various lookup tables in Cycles) would in fact be at class scope on Metal due to the context class. The simplest solution to this would be to include the constants in a monolithic block before including Metal's "context_begin.h", at the loss of some locality of reference (although I'm happy to consider other approaches if they seem better). Comment Actions I think it would be fine to move all the tables into a single file that we can include ahead of context_begin.h. Comment Actions Looks fine, but I think we could try the suggestion from @Jesse Yurkovich (deadpin)? Maybe rename ccl_static_constant to ccl_inline_constant, and then define that as inline constexpr for the CPU device, and leave it unchanged for GPU devices? Comment Actions I'm not sure if it's better to use /* clang-format off */ or just add a line break after #include "kernel/tables.h". Comment Actions
Comment Actions I need to add one fix for OptiX kernel building. I'll commit this patch myself with that fix included. |