#include <metal_stdlib>
using namespace metal;
struct tint_GammaTransferParams {
  float G;
  float A;
  float B;
  float C;
  float D;
  float E;
  float F;
  uint padding;
};
struct tint_ExternalTextureParams {
  uint numPlanes;
  uint doYuvToRgbConversionOnly;
  float3x4 yuvToRgbConversionMatrix;
  tint_GammaTransferParams gammaDecodeParams;
  tint_GammaTransferParams gammaEncodeParams;
  float3x3 gamutConversionMatrix;
  float3x2 sampleTransform;
  float3x2 loadTransform;
  float2 samplePlane0RectMin;
  float2 samplePlane0RectMax;
  float2 samplePlane1RectMin;
  float2 samplePlane1RectMax;
  uint2 visibleSize;
  float2 plane1CoordFactor;
};
struct tint_module_vars_struct {
  texture2d<float, access::sample> arg_0_plane0;
  texture2d<float, access::sample> arg_0_plane1;
  const constant tint_ExternalTextureParams* arg_0_params;
  device float4* prevent_dce;
};
struct vertex_main_outputs {
  float4 tint_symbol [[position]];
};

float3 tint_GammaCorrection(float3 v, tint_GammaTransferParams params) {
  float3 const v_1 = float3(params.G);
  float3 const v_2 = float3(params.D);
  float3 const v_3 = abs(v);
  float3 const v_4 = sign(v);
  return select((v_4 * (pow(((params.A * v_3) + params.B), v_1) + params.E)), (v_4 * ((params.C * v_3) + params.F)), (v_3 < v_2));
}
float4 tint_TextureLoadExternal(texture2d<float, access::sample> plane_0, texture2d<float, access::sample> plane_1, tint_ExternalTextureParams params, uint2 coords) {
  float2 const v_5 = rint((params.loadTransform * float3(float2(min(coords, params.visibleSize)), 1.0f)));
  uint2 const v_6 = uint2(v_5);
  float3 v_7 = 0.0f;
  float v_8 = 0.0f;
  if ((params.numPlanes == 1u)) {
    float4 const v_9 = plane_0.read(v_6, 0u);
    v_7 = v_9.xyz;
    v_8 = v_9[3u];
  } else {
    float const v_10 = plane_0.read(v_6, 0u)[0u];
    v_7 = (float4(v_10, plane_1.read(uint2((v_5 * params.plane1CoordFactor)), 0u).xy, 1.0f) * params.yuvToRgbConversionMatrix);
    v_8 = 1.0f;
  }
  float3 const v_11 = v_7;
  float3 v_12 = 0.0f;
  if ((params.doYuvToRgbConversionOnly == 0u)) {
    v_12 = tint_GammaCorrection((params.gamutConversionMatrix * tint_GammaCorrection(v_11, params.gammaDecodeParams)), params.gammaEncodeParams);
  } else {
    v_12 = v_11;
  }
  return float4(v_12, v_8);
}
void textureLoad_1bfdfb(tint_module_vars_struct tint_module_vars) {
  float4 res = tint_TextureLoadExternal(tint_module_vars.arg_0_plane0, tint_module_vars.arg_0_plane1, (*tint_module_vars.arg_0_params), uint2(1u));
  (*tint_module_vars.prevent_dce) = res;
}
float4 vertex_main_inner(tint_module_vars_struct tint_module_vars) {
  textureLoad_1bfdfb(tint_module_vars);
  return float4(0.0f);
}
fragment void fragment_main(texture2d<float, access::sample> arg_0_plane0 [[texture(0)]], texture2d<float, access::sample> arg_0_plane1 [[texture(1)]], const constant tint_ExternalTextureParams* arg_0_params [[buffer(2)]], device float4* prevent_dce [[buffer(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.arg_0_plane0=arg_0_plane0, .arg_0_plane1=arg_0_plane1, .arg_0_params=arg_0_params, .prevent_dce=prevent_dce};
  textureLoad_1bfdfb(tint_module_vars);
}
kernel void compute_main(texture2d<float, access::sample> arg_0_plane0 [[texture(0)]], texture2d<float, access::sample> arg_0_plane1 [[texture(1)]], const constant tint_ExternalTextureParams* arg_0_params [[buffer(2)]], device float4* prevent_dce [[buffer(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.arg_0_plane0=arg_0_plane0, .arg_0_plane1=arg_0_plane1, .arg_0_params=arg_0_params, .prevent_dce=prevent_dce};
  textureLoad_1bfdfb(tint_module_vars);
}
vertex vertex_main_outputs vertex_main(texture2d<float, access::sample> arg_0_plane0 [[texture(0)]], texture2d<float, access::sample> arg_0_plane1 [[texture(1)]], const constant tint_ExternalTextureParams* arg_0_params [[buffer(2)]], device float4* prevent_dce [[buffer(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.arg_0_plane0=arg_0_plane0, .arg_0_plane1=arg_0_plane1, .arg_0_params=arg_0_params, .prevent_dce=prevent_dce};
  return vertex_main_outputs{.tint_symbol=vertex_main_inner(tint_module_vars)};
}
