2016-04-21 09:16:44 +02:00
|
|
|
#include <metal_texture>
|
2017-12-31 01:32:22 +01:00
|
|
|
#include <metal_matrix>
|
2016-04-21 09:16:44 +02:00
|
|
|
|
|
|
|
using namespace metal;
|
|
|
|
|
2017-12-31 01:32:22 +01:00
|
|
|
struct SolidVertexOutput
|
2016-04-21 09:16:44 +02:00
|
|
|
{
|
2018-01-01 02:06:16 +01:00
|
|
|
float4 position [[position]];
|
|
|
|
float pointSize [[point_size]];
|
2017-12-09 21:58:41 +01:00
|
|
|
};
|
|
|
|
|
2017-12-31 01:32:22 +01:00
|
|
|
vertex SolidVertexOutput SDL_Solid_vertex(const device float2 *position [[buffer(0)]],
|
|
|
|
constant float4x4 &projection [[buffer(2)]],
|
2018-01-03 05:43:01 +01:00
|
|
|
constant float4x4 &transform [[buffer(3)]],
|
2017-12-31 01:32:22 +01:00
|
|
|
uint vid [[vertex_id]])
|
2017-12-09 21:58:41 +01:00
|
|
|
{
|
2017-12-31 01:32:22 +01:00
|
|
|
SolidVertexOutput v;
|
2018-01-03 05:43:01 +01:00
|
|
|
v.position = (projection * transform) * float4(position[vid], 0.0f, 1.0f);
|
2018-01-06 23:54:12 +01:00
|
|
|
v.pointSize = 1.0f;
|
2018-01-01 02:06:16 +01:00
|
|
|
return v;
|
2016-04-21 09:16:44 +02:00
|
|
|
}
|
2018-01-01 02:06:16 +01:00
|
|
|
|
2017-12-09 21:58:41 +01:00
|
|
|
fragment float4 SDL_Solid_fragment(constant float4 &col [[buffer(0)]])
|
2016-04-21 09:16:44 +02:00
|
|
|
{
|
|
|
|
return col;
|
|
|
|
}
|
|
|
|
|
2017-12-31 01:32:22 +01:00
|
|
|
struct CopyVertexOutput
|
2016-04-21 09:16:44 +02:00
|
|
|
{
|
|
|
|
float4 position [[position]];
|
|
|
|
float2 texcoord;
|
|
|
|
};
|
|
|
|
|
2017-12-31 01:32:22 +01:00
|
|
|
vertex CopyVertexOutput SDL_Copy_vertex(const device float2 *position [[buffer(0)]],
|
|
|
|
const device float2 *texcoords [[buffer(1)]],
|
|
|
|
constant float4x4 &projection [[buffer(2)]],
|
2018-01-01 02:06:16 +01:00
|
|
|
constant float4x4 &transform [[buffer(3)]],
|
2017-12-31 01:32:22 +01:00
|
|
|
uint vid [[vertex_id]])
|
2016-04-21 09:16:44 +02:00
|
|
|
{
|
2017-12-31 01:32:22 +01:00
|
|
|
CopyVertexOutput v;
|
2018-01-01 02:06:16 +01:00
|
|
|
v.position = (projection * transform) * float4(position[vid], 0.0f, 1.0f);
|
2017-12-09 21:58:41 +01:00
|
|
|
v.texcoord = texcoords[vid];
|
|
|
|
return v;
|
2016-04-21 09:16:44 +02:00
|
|
|
}
|
|
|
|
|
2018-01-02 00:37:16 +01:00
|
|
|
fragment float4 SDL_Copy_fragment(CopyVertexOutput vert [[stage_in]],
|
|
|
|
constant float4 &col [[buffer(0)]],
|
|
|
|
texture2d<float> tex [[texture(0)]],
|
|
|
|
sampler s [[sampler(0)]])
|
2016-04-21 09:16:44 +02:00
|
|
|
{
|
2017-12-10 00:00:41 +01:00
|
|
|
return tex.sample(s, vert.texcoord) * col;
|
|
|
|
}
|
2018-01-06 23:54:12 +01:00
|
|
|
|
|
|
|
struct YUVDecode
|
|
|
|
{
|
|
|
|
float3 offset;
|
|
|
|
float3 Rcoeff;
|
|
|
|
float3 Gcoeff;
|
|
|
|
float3 Bcoeff;
|
|
|
|
};
|
|
|
|
|
|
|
|
fragment float4 SDL_YUV_fragment(CopyVertexOutput vert [[stage_in]],
|
|
|
|
constant float4 &col [[buffer(0)]],
|
|
|
|
constant YUVDecode &decode [[buffer(1)]],
|
|
|
|
texture2d<float> texY [[texture(0)]],
|
|
|
|
texture2d_array<float> texUV [[texture(1)]],
|
|
|
|
sampler s [[sampler(0)]])
|
|
|
|
{
|
|
|
|
float3 yuv;
|
|
|
|
yuv.x = texY.sample(s, vert.texcoord).r;
|
|
|
|
yuv.y = texUV.sample(s, vert.texcoord, 0).r;
|
|
|
|
yuv.z = texUV.sample(s, vert.texcoord, 1).r;
|
|
|
|
|
|
|
|
yuv += decode.offset;
|
|
|
|
|
|
|
|
return col * float4(dot(yuv, decode.Rcoeff), dot(yuv, decode.Gcoeff), dot(yuv, decode.Bcoeff), 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
fragment float4 SDL_NV12_fragment(CopyVertexOutput vert [[stage_in]],
|
|
|
|
constant float4 &col [[buffer(0)]],
|
|
|
|
constant YUVDecode &decode [[buffer(1)]],
|
|
|
|
texture2d<float> texY [[texture(0)]],
|
|
|
|
texture2d<float> texUV [[texture(1)]],
|
|
|
|
sampler s [[sampler(0)]])
|
|
|
|
{
|
|
|
|
float3 yuv;
|
|
|
|
yuv.x = texY.sample(s, vert.texcoord).r;
|
|
|
|
yuv.yz = texUV.sample(s, vert.texcoord).rg;
|
|
|
|
|
|
|
|
yuv += decode.offset;
|
|
|
|
|
|
|
|
return col * float4(dot(yuv, decode.Rcoeff), dot(yuv, decode.Gcoeff), dot(yuv, decode.Bcoeff), 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
fragment float4 SDL_NV21_fragment(CopyVertexOutput vert [[stage_in]],
|
|
|
|
constant float4 &col [[buffer(0)]],
|
|
|
|
constant YUVDecode &decode [[buffer(1)]],
|
|
|
|
texture2d<float> texY [[texture(0)]],
|
|
|
|
texture2d<float> texUV [[texture(1)]],
|
|
|
|
sampler s [[sampler(0)]])
|
|
|
|
{
|
|
|
|
float3 yuv;
|
|
|
|
yuv.x = texY.sample(s, vert.texcoord).r;
|
|
|
|
yuv.yz = texUV.sample(s, vert.texcoord).gr;
|
|
|
|
|
|
|
|
yuv += decode.offset;
|
|
|
|
|
|
|
|
return col * float4(dot(yuv, decode.Rcoeff), dot(yuv, decode.Gcoeff), dot(yuv, decode.Bcoeff), 1.0);
|
|
|
|
}
|