#include <metal_stdlib>

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

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

