#include <metal_stdlib>

using namespace metal;
uint3 textureDimensions_ef2e58(texture3d<int, access::write> tint_symbol) {
  uint3 res = uint3(tint_symbol.get_width(), tint_symbol.get_height(), tint_symbol.get_depth());
  return res;
}

fragment void fragment_main(device packed_uint3* tint_symbol_1 [[buffer(0)]], texture3d<int, access::write> tint_symbol_2 [[texture(0)]]) {
  *(tint_symbol_1) = packed_uint3(textureDimensions_ef2e58(tint_symbol_2));
  return;
}

kernel void compute_main(device packed_uint3* tint_symbol_3 [[buffer(0)]], texture3d<int, access::write> tint_symbol_4 [[texture(0)]]) {
  *(tint_symbol_3) = packed_uint3(textureDimensions_ef2e58(tint_symbol_4));
  return;
}

