#include <metal_stdlib>
using namespace metal;

struct tint_module_vars_struct {
  device float4* prevent_dce;
  texturecube_array<float, access::sample> arg_0;
  sampler arg_1;
};

struct VertexOutput {
  float4 pos;
  float4 prevent_dce;
};

struct vertex_main_outputs {
  float4 VertexOutput_pos [[position]];
  float4 VertexOutput_prevent_dce [[user(locn0)]] [[flat]];
};

float4 textureSampleGrad_e383db(tint_module_vars_struct tint_module_vars) {
  float4 res = tint_module_vars.arg_0.sample(tint_module_vars.arg_1, float3(1.0f), max(1, 0), gradientcube(float3(1.0f), float3(1.0f)));
  return res;
}

fragment void fragment_main(device float4* prevent_dce [[buffer(0)]], texturecube_array<float, access::sample> arg_0 [[texture(0)]], sampler arg_1 [[sampler(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.prevent_dce=prevent_dce, .arg_0=arg_0, .arg_1=arg_1};
  (*tint_module_vars.prevent_dce) = textureSampleGrad_e383db(tint_module_vars);
}

kernel void compute_main(device float4* prevent_dce [[buffer(0)]], texturecube_array<float, access::sample> arg_0 [[texture(0)]], sampler arg_1 [[sampler(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.prevent_dce=prevent_dce, .arg_0=arg_0, .arg_1=arg_1};
  (*tint_module_vars.prevent_dce) = textureSampleGrad_e383db(tint_module_vars);
}

VertexOutput vertex_main_inner(tint_module_vars_struct tint_module_vars) {
  VertexOutput out = {};
  out.pos = float4(0.0f);
  out.prevent_dce = textureSampleGrad_e383db(tint_module_vars);
  return out;
}

vertex vertex_main_outputs vertex_main(texturecube_array<float, access::sample> arg_0 [[texture(0)]], sampler arg_1 [[sampler(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.arg_0=arg_0, .arg_1=arg_1};
  VertexOutput const v = vertex_main_inner(tint_module_vars);
  vertex_main_outputs tint_wrapper_result = {};
  tint_wrapper_result.VertexOutput_pos = v.pos;
  tint_wrapper_result.VertexOutput_prevent_dce = v.prevent_dce;
  return tint_wrapper_result;
}
