Atlas - SDL_shaders_metal.metal
Home / ext / SDL2 / src / render / metal Lines: 1 | Size: 3849 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1#include <metal_texture> 2#include <metal_matrix> 3 4using namespace metal; 5 6struct SolidVertexOutput 7{ 8 float4 position [[position]]; 9 float pointSize [[point_size]]; 10}; 11 12vertex SolidVertexOutput SDL_Solid_vertex(const device float2 *position [[buffer(0)]], 13 constant float4x4 &projection [[buffer(2)]], 14 constant float4x4 &transform [[buffer(3)]], 15 uint vid [[vertex_id]]) 16{ 17 SolidVertexOutput v; 18 v.position = (projection * transform) * float4(position[vid], 0.0f, 1.0f); 19 v.pointSize = 1.0f; 20 return v; 21} 22 23fragment float4 SDL_Solid_fragment(constant float4 &col [[buffer(0)]]) 24{ 25 return col; 26} 27 28struct CopyVertexOutput 29{ 30 float4 position [[position]]; 31 float2 texcoord; 32}; 33 34vertex CopyVertexOutput SDL_Copy_vertex(const device float2 *position [[buffer(0)]], 35 const device float2 *texcoords [[buffer(1)]], 36 constant float4x4 &projection [[buffer(2)]], 37 constant float4x4 &transform [[buffer(3)]], 38 uint vid [[vertex_id]]) 39{ 40 CopyVertexOutput v; 41 v.position = (projection * transform) * float4(position[vid], 0.0f, 1.0f); 42 v.texcoord = texcoords[vid]; 43 return v; 44} 45 46fragment float4 SDL_Copy_fragment(CopyVertexOutput vert [[stage_in]], 47 constant float4 &col [[buffer(0)]], 48 texture2d<float> tex [[texture(0)]], 49 sampler s [[sampler(0)]]) 50{ 51 return tex.sample(s, vert.texcoord) * col; 52} 53 54struct YUVDecode 55{ 56 float3 offset; 57 float3 Rcoeff; 58 float3 Gcoeff; 59 float3 Bcoeff; 60}; 61 62fragment float4 SDL_YUV_fragment(CopyVertexOutput vert [[stage_in]], 63 constant float4 &col [[buffer(0)]], 64 constant YUVDecode &decode [[buffer(1)]], 65 texture2d<float> texY [[texture(0)]], 66 texture2d_array<float> texUV [[texture(1)]], 67 sampler s [[sampler(0)]]) 68{ 69 float3 yuv; 70 yuv.x = texY.sample(s, vert.texcoord).r; 71 yuv.y = texUV.sample(s, vert.texcoord, 0).r; 72 yuv.z = texUV.sample(s, vert.texcoord, 1).r; 73 74 yuv += decode.offset; 75 76 return col * float4(dot(yuv, decode.Rcoeff), dot(yuv, decode.Gcoeff), dot(yuv, decode.Bcoeff), 1.0); 77} 78 79fragment float4 SDL_NV12_fragment(CopyVertexOutput vert [[stage_in]], 80 constant float4 &col [[buffer(0)]], 81 constant YUVDecode &decode [[buffer(1)]], 82 texture2d<float> texY [[texture(0)]], 83 texture2d<float> texUV [[texture(1)]], 84 sampler s [[sampler(0)]]) 85{ 86 float3 yuv; 87 yuv.x = texY.sample(s, vert.texcoord).r; 88 yuv.yz = texUV.sample(s, vert.texcoord).rg; 89 90 yuv += decode.offset; 91 92 return col * float4(dot(yuv, decode.Rcoeff), dot(yuv, decode.Gcoeff), dot(yuv, decode.Bcoeff), 1.0); 93} 94 95fragment float4 SDL_NV21_fragment(CopyVertexOutput vert [[stage_in]], 96 constant float4 &col [[buffer(0)]], 97 constant YUVDecode &decode [[buffer(1)]], 98 texture2d<float> texY [[texture(0)]], 99 texture2d<float> texUV [[texture(1)]], 100 sampler s [[sampler(0)]]) 101{ 102 float3 yuv; 103 yuv.x = texY.sample(s, vert.texcoord).r; 104 yuv.yz = texUV.sample(s, vert.texcoord).gr; 105 106 yuv += decode.offset; 107 108 return col * float4(dot(yuv, decode.Rcoeff), dot(yuv, decode.Gcoeff), dot(yuv, decode.Bcoeff), 1.0); 109} 110[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.