From: Steinar H. Gunderson Date: Sun, 24 Sep 2017 17:39:25 +0000 (+0200) Subject: Make blocks per stream a named constant. X-Git-Url: https://git.sesse.net/?p=narabu;a=commitdiff_plain;h=69e36d8b488476d9d0e23f5b54eb18a4f9b5fbdd Make blocks per stream a named constant. --- diff --git a/decoder.shader b/decoder.shader index 724a2f5..3b72126 100644 --- a/decoder.shader +++ b/decoder.shader @@ -16,6 +16,7 @@ const uint prob_bits = 12; const uint prob_scale = 1 << prob_bits; const uint NUM_SYMS = 256; const uint ESCAPE_LIMIT = NUM_SYMS - 1; +const uint BLOCKS_PER_STREAM = 320; // These need to be folded into quant_matrix. const float dc_scalefac = 8.0; @@ -230,7 +231,7 @@ void main() pick_timer(start, local_timing[0]); - for (uint block_idx = 40; block_idx --> 0; ) { + for (uint block_idx = BLOCKS_PER_STREAM / 8; block_idx --> 0; ) { pick_timer(start, local_timing[1]); // rANS decode one coefficient across eight blocks (so 64x8 coefficients). diff --git a/narabu.cpp b/narabu.cpp index 11117f4..898f7ef 100644 --- a/narabu.cpp +++ b/narabu.cpp @@ -24,6 +24,7 @@ const unsigned prob_bits = 12; const unsigned prob_scale = 1 << prob_bits; const unsigned NUM_SYMS = 256; const unsigned NUM_TABLES = 8; +const unsigned BLOCKS_PER_STREAM = 320; struct RansDecSymbol { unsigned sym_start; @@ -266,7 +267,7 @@ int main(int argc, char **argv) #define PARALLEL_SLICES 1 steady_clock::time_point start = steady_clock::now(); for (int i = 0; i < 1000; ++i) { - unsigned num_slices = (WIDTH/8)*(HEIGHT/8)/320; + unsigned num_slices = (WIDTH/8)*(HEIGHT/8)/BLOCKS_PER_STREAM; glDispatchCompute(1, (num_slices+PARALLEL_SLICES-1)/PARALLEL_SLICES, 1); } check_error(); diff --git a/qdc.cpp b/qdc.cpp index 5a4a9d5..a0919bd 100644 --- a/qdc.cpp +++ b/qdc.cpp @@ -23,8 +23,10 @@ #define HEIGHT_BLOCKS (HEIGHT/8) #define NUM_BLOCKS (WIDTH_BLOCKS * HEIGHT_BLOCKS) #define NUM_BLOCKS_CHROMA (WIDTH_BLOCKS_CHROMA * HEIGHT_BLOCKS) + #define NUM_SYMS 256 #define ESCAPE_LIMIT (NUM_SYMS - 1) +#define BLOCKS_PER_STREAM 320 // If you set this to 1, the program will try to optimize the placement // of coefficients to rANS probability distributions. This is randomized, @@ -720,10 +722,10 @@ int main(int argc, char **argv) #endif // DC coefficient pred from the right to left (within each slice) - for (unsigned block_idx = 0; block_idx < NUM_BLOCKS; block_idx += 320) { + for (unsigned block_idx = 0; block_idx < NUM_BLOCKS; block_idx += BLOCKS_PER_STREAM) { int prev_k = 128; - for (unsigned subblock_idx = 320; subblock_idx --> 0; ) { + for (unsigned subblock_idx = BLOCKS_PER_STREAM; subblock_idx --> 0; ) { unsigned yb = (block_idx + subblock_idx) / WIDTH_BLOCKS; unsigned xb = (block_idx + subblock_idx) % WIDTH_BLOCKS; int k = coeff_y[(yb * 8) * WIDTH + (xb * 8)]; @@ -733,11 +735,11 @@ int main(int argc, char **argv) prev_k = k; } } - for (unsigned block_idx = 0; block_idx < NUM_BLOCKS_CHROMA; block_idx += 320) { + for (unsigned block_idx = 0; block_idx < NUM_BLOCKS_CHROMA; block_idx += BLOCKS_PER_STREAM) { int prev_k_cb = 0; int prev_k_cr = 0; - for (unsigned subblock_idx = 320; subblock_idx --> 0; ) { + for (unsigned subblock_idx = BLOCKS_PER_STREAM; subblock_idx --> 0; ) { unsigned yb = (block_idx + subblock_idx) / WIDTH_BLOCKS_CHROMA; unsigned xb = (block_idx + subblock_idx) % WIDTH_BLOCKS_CHROMA; int k_cb = coeff_cb[(yb * 8) * WIDTH/2 + (xb * 8)]; @@ -880,7 +882,7 @@ int main(int argc, char **argv) //printf("encoding coeff %d xb,yb=%d,%d: %d\n", y*8+x, xb, yb, k); rans_encoder.encode_coeff(k); - if (block_idx % 320 == 319 || block_idx == NUM_BLOCKS - 1) { + if (block_idx % BLOCKS_PER_STREAM == (BLOCKS_PER_STREAM - 1) || block_idx == NUM_BLOCKS - 1) { int l = rans_encoder.save_block(codedfp); num_bytes += l; lens.push_back(l); @@ -920,7 +922,7 @@ int main(int argc, char **argv) //printf("encoding coeff %d xb,yb=%d,%d: %d\n", y*8+x, xb, yb, k); rans_encoder.encode_coeff(k); - if (block_idx % 320 == 319 || block_idx == NUM_BLOCKS - 1) { + if (block_idx % BLOCKS_PER_STREAM == (BLOCKS_PER_STREAM - 1) || block_idx == NUM_BLOCKS - 1) { num_bytes += rans_encoder.save_block(codedfp); } } @@ -945,7 +947,7 @@ int main(int argc, char **argv) //printf("encoding coeff %d xb,yb=%d,%d: %d\n", y*8+x, xb, yb, k); rans_encoder.encode_coeff(k); - if (block_idx % 320 == 319 || block_idx == NUM_BLOCKS - 1) { + if (block_idx % BLOCKS_PER_STREAM == (BLOCKS_PER_STREAM - 1) || block_idx == NUM_BLOCKS - 1) { num_bytes += rans_encoder.save_block(codedfp); } }