Metal: GLSL Compatibility - explicit mat4_to_mat3 conversion

Explicit constructor for mat3 from a mat4 is not valid and cannot be overloaded.

Adding explicit texture resource type flags for depth textures. This is an explicit requirement for Metal Shading language. This is a temporary compatibility, as this path is already supported in GPU_SHADER_CREATE_INFO under ImageType::DEPTH_2D, though required in shader source for MSL shaders which do not have create info.

Authored by Apple: Michael Parkin-White

Ref T96261

Reviewed By: fclem

Maniphest Tasks: T96261

Differential Revision: https://developer.blender.org/D14418
This commit is contained in:
Jason Fielder 2022-03-30 19:37:29 +02:00 committed by Clément Foucault
parent 60a6fbf5b5
commit 7c9e128bbf
Notes: blender-bot 2023-02-14 03:46:57 +01:00
Referenced by issue #97545, EEVEE Viewport Shading crash (3.2.0 Alpha)
Referenced by issue #96261, Metal Viewport
13 changed files with 30 additions and 20 deletions

View File

@ -4,7 +4,7 @@
/* Convert depth to Mist factor */
uniform vec3 mistSettings;
uniform sampler2D depthBuffer;
uniform depth2D depthBuffer;
#define mistStart mistSettings.x
#define mistInvDistance mistSettings.y

View File

@ -11,7 +11,7 @@
* by Jorge Jimenez
*/
uniform sampler2D colorBuffer;
uniform sampler2D depthBuffer;
uniform depth2D depthBuffer;
uniform sampler2D velocityBuffer;
uniform sampler2D tileMaxBuffer;

View File

@ -9,7 +9,7 @@
#define MAX_SSS_SAMPLES 65
layout(std140) uniform sssProfile
{
vec4 kernel[MAX_SSS_SAMPLES];
vec4 sss_kernel[MAX_SSS_SAMPLES];
vec4 radii_max_radius;
int sss_samples;
};
@ -48,11 +48,11 @@ void main(void)
float sss_radius_inv = 1.0 / max(1e-8, sss_radius);
/* Center sample */
vec3 accum = sss_irradiance * kernel[0].rgb;
vec3 accum = sss_irradiance * sss_kernel[0].rgb;
for (int i = 1; i < sss_samples && i < MAX_SSS_SAMPLES; i++) {
vec2 sample_uv = uvs + kernel[i].a * finalStep *
((abs(kernel[i].a) > sssJitterThreshold) ? dir : dir_rand);
vec2 sample_uv = uvs + sss_kernel[i].a * finalStep *
((abs(sss_kernel[i].a) > sssJitterThreshold) ? dir : dir_rand);
vec3 color = texture(sssIrradiance, sample_uv).rgb;
float sample_depth = texture(depthBuffer, sample_uv).r;
sample_depth = get_view_z_from_depth(sample_depth);
@ -66,8 +66,8 @@ void main(void)
if (any(lessThan(sample_uv, vec2(0.0))) || any(greaterThan(sample_uv, vec2(1.0)))) {
s = 0.0;
}
/* Mix with first sample in failure case and apply kernel color. */
accum += kernel[i].rgb * mix(sss_irradiance, color, s);
/* Mix with first sample in failure case and apply sss_kernel color. */
accum += sss_kernel[i].rgb * mix(sss_irradiance, color, s);
}
#if defined(FIRST_PASS)

View File

@ -3,7 +3,7 @@
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
uniform sampler2D colorBuffer;
uniform sampler2D depthBuffer;
uniform depth2D depthBuffer;
uniform sampler2D colorHistoryBuffer;
uniform mat4 prevViewProjectionMatrix;

View File

@ -8,7 +8,7 @@ in vec4 uvcoordsvar;
out vec4 FragColor;
uniform sampler2D depthBuffer;
uniform depth2D depthBuffer;
uniform sampler1D sssTexProfile;
uniform sampler2D sssRadius;
uniform sampler2DArray sssShadowCubes;
@ -21,7 +21,7 @@ uniform sampler2DArray sssShadowCascades;
layout(std140) uniform sssProfile
{
vec4 kernel[MAX_SSS_SAMPLES];
vec4 sss_kernel[MAX_SSS_SAMPLES];
vec4 radii_max_radius;
int sss_samples;
};

View File

@ -1,7 +1,7 @@
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
uniform sampler2D depthBuffer;
uniform depth2D depthBuffer;
uniform mat4 prevViewProjMatrix;
uniform mat4 currViewProjMatrixInv;

View File

@ -89,8 +89,8 @@ layout(std140) uniform light_block
LightData lights_data[MAX_LIGHT];
};
uniform sampler2DArrayShadow shadowCubeTexture;
uniform sampler2DArrayShadow shadowCascadeTexture;
uniform depth2DArrayShadow shadowCubeTexture;
uniform depth2DArrayShadow shadowCascadeTexture;
/** \} */

View File

@ -16,7 +16,7 @@
uniform int postProcessType;
uniform int currentSample;
uniform sampler2D depthBuffer;
uniform depth2D depthBuffer;
uniform sampler2D inputBuffer;
uniform sampler2D inputSecondLightBuffer;
uniform sampler2D inputColorBuffer;

View File

@ -3,7 +3,7 @@
#pragma BLENDER_REQUIRE(common_utiltex_lib.glsl)
#pragma BLENDER_REQUIRE(lights_lib.glsl)
uniform sampler2D depthBuffer;
uniform depth2D depthBuffer;
out vec4 fragColor;

View File

@ -2,7 +2,7 @@
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
uniform sampler2D colorTex;
uniform sampler2D depthTex;
uniform depth2D depthTex;
uniform sampler2D lineTex;
uniform bool doSmoothLines;

View File

@ -1,5 +1,5 @@
uniform sampler2D depthBuffer;
uniform depth2D depthBuffer;
uniform vec4 gridModelMatrix[4];
uniform bool isTransform;

View File

@ -12,7 +12,7 @@ uniform vec3 planeAxes;
uniform float gridDistance;
uniform vec3 gridSize;
uniform float lineKernel = 0.0;
uniform sampler2D depthBuffer;
uniform depth2D depthBuffer;
uniform int gridFlag;
uniform float zoomFactor;
@ -49,7 +49,7 @@ float get_grid(vec2 co, vec2 fwidthCos, float grid_size)
{
float half_size = grid_size / 2.0;
/* triangular wave pattern, amplitude is [0, half_size] */
vec2 grid_domain = abs(mod(co + half_size, grid_size) - half_size);
vec2 grid_domain = abs(mod(co + half_size, vec2(grid_size)) - half_size);
/* modulate by the absolute rate of change of the coordinates
* (make lines have the same width under perspective) */
grid_domain /= fwidthCos;

View File

@ -1,3 +1,13 @@
/* Texture format tokens -- Type explictness required by other Graphics APIs. */
#define depth2D sampler2D
#define depth2DArray sampler2DArray
#define depth2DMS sampler2DMS
#define depth2DMSArray sampler2DMSArray
#define depthCube samplerCube
#define depthCubeArray samplerCubeArray
#define depth2DArrayShadow sampler2DArrayShadow
/* Backend Functions. */
#define select(A, B, mask) mix(A, B, mask)