#include <metal_stdlib>

using namespace metal;
struct tint_symbol {
  float4 value [[position]];
};

void textureDimensions_26bdfa(texture3d<float, access::sample> tint_symbol_2) {
  int3 res = int3(tint_symbol_2.get_width(0), tint_symbol_2.get_height(0), tint_symbol_2.get_depth(0));
}

vertex tint_symbol vertex_main(texture3d<float, access::sample> tint_symbol_3 [[texture(0)]]) {
  textureDimensions_26bdfa(tint_symbol_3);
  tint_symbol const tint_symbol_1 = {.value=float4()};
  return tint_symbol_1;
}

fragment void fragment_main(texture3d<float, access::sample> tint_symbol_4 [[texture(0)]]) {
  textureDimensions_26bdfa(tint_symbol_4);
  return;
}

kernel void compute_main(texture3d<float, access::sample> tint_symbol_5 [[texture(0)]]) {
  textureDimensions_26bdfa(tint_symbol_5);
  return;
}

