X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=decoder.shader;h=e7b83e0ccbb52402dcb0a827119fe272eff892fc;hb=d065040ec9cc2f4ba71ab399e6e9da998b45e16e;hp=512d743cb1307b2932f5a198c81f2cb562a4174a;hpb=8989d0f3ce3d2c5074aeb5be4297fda30d3efc67;p=narabu diff --git a/decoder.shader b/decoder.shader index 512d743..e7b83e0 100644 --- a/decoder.shader +++ b/decoder.shader @@ -1,12 +1,16 @@ -#version 430 +#version 440 #extension GL_ARB_shader_clock : enable +#define PARALLEL_SLICES 1 + #define ENABLE_TIMING 0 -layout(local_size_x = 8, local_size_y = 8) in; +layout(local_size_x = 64*PARALLEL_SLICES) in; layout(r8ui) uniform restrict readonly uimage2D cum2sym_tex; layout(rg16ui) uniform restrict readonly uimage2D dsyms_tex; layout(r8) uniform restrict writeonly image2D out_tex; +layout(r16i) uniform restrict writeonly iimage2D coeff_tex; +uniform int num_blocks; const uint prob_bits = 12; const uint prob_scale = 1 << prob_bits; @@ -37,6 +41,16 @@ const uint ff_zigzag_direct[64] = { 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63 }; +const uint stream_mapping[64] = { + 0, 0, 1, 1, 2, 2, 3, 3, + 0, 0, 1, 2, 2, 2, 3, 3, + 1, 1, 2, 2, 2, 3, 3, 3, + 1, 1, 2, 2, 2, 3, 3, 3, + 1, 2, 2, 2, 2, 3, 3, 3, + 2, 2, 2, 2, 3, 3, 3, 3, + 2, 2, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, +}; layout(std430, binding = 9) buffer layoutName { @@ -58,18 +72,10 @@ uniform uint sign_bias_per_model[16]; const uint RANS_BYTE_L = (1u << 23); // lower bound of our normalization interval -uint last_offset = -1, ransbuf; - uint get_rans_byte(uint offset) { - if (last_offset != (offset >> 2)) { - last_offset = offset >> 2; - ransbuf = data_SSBO[offset >> 2]; - } - return bitfieldExtract(ransbuf, 8 * int(offset & 3u), 8); - // We assume little endian. -// return bitfieldExtract(data_SSBO[offset >> 2], 8 * int(offset & 3u), 8); + return bitfieldExtract(data_SSBO[offset >> 2], 8 * int(offset & 3u), 8); } uint RansDecInit(inout uint offset) @@ -162,7 +168,7 @@ void idct_1d(inout float y0, inout float y1, inout float y2, inout float y3, ino y7 = p6_0 - p6_7; } -shared float temp[64 * 8]; +shared float temp[64 * 8 * PARALLEL_SLICES]; void pick_timer(inout uvec2 start, inout uvec2 t) { @@ -193,18 +199,22 @@ void main() } uvec2 start = clock2x32ARB(); #else - uvec2 start; + uvec2 start = uvec2(0, 0); + local_timing[0] = start; #endif - const uint num_blocks = 720 / 16; // FIXME: make a uniform - const uint thread_num = gl_LocalInvocationID.y * 8 + gl_LocalInvocationID.x; + const uint local_x = gl_LocalInvocationID.x % 8; + const uint local_y = (gl_LocalInvocationID.x / 8) % 8; + const uint local_z = gl_LocalInvocationID.x / 64; + + const uint slice_num = local_z; + const uint thread_num = local_y * 8 + local_x; - const uint block_row = gl_WorkGroupID.y; + const uint block_row = gl_WorkGroupID.y * PARALLEL_SLICES + slice_num; //const uint coeff_num = ff_zigzag_direct[thread_num]; const uint coeff_num = thread_num; const uint stream_num = coeff_num * num_blocks + block_row; - //const uint stream_num = block_row * num_blocks + coeff_num; // HACK - const uint model_num = min((coeff_num % 8) + (coeff_num / 8), 7); + const uint model_num = stream_mapping[coeff_num]; const uint sign_bias = sign_bias_per_model[model_num]; // Initialize rANS decoder. @@ -252,7 +262,13 @@ void main() last_k = k; } - temp[subblock_idx * 64 + coeff_num] = k * q; +#if 0 + uint y = block_row * 16 + block_y * 8 + local_y; + uint x = block_x * 64 + subblock_idx * 8 + local_x; + imageStore(coeff_tex, ivec2(x, y), ivec4(k, 0,0,0)); +#endif + + temp[slice_num * 64 * 8 + subblock_idx * 64 + coeff_num] = k * q; //temp[subblock_idx * 64 + 8 * y + x] = (2 * k * w * 4) / 32; // 100% matching unquant } @@ -264,14 +280,14 @@ void main() pick_timer(start, local_timing[3]); // Horizontal DCT one row (so 64 rows). - idct_1d(temp[thread_num * 8 + 0], - temp[thread_num * 8 + 1], - temp[thread_num * 8 + 2], - temp[thread_num * 8 + 3], - temp[thread_num * 8 + 4], - temp[thread_num * 8 + 5], - temp[thread_num * 8 + 6], - temp[thread_num * 8 + 7]); + idct_1d(temp[slice_num * 64 * 8 + thread_num * 8 + 0], + temp[slice_num * 64 * 8 + thread_num * 8 + 1], + temp[slice_num * 64 * 8 + thread_num * 8 + 2], + temp[slice_num * 64 * 8 + thread_num * 8 + 3], + temp[slice_num * 64 * 8 + thread_num * 8 + 4], + temp[slice_num * 64 * 8 + thread_num * 8 + 5], + temp[slice_num * 64 * 8 + thread_num * 8 + 6], + temp[slice_num * 64 * 8 + thread_num * 8 + 7]); pick_timer(start, local_timing[4]); @@ -281,7 +297,7 @@ void main() pick_timer(start, local_timing[5]); // Vertical DCT one row (so 64 columns). - uint row_offset = gl_LocalInvocationID.y * 64 + gl_LocalInvocationID.x; + uint row_offset = local_z * 64 * 8 + local_y * 64 + local_x; idct_1d(temp[row_offset + 0 * 8], temp[row_offset + 1 * 8], temp[row_offset + 2 * 8], @@ -294,7 +310,7 @@ void main() pick_timer(start, local_timing[6]); uint y = block_row * 16 + block_y * 8; - uint x = block_x * 64 + gl_LocalInvocationID.y * 8 + gl_LocalInvocationID.x; + uint x = block_x * 64 + local_y * 8 + local_x; for (uint yl = 0; yl < 8; ++yl) { imageStore(out_tex, ivec2(x, yl + y), vec4(temp[row_offset + yl * 8], 0.0, 0.0, 1.0)); }