Metal: MTLShader and MTLShaderGenerator implementation.
Full support for translation and compilation of shaders in Metal, using GPUShaderCreateInfo. Includes render pipeline state creation and management, enabling all standard GPU viewport rendering features in Metal. Authored by Apple: Michael Parkin-White, Marco Giordano Ref T96261 Reviewed By: fclem Maniphest Tasks: T96261 Differential Revision: https://developer.blender.org/D15563
This commit is contained in:
@@ -74,7 +74,7 @@ template<> uchar convert_type<uchar>(float val)
|
||||
|
||||
template<> uint convert_type<uint>(float val)
|
||||
{
|
||||
return uint(val * double(0xFFFFFFFFu));
|
||||
return uint(val * float(0xFFFFFFFFu));
|
||||
}
|
||||
|
||||
struct TextureReadParams {
|
||||
|
||||
@@ -38,22 +38,6 @@ using namespace metal;
|
||||
# define POSITION_TYPE uint3
|
||||
#endif
|
||||
|
||||
float3 mtl_linear_to_srgb_attr(float3 c)
|
||||
{
|
||||
c = max(c, float3(0.0));
|
||||
float3 c1 = c * 12.92;
|
||||
float3 c2 = 1.055 * pow(c, float3(1.0 / 2.4)) - 0.055;
|
||||
return mix(c1, c2, step(float3(0.0031308), c));
|
||||
}
|
||||
|
||||
float3 mtl_srgb_to_linear_attr(float3 c)
|
||||
{
|
||||
c = max(c, float3(0.0));
|
||||
float3 c1 = c * (1.0 / 12.92);
|
||||
float3 c2 = pow((c + 0.055) * (1.0 / 1.055), float3(2.4));
|
||||
return mix(c1, c2, step(float3(0.04045), c));
|
||||
}
|
||||
|
||||
struct TextureUpdateParams {
|
||||
int mip_index;
|
||||
int extent[3];
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
|
||||
uniform sampler2D source_data;
|
||||
uniform int mip;
|
||||
|
||||
in vec2 texCoord_interp;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragDepth = textureLod(source_data, texCoord_interp, mip).r;
|
||||
|
||||
35
source/blender/gpu/metal/kernels/depth_2d_update_info.hh
Normal file
35
source/blender/gpu/metal/kernels/depth_2d_update_info.hh
Normal file
@@ -0,0 +1,35 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup gpu
|
||||
*/
|
||||
|
||||
#include "gpu_shader_create_info.hh"
|
||||
|
||||
GPU_SHADER_INTERFACE_INFO(depth_2d_update_iface, "").smooth(Type::VEC2, "texCoord_interp");
|
||||
|
||||
GPU_SHADER_CREATE_INFO(depth_2d_update_info_base)
|
||||
.vertex_in(0, Type::VEC2, "pos")
|
||||
.vertex_out(depth_2d_update_iface)
|
||||
.fragment_out(0, Type::VEC4, "fragColor")
|
||||
.push_constant(Type::VEC2, "extent")
|
||||
.push_constant(Type::VEC2, "offset")
|
||||
.push_constant(Type::VEC2, "size")
|
||||
.push_constant(Type::INT, "mip")
|
||||
.sampler(0, ImageType::FLOAT_2D, "source_data", Frequency::PASS)
|
||||
.vertex_source("depth_2d_update_vert.glsl");
|
||||
|
||||
GPU_SHADER_CREATE_INFO(depth_2d_update_float)
|
||||
.fragment_source("depth_2d_update_float_frag.glsl")
|
||||
.additional_info("depth_2d_update_info_base")
|
||||
.do_static_compilation(true);
|
||||
|
||||
GPU_SHADER_CREATE_INFO(depth_2d_update_int24)
|
||||
.fragment_source("depth_2d_update_int24_frag.glsl")
|
||||
.additional_info("depth_2d_update_info_base")
|
||||
.do_static_compilation(true);
|
||||
|
||||
GPU_SHADER_CREATE_INFO(depth_2d_update_int32)
|
||||
.fragment_source("depth_2d_update_int32_frag.glsl")
|
||||
.additional_info("depth_2d_update_info_base")
|
||||
.do_static_compilation(true);
|
||||
@@ -1,8 +1,4 @@
|
||||
|
||||
uniform isampler2D source_data;
|
||||
uniform int mip;
|
||||
|
||||
in vec2 texCoord_interp;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
|
||||
uniform isampler2D source_data;
|
||||
uniform int mip;
|
||||
|
||||
in vec2 texCoord_interp;
|
||||
|
||||
void main()
|
||||
{
|
||||
uint val = textureLod(source_data, texCoord_interp, mip).r;
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
|
||||
uniform vec2 extent;
|
||||
uniform vec2 offset;
|
||||
uniform vec2 size;
|
||||
out vec2 texCoord_interp;
|
||||
in vec2 pos;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 rect = vec4(offset.x, offset.y, offset.x + extent.x, offset.y + extent.y);
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
|
||||
|
||||
in vec4 uvcoordsvar;
|
||||
uniform sampler2D imageTexture;
|
||||
uniform int mip;
|
||||
out vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tex_color = textureLod(imageTexture, uvcoordsvar.xy, mip);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup gpu
|
||||
*/
|
||||
|
||||
#include "gpu_shader_create_info.hh"
|
||||
|
||||
GPU_SHADER_INTERFACE_INFO(fullscreen_blit_iface, "").smooth(Type::VEC4, "uvcoordsvar");
|
||||
|
||||
GPU_SHADER_CREATE_INFO(fullscreen_blit)
|
||||
.vertex_in(0, Type::VEC2, "pos")
|
||||
.vertex_out(fullscreen_blit_iface)
|
||||
.fragment_out(0, Type::VEC4, "fragColor")
|
||||
.push_constant(Type::VEC2, "fullscreen")
|
||||
.push_constant(Type::VEC2, "size")
|
||||
.push_constant(Type::VEC2, "dst_offset")
|
||||
.push_constant(Type::VEC2, "src_offset")
|
||||
.push_constant(Type::INT, "mip")
|
||||
.sampler(0, ImageType::FLOAT_2D, "imageTexture", Frequency::PASS)
|
||||
.vertex_source("gpu_shader_fullscreen_blit_vert.glsl")
|
||||
.fragment_source("gpu_shader_fullscreen_blit_frag.glsl")
|
||||
.do_static_compilation(true);
|
||||
@@ -1,12 +1,4 @@
|
||||
|
||||
out vec4 uvcoordsvar;
|
||||
|
||||
in vec2 pos;
|
||||
uniform vec2 fullscreen;
|
||||
uniform vec2 size;
|
||||
uniform vec2 dst_offset;
|
||||
uniform vec2 src_offset;
|
||||
|
||||
void main()
|
||||
{
|
||||
/* The position represents a 0-1 square, we first scale it by the size we want to have it on
|
||||
|
||||
Reference in New Issue
Block a user