Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Jones <michael_p_jones@apple.com>2021-10-14 15:53:40 +0300
committerMichael Jones <michael_p_jones@apple.com>2021-10-14 18:14:43 +0300
commita0f269f682dab848afc80cd322d04a0c4a815cae (patch)
tree0978b1888273fbaa2d14550bde484c5247fa89ff /intern/cycles/kernel/closure/bsdf_hair_principled.h
parent47caeb8c26686e24ea7e694f94fabee44f3d2dca (diff)
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation. MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness. The vast majority of deltas in this patch fall into one of two cases: - Ensuring ccl_private is specified for thread-local pointer types - Ensuring ccl_global is specified for device-wide pointer types Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant. In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture. The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation. Ref T92212 Reviewed By: brecht Maniphest Tasks: T92212 Differential Revision: https://developer.blender.org/D12864
Diffstat (limited to 'intern/cycles/kernel/closure/bsdf_hair_principled.h')
-rw-r--r--intern/cycles/kernel/closure/bsdf_hair_principled.h58
1 files changed, 31 insertions, 27 deletions
diff --git a/intern/cycles/kernel/closure/bsdf_hair_principled.h b/intern/cycles/kernel/closure/bsdf_hair_principled.h
index bfe56e5ab0e..17097b0739b 100644
--- a/intern/cycles/kernel/closure/bsdf_hair_principled.h
+++ b/intern/cycles/kernel/closure/bsdf_hair_principled.h
@@ -24,12 +24,12 @@
CCL_NAMESPACE_BEGIN
-typedef ccl_addr_space struct PrincipledHairExtra {
+typedef struct PrincipledHairExtra {
/* Geometry data. */
float4 geom;
} PrincipledHairExtra;
-typedef ccl_addr_space struct PrincipledHairBSDF {
+typedef struct PrincipledHairBSDF {
SHADER_CLOSURE_BASE;
/* Absorption coefficient. */
@@ -46,7 +46,7 @@ typedef ccl_addr_space struct PrincipledHairBSDF {
float m0_roughness;
/* Extra closure. */
- PrincipledHairExtra *extra;
+ ccl_private PrincipledHairExtra *extra;
} PrincipledHairBSDF;
static_assert(sizeof(ShaderClosure) >= sizeof(PrincipledHairBSDF),
@@ -180,14 +180,15 @@ ccl_device_inline float longitudinal_scattering(
}
/* Combine the three values using their luminances. */
-ccl_device_inline float4 combine_with_energy(const KernelGlobals *kg, float3 c)
+ccl_device_inline float4 combine_with_energy(ccl_global const KernelGlobals *kg, float3 c)
{
return make_float4(c.x, c.y, c.z, linear_rgb_to_gray(kg, c));
}
#ifdef __HAIR__
/* Set up the hair closure. */
-ccl_device int bsdf_principled_hair_setup(ShaderData *sd, PrincipledHairBSDF *bsdf)
+ccl_device int bsdf_principled_hair_setup(ccl_private ShaderData *sd,
+ ccl_private PrincipledHairBSDF *bsdf)
{
bsdf->type = CLOSURE_BSDF_HAIR_PRINCIPLED_ID;
bsdf->v = clamp(bsdf->v, 0.001f, 1.0f);
@@ -228,7 +229,10 @@ ccl_device int bsdf_principled_hair_setup(ShaderData *sd, PrincipledHairBSDF *bs
#endif /* __HAIR__ */
/* Given the Fresnel term and transmittance, generate the attenuation terms for each bounce. */
-ccl_device_inline void hair_attenuation(const KernelGlobals *kg, float f, float3 T, float4 *Ap)
+ccl_device_inline void hair_attenuation(ccl_global const KernelGlobals *kg,
+ float f,
+ float3 T,
+ ccl_private float4 *Ap)
{
/* Primary specular (R). */
Ap[0] = make_float4(f, f, f, f);
@@ -259,7 +263,7 @@ ccl_device_inline void hair_attenuation(const KernelGlobals *kg, float f, float3
ccl_device_inline void hair_alpha_angles(float sin_theta_i,
float cos_theta_i,
float alpha,
- float *angles)
+ ccl_private float *angles)
{
float sin_1alpha = sinf(alpha);
float cos_1alpha = cos_from_sin(sin_1alpha);
@@ -277,15 +281,15 @@ ccl_device_inline void hair_alpha_angles(float sin_theta_i,
}
/* Evaluation function for our shader. */
-ccl_device float3 bsdf_principled_hair_eval(const KernelGlobals *kg,
- const ShaderData *sd,
- const ShaderClosure *sc,
+ccl_device float3 bsdf_principled_hair_eval(ccl_global const KernelGlobals *kg,
+ ccl_private const ShaderData *sd,
+ ccl_private const ShaderClosure *sc,
const float3 omega_in,
- float *pdf)
+ ccl_private float *pdf)
{
kernel_assert(isfinite3_safe(sd->P) && isfinite_safe(sd->ray_length));
- const PrincipledHairBSDF *bsdf = (const PrincipledHairBSDF *)sc;
+ ccl_private const PrincipledHairBSDF *bsdf = (ccl_private const PrincipledHairBSDF *)sc;
float3 Y = float4_to_float3(bsdf->extra->geom);
float3 X = safe_normalize(sd->dPdu);
@@ -355,18 +359,18 @@ ccl_device float3 bsdf_principled_hair_eval(const KernelGlobals *kg,
}
/* Sampling function for the hair shader. */
-ccl_device int bsdf_principled_hair_sample(const KernelGlobals *kg,
- const ShaderClosure *sc,
- ShaderData *sd,
+ccl_device int bsdf_principled_hair_sample(ccl_global const KernelGlobals *kg,
+ ccl_private const ShaderClosure *sc,
+ ccl_private ShaderData *sd,
float randu,
float randv,
- float3 *eval,
- float3 *omega_in,
- float3 *domega_in_dx,
- float3 *domega_in_dy,
- float *pdf)
+ ccl_private float3 *eval,
+ ccl_private float3 *omega_in,
+ ccl_private float3 *domega_in_dx,
+ ccl_private float3 *domega_in_dy,
+ ccl_private float *pdf)
{
- PrincipledHairBSDF *bsdf = (PrincipledHairBSDF *)sc;
+ ccl_private PrincipledHairBSDF *bsdf = (ccl_private PrincipledHairBSDF *)sc;
float3 Y = float4_to_float3(bsdf->extra->geom);
@@ -378,8 +382,8 @@ ccl_device int bsdf_principled_hair_sample(const KernelGlobals *kg,
float2 u[2];
u[0] = make_float2(randu, randv);
- u[1].x = lcg_step_float_addrspace(&sd->lcg_state);
- u[1].y = lcg_step_float_addrspace(&sd->lcg_state);
+ u[1].x = lcg_step_float(&sd->lcg_state);
+ u[1].y = lcg_step_float(&sd->lcg_state);
float sin_theta_o = wo.x;
float cos_theta_o = cos_from_sin(sin_theta_o);
@@ -482,9 +486,9 @@ ccl_device int bsdf_principled_hair_sample(const KernelGlobals *kg,
}
/* Implements Filter Glossy by capping the effective roughness. */
-ccl_device void bsdf_principled_hair_blur(ShaderClosure *sc, float roughness)
+ccl_device void bsdf_principled_hair_blur(ccl_private ShaderClosure *sc, float roughness)
{
- PrincipledHairBSDF *bsdf = (PrincipledHairBSDF *)sc;
+ ccl_private PrincipledHairBSDF *bsdf = (ccl_private PrincipledHairBSDF *)sc;
bsdf->v = fmaxf(roughness, bsdf->v);
bsdf->s = fmaxf(roughness, bsdf->s);
@@ -500,9 +504,9 @@ ccl_device_inline float bsdf_principled_hair_albedo_roughness_scale(
return (((((0.245f * x) + 5.574f) * x - 10.73f) * x + 2.532f) * x - 0.215f) * x + 5.969f;
}
-ccl_device float3 bsdf_principled_hair_albedo(const ShaderClosure *sc)
+ccl_device float3 bsdf_principled_hair_albedo(ccl_private const ShaderClosure *sc)
{
- PrincipledHairBSDF *bsdf = (PrincipledHairBSDF *)sc;
+ ccl_private PrincipledHairBSDF *bsdf = (ccl_private PrincipledHairBSDF *)sc;
return exp3(-sqrt(bsdf->sigma) * bsdf_principled_hair_albedo_roughness_scale(bsdf->v));
}