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:
authorJason Fielder <jason_apple>2022-03-22 14:44:26 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-03-22 14:54:44 +0300
commit19c793af35ea8e694c16995d115d7c9247fee81a (patch)
treec24ad1eead6cb91cbc6260a10e8cf13dc13db903 /source/blender/gpu
parent309ea314858a9b7892ea2c8a6fe55ab2a1028697 (diff)
Metal: Make GLSL shader source MSL compliant also
Metal shading language follows the C++ 14 standard and in some cases requires a greater level of explicitness than GLSL. There are also some small language differences: - Explicit type-casts (C++ requirements) - Explicit constant values (C++ requirements, e.g. floating point values using 0.0 instead of 0). - Metal/OpenGL compatibility paths - GLSL Function prototypes - Explicit accessors for vector types when sampling textures. Authored by Apple: Michael Parkin-White Ref T96261 Reviewed By: fclem Maniphest Tasks: T96261 Differential Revision: https://developer.blender.org/D14378
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/CMakeLists.txt1
-rw-r--r--source/blender/gpu/intern/gpu_shader.cc10
-rw-r--r--source/blender/gpu/opengl/gl_shader.cc7
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl27
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl2
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_keyframe_shape_vert.glsl2
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_frag.glsl4
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_vert.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_light_falloff.glsl4
-rw-r--r--source/blender/gpu/shaders/opengl/glsl_shader_defines.glsl17
12 files changed, 74 insertions, 14 deletions
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 6c795aba560..c28b51de8ac 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -210,6 +210,7 @@ endif()
set(GLSL_SRC
GPU_shader_shared.h
+ shaders/opengl/glsl_shader_defines.glsl
shaders/gpu_shader_depth_only_frag.glsl
shaders/gpu_shader_uniform_color_frag.glsl
diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc
index ac8e98a4a21..b434cfbbb0e 100644
--- a/source/blender/gpu/intern/gpu_shader.cc
+++ b/source/blender/gpu/intern/gpu_shader.cc
@@ -88,6 +88,16 @@ static void standard_defines(Vector<const char *> &sources)
else if (GPU_type_matches(GPU_DEVICE_ANY, GPU_OS_UNIX, GPU_DRIVER_ANY)) {
sources.append("#define OS_UNIX\n");
}
+ /* API Definition */
+ eGPUBackendType backend = GPU_backend_get_type();
+ switch (backend) {
+ case GPU_BACKEND_OPENGL:
+ sources.append("#define GPU_OPENGL\n");
+ break;
+ default:
+ BLI_assert(false && "Invalid GPU Backend Type");
+ break;
+ }
if (GPU_crappy_amd_driver()) {
sources.append("#define GPU_DEPRECATED_AMD_DRIVER\n");
diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc
index c0182306047..c76e21f9f71 100644
--- a/source/blender/gpu/opengl/gl_shader.cc
+++ b/source/blender/gpu/opengl/gl_shader.cc
@@ -24,6 +24,8 @@ using namespace blender;
using namespace blender::gpu;
using namespace blender::gpu::shader;
+extern char datatoc_glsl_shader_defines_glsl[];
+
/* -------------------------------------------------------------------- */
/** \name Creation / Destruction
* \{ */
@@ -760,7 +762,7 @@ bool GLShader::do_geometry_shader_injection(const shader::ShaderCreateInfo *info
static char *glsl_patch_default_get()
{
/** Used for shader patching. Init once. */
- static char patch[1024] = "\0";
+ static char patch[2048] = "\0";
if (patch[0] != '\0') {
return patch;
}
@@ -827,6 +829,9 @@ static char *glsl_patch_default_get()
STR_CONCATF(patch, slen, "#define DFDX_SIGN %1.1f\n", GLContext::derivative_signs[0]);
STR_CONCATF(patch, slen, "#define DFDY_SIGN %1.1f\n", GLContext::derivative_signs[1]);
+ /* GLSL Backend Lib. */
+ STR_CONCAT(patch, slen, datatoc_glsl_shader_defines_glsl);
+
BLI_assert(slen < sizeof(patch));
return patch;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl
index 9851e08fe2e..353bf1481da 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl
@@ -23,15 +23,15 @@ void main()
/* Use pos to select the right swizzle (instead of gl_VertexID)
* in order to workaround an OSX driver bug. */
- if (pos == vec2(0.0, 0.0)) {
+ if (all(equal(pos, vec2(0.0, 0.0)))) {
rect.xy = rect.xz;
tex.xy = tex.xz;
}
- else if (pos == vec2(0.0, 1.0)) {
+ else if (all(equal(pos, vec2(0.0, 1.0)))) {
rect.xy = rect.xw;
tex.xy = tex.xw;
}
- else if (pos == vec2(1.0, 1.0)) {
+ else if (all(equal(pos, vec2(1.0, 1.0)))) {
rect.xy = rect.yw;
tex.xy = tex.yw;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl
index d9a5aeeef46..903c602c5d6 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl
@@ -15,6 +15,32 @@ void main()
{
vec2 uv;
vec2 co;
+
+#ifdef GPU_METAL
+/* Metal API does not support Triangle fan primitive topology.
+ * When this shader is called using Triangle-Strip, vertex ID's
+ * are in a different order. */
+# define GPU_PRIM_TRI_STRIP
+#endif
+
+#ifdef GPU_PRIM_TRI_STRIP
+ if (gl_VertexID == 0) {
+ co = rect_geom.xw;
+ uv = rect_icon.xw;
+ }
+ else if (gl_VertexID == 1) {
+ co = rect_geom.xy;
+ uv = rect_icon.xy;
+ }
+ else if (gl_VertexID == 2) {
+ co = rect_geom.zw;
+ uv = rect_icon.zw;
+ }
+ else {
+ co = rect_geom.zy;
+ uv = rect_icon.zy;
+ }
+#else
if (gl_VertexID == 0) {
co = rect_geom.xy;
uv = rect_icon.xy;
@@ -31,6 +57,7 @@ void main()
co = rect_geom.zy;
uv = rect_icon.zy;
}
+#endif
gl_Position = ModelViewProjectionMatrix * vec4(co, 0.0f, 1.0f);
texCoord_interp = uv;
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl
index 80b93baf20a..3a39cd8b847 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl
@@ -53,7 +53,7 @@ flat out float lineWidth;
noperspective out float butCo;
flat out float discardFac;
-# ifdef OS_MAC
+# if defined(OS_MAC) && defined(GPU_OPENGL)
in float dummy;
# endif
#endif
diff --git a/source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl
index 2314dbbc5d5..aa182eb52be 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl
@@ -32,9 +32,9 @@ void linearrgb_to_srgb(vec4 col_from, out vec4 col_to)
void main()
{
- fragColor = texture(image_texture, texCoord_interp.st);
- vec4 overlay_col = texture(overlays_texture, texCoord_interp.st);
-
+ fragColor = texture(image_texture, texCoord_interp.xy);
+ vec4 overlay_col = texture(overlays_texture, texCoord_interp.xy);
+
if (overlay) {
fragColor = clamp(fragColor, 0.0, 1.0);
fragColor *= 1.0 - overlay_col.a;
diff --git a/source/blender/gpu/shaders/gpu_shader_keyframe_shape_vert.glsl b/source/blender/gpu/shaders/gpu_shader_keyframe_shape_vert.glsl
index 4ef3ff1a8d0..617c02ac079 100644
--- a/source/blender/gpu/shaders/gpu_shader_keyframe_shape_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_keyframe_shape_vert.glsl
@@ -43,7 +43,7 @@ bool test(int bit)
vec2 line_thresholds(float width)
{
- return vec2(max(0, width - line_falloff), width);
+ return vec2(max(0.0, width - line_falloff), width);
}
void main()
diff --git a/source/blender/gpu/shaders/gpu_shader_text_frag.glsl b/source/blender/gpu/shaders/gpu_shader_text_frag.glsl
index c339d3cbabb..f958a81b1eb 100644
--- a/source/blender/gpu/shaders/gpu_shader_text_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_text_frag.glsl
@@ -52,7 +52,7 @@ bool is_inside_box(ivec2 v)
float texture_1D_custom_bilinear_filter(vec2 uv)
{
- vec2 texel_2d = uv * glyph_dim + 0.5;
+ vec2 texel_2d = uv * vec2(glyph_dim) + vec2(0.5);
ivec2 texel_2d_near = ivec2(texel_2d) - 1;
int frag_offset = glyph_offset + texel_2d_near.y * glyph_dim.x + texel_2d_near.x;
@@ -100,7 +100,7 @@ void main()
fragColor.a = texture_1D_custom_bilinear_filter(texCoord_interp);
}
else {
- vec2 texel = 1.0 / glyph_dim;
+ vec2 texel = 1.0 / vec2(glyph_dim);
fragColor.a = 0.0;
if (interp_size == 1) {
diff --git a/source/blender/gpu/shaders/gpu_shader_text_vert.glsl b/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
index 5b01fea5266..4221e426a3e 100644
--- a/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
@@ -29,7 +29,7 @@ void main()
texCoord_interp = mix(-interp_offset, 1.0 + interp_offset, quad);
vec2 final_pos = mix(
- pos.xy + ivec2(-interp_size, interp_size), pos.zw + ivec2(interp_size, -interp_size), quad);
+ vec2(ivec2(pos.xy) + ivec2(-interp_size, interp_size)), vec2(ivec2(pos.zw) + ivec2(interp_size, -interp_size)), quad);
gl_Position = ModelViewProjectionMatrix * vec4(final_pos, 0.0, 1.0);
}
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_light_falloff.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_light_falloff.glsl
index f3eae653f95..e1c7a00646f 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_light_falloff.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_light_falloff.glsl
@@ -1,7 +1,7 @@
void node_light_falloff(
- float strength, float tsmooth, out float quadratic, out float linear, out float constant)
+ float strength, float tsmooth, out float quadratic, out float linear, out float falloff_constant)
{
quadratic = strength;
linear = strength;
- constant = strength;
+ falloff_constant = strength;
}
diff --git a/source/blender/gpu/shaders/opengl/glsl_shader_defines.glsl b/source/blender/gpu/shaders/opengl/glsl_shader_defines.glsl
new file mode 100644
index 00000000000..a5fce2e71c3
--- /dev/null
+++ b/source/blender/gpu/shaders/opengl/glsl_shader_defines.glsl
@@ -0,0 +1,17 @@
+/* Backend Functions. */
+#define select(A, B, mask) mix(A, B, mask)
+
+bool is_zero(vec2 A)
+{
+ return all(equal(A, vec2(0.0)));
+}
+
+bool is_zero(vec3 A)
+{
+ return all(equal(A, vec3(0.0)));
+}
+
+bool is_zero(vec4 A)
+{
+ return all(equal(A, vec4(0.0)));
+}