Metal: GLSL Shader compatibility 5

MSL does not have an implicit global scope, this is emulated via macro's adding an indirection for uniforms, attributes, shader stage inputs and outputs such as:

#define roughness shaderinst->roughness.

Variables in GLSL which exist within uniform blocks can be directly referenced via the global scope, unlike standard C++. This means that variable name pollution occurs if subsequent local variables in the code use the same name, resulting in compilation errors.

A number of these conflicting names have been renamed to ensure unique naming and no further scope pollution.

Ref T96261

Reviewed By: fclem

Maniphest Tasks: T96261

Differential Revision: https://developer.blender.org/D14452
This commit is contained in:
Jason Fielder 2022-03-30 19:47:59 +02:00 committed by Clément Foucault
parent 7c9e128bbf
commit 49bc640b76
Notes: blender-bot 2023-02-14 10:18:56 +01:00
Referenced by issue #96261, Metal Viewport
12 changed files with 37 additions and 37 deletions

View File

@ -204,7 +204,7 @@ void EEVEE_lightbake_cache_init(EEVEE_ViewLayerData *sldata,
DRW_shgroup_uniform_float(grp, "intensityFac", &pinfo->intensity_fac, 1);
DRW_shgroup_uniform_float(grp, "sampleCount", &pinfo->samples_len, 1);
DRW_shgroup_uniform_float(grp, "roughness", &pinfo->roughness, 1);
DRW_shgroup_uniform_float(grp, "probe_roughness", &pinfo->roughness, 1);
DRW_shgroup_uniform_float(grp, "lodFactor", &pinfo->lodfactor, 1);
DRW_shgroup_uniform_float(grp, "lodMax", &pinfo->lod_rt_max, 1);
DRW_shgroup_uniform_float(grp, "texelSize", &pinfo->texel_size, 1);

View File

@ -4,7 +4,7 @@
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
uniform samplerCube probeHdr;
uniform float roughness;
uniform float probe_roughness;
uniform float texelSize;
uniform float lodFactor;
uniform float lodMax;
@ -51,7 +51,7 @@ void main()
float pdf;
/* Microfacet normal */
vec3 H = sample_ggx(Xi, roughness, V, N, T, B, pdf);
vec3 H = sample_ggx(Xi, probe_roughness, V, N, T, B, pdf);
vec3 L = -reflect(V, H);
float NL = dot(N, L);

View File

@ -74,7 +74,7 @@ GPU_SHADER_INTERFACE_INFO(workbench_material_iface, "")
.smooth(Type::FLOAT, "alpha_interp")
.smooth(Type::VEC2, "uv_interp")
.flat(Type::INT, "object_id")
.flat(Type::FLOAT, "roughness")
.flat(Type::FLOAT, "_roughness")
.flat(Type::FLOAT, "metallic");
GPU_SHADER_CREATE_INFO(workbench_material)

View File

@ -7,7 +7,7 @@ void main()
{
normalData = workbench_normal_encode(gl_FrontFacing, normal_interp);
materialData = vec4(color_interp, workbench_float_pair_encode(roughness, metallic));
materialData = vec4(color_interp, workbench_float_pair_encode(_roughness, metallic));
objectId = uint(object_id);

View File

@ -66,7 +66,7 @@ void main()
normal_interp = normalize(normal_world_to_view(nor));
workbench_material_data_get(resource_handle, color_interp, alpha_interp, roughness, metallic);
workbench_material_data_get(resource_handle, color_interp, alpha_interp, _roughness, metallic);
if (materialIndex == 0) {
color_interp = hair_get_customdata_vec3(ac);
@ -76,7 +76,7 @@ void main()
* So we lower their alpha artificially. */
alpha_interp *= 0.3;
workbench_hair_random_material(hair_rand, color_interp, roughness, metallic);
workbench_hair_random_material(hair_rand, color_interp, _roughness, metallic);
object_id = int(uint(resource_handle) & 0xFFFFu) + 1;
}

View File

@ -19,7 +19,7 @@ void main()
uv_interp = vec2(0.0);
workbench_material_data_get(resource_handle, color_interp, alpha_interp, roughness, metallic);
workbench_material_data_get(resource_handle, color_interp, alpha_interp, _roughness, metallic);
if (materialIndex == 0) {
color_interp = vec3(1.0);

View File

@ -16,7 +16,7 @@ void main()
normal_interp = normalize(normal_object_to_view(nor));
workbench_material_data_get(resource_handle, color_interp, alpha_interp, roughness, metallic);
workbench_material_data_get(resource_handle, color_interp, alpha_interp, _roughness, metallic);
if (materialIndex == 0) {
color_interp = ac.rgb;

View File

@ -62,7 +62,7 @@ void main()
#endif
#ifdef V3D_LIGHTING_STUDIO
vec3 shaded_color = get_world_lighting(color, roughness, metallic, N, I);
vec3 shaded_color = get_world_lighting(color, _roughness, metallic, N, I);
#endif
#ifdef V3D_LIGHTING_FLAT

View File

@ -12,19 +12,19 @@ vec4 texture_read_as_linearrgb(sampler2D tex, bool premultiplied, vec2 co)
{
/* By convention image textures return scene linear colors, but
* overlays still assume srgb. */
vec4 color = texture(tex, co);
vec4 col = texture(tex, co);
/* Unpremultiply if stored multiplied, since straight alpha is expected by shaders. */
if (premultiplied && !(color.a == 0.0 || color.a == 1.0)) {
color.rgb = color.rgb / color.a;
if (premultiplied && !(col.a == 0.0 || col.a == 1.0)) {
col.rgb = col.rgb / col.a;
}
return color;
return col;
}
vec4 texture_read_as_srgb(sampler2D tex, bool premultiplied, vec2 co)
{
vec4 color = texture_read_as_linearrgb(tex, premultiplied, co);
color.r = linearrgb_to_srgb(color.r);
color.g = linearrgb_to_srgb(color.g);
color.b = linearrgb_to_srgb(color.b);
return color;
vec4 col = texture_read_as_linearrgb(tex, premultiplied, co);
col.r = linearrgb_to_srgb(col.r);
col.g = linearrgb_to_srgb(col.g);
col.b = linearrgb_to_srgb(col.b);
return col;
}

View File

@ -6,13 +6,13 @@
void view_clipping_distances(vec3 wpos)
{
# ifdef USE_WORLD_CLIP_PLANES
vec4 pos = vec4(wpos, 1.0);
gl_ClipDistance[0] = dot(drw_view.clip_planes[0], pos);
gl_ClipDistance[1] = dot(drw_view.clip_planes[1], pos);
gl_ClipDistance[2] = dot(drw_view.clip_planes[2], pos);
gl_ClipDistance[3] = dot(drw_view.clip_planes[3], pos);
gl_ClipDistance[4] = dot(drw_view.clip_planes[4], pos);
gl_ClipDistance[5] = dot(drw_view.clip_planes[5], pos);
vec4 pos_4d = vec4(wpos, 1.0);
gl_ClipDistance[0] = dot(drw_view.clip_planes[0], pos_4d);
gl_ClipDistance[1] = dot(drw_view.clip_planes[1], pos_4d);
gl_ClipDistance[2] = dot(drw_view.clip_planes[2], pos_4d);
gl_ClipDistance[3] = dot(drw_view.clip_planes[3], pos_4d);
gl_ClipDistance[4] = dot(drw_view.clip_planes[4], pos_4d);
gl_ClipDistance[5] = dot(drw_view.clip_planes[5], pos_4d);
# endif
}

View File

@ -7,13 +7,13 @@ uniform vec4 WorldClipPlanes[6];
# define _world_clip_planes_calc_clip_distance(wpos, _clipplanes) \
{ \
vec4 pos = vec4(wpos, 1.0); \
gl_ClipDistance[0] = dot(_clipplanes[0], pos); \
gl_ClipDistance[1] = dot(_clipplanes[1], pos); \
gl_ClipDistance[2] = dot(_clipplanes[2], pos); \
gl_ClipDistance[3] = dot(_clipplanes[3], pos); \
gl_ClipDistance[4] = dot(_clipplanes[4], pos); \
gl_ClipDistance[5] = dot(_clipplanes[5], pos); \
vec4 _pos = vec4(wpos, 1.0); \
gl_ClipDistance[0] = dot(_clipplanes[0], _pos); \
gl_ClipDistance[1] = dot(_clipplanes[1], _pos); \
gl_ClipDistance[2] = dot(_clipplanes[2], _pos); \
gl_ClipDistance[3] = dot(_clipplanes[3], _pos); \
gl_ClipDistance[4] = dot(_clipplanes[4], _pos); \
gl_ClipDistance[5] = dot(_clipplanes[5], _pos); \
}
/* When all shaders are builtin shaders are migrated this could be applied directly. */

View File

@ -6,13 +6,13 @@
uniform bool srgbTarget = false;
#endif
vec4 blender_srgb_to_framebuffer_space(vec4 col)
vec4 blender_srgb_to_framebuffer_space(vec4 in_color)
{
if (srgbTarget) {
vec3 c = max(col.rgb, vec3(0.0));
vec3 c = max(in_color.rgb, vec3(0.0));
vec3 c1 = c * (1.0 / 12.92);
vec3 c2 = pow((c + 0.055) * (1.0 / 1.055), vec3(2.4));
col.rgb = mix(c1, c2, step(vec3(0.04045), c));
in_color.rgb = mix(c1, c2, step(vec3(0.04045), c));
}
return col;
return in_color;
}