]> git.sesse.net Git - nageru/blob - nageru/v210_subsample.comp
Fix a comment typo.
[nageru] / nageru / v210_subsample.comp
1 #version 150
2 #extension GL_ARB_compute_shader : enable
3 #extension GL_ARB_shader_image_load_store : enable
4
5 layout(local_size_x=2, local_size_y=16) in;
6 layout(r16) uniform restrict readonly image2D in_y;
7 uniform sampler2D in_cbcr;  // Of type RG16.
8 layout(rgb10_a2) uniform restrict writeonly image2D outbuf;
9 uniform float inv_width, inv_height;
10
11 void main()
12 {
13         int xb = int(gl_GlobalInvocationID.x);  // X block number.
14         int y = int(gl_GlobalInvocationID.y);  // Y (actual line).
15         float yf = (gl_GlobalInvocationID.y + 0.5f) * inv_height;  // Y float coordinate.
16
17         // Load and scale CbCr values, sampling in-between the texels to get
18         // to (left/4 + center/2 + right/4).
19         vec2 pix_cbcr[3];
20         for (int i = 0; i < 3; ++i) {
21                 vec2 a = texture(in_cbcr, vec2((xb * 6 + i * 2) * inv_width, yf)).xy;
22                 vec2 b = texture(in_cbcr, vec2((xb * 6 + i * 2 + 1) * inv_width, yf)).xy;
23                 pix_cbcr[i] = (a + b) * (0.5 * 65535.0 / 1023.0);
24         }
25
26         // Load and scale the Y values. Note that we use integer coordinates here,
27         // so we don't need to offset by 0.5.
28         float pix_y[6];
29         for (int i = 0; i < 6; ++i) {
30                 pix_y[i] = imageLoad(in_y, ivec2(xb * 6 + i, y)).x * (65535.0 / 1023.0);
31         }
32
33         imageStore(outbuf, ivec2(xb * 4 + 0, y), vec4(pix_cbcr[0].x, pix_y[0],      pix_cbcr[0].y, 1.0));
34         imageStore(outbuf, ivec2(xb * 4 + 1, y), vec4(pix_y[1],      pix_cbcr[1].x, pix_y[2],      1.0));
35         imageStore(outbuf, ivec2(xb * 4 + 2, y), vec4(pix_cbcr[1].y, pix_y[3],      pix_cbcr[2].x, 1.0));
36         imageStore(outbuf, ivec2(xb * 4 + 3, y), vec4(pix_y[4],      pix_cbcr[2].y, pix_y[5],      1.0));
37 }