#include <metal_stdlib>
using namespace metal;

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

struct VertexOutput {
  float4 pos;
  uint2 prevent_dce;
};

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

uint2 textureDimensions_879b73(tint_module_vars_struct tint_module_vars) {
  uint2 res = uint2(tint_module_vars.arg_0.get_width(0u), tint_module_vars.arg_0.get_height(0u));
  return res;
}

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

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

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

vertex vertex_main_outputs vertex_main(texturecube_array<float, access::sample> arg_0 [[texture(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.arg_0=arg_0};
  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;
}
