#include <metal_stdlib>

using namespace metal;
uint3 textureDimensions_0276ec(texture3d<uint, access::read_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<uint, access::read_write> tint_symbol_2 [[texture(0)]]) {
  *(tint_symbol_1) = packed_uint3(textureDimensions_0276ec(tint_symbol_2));
  return;
}

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

