]> git.sesse.net Git - narabu/commitdiff
Implement sign_bias in the rANS GPU encoder. Still not working properly.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 16 Oct 2017 20:16:41 +0000 (22:16 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 16 Oct 2017 20:16:41 +0000 (22:16 +0200)
coded.dat
rans.shader

index a81138917ee68b42279ee1b4130f012bcade8d81..3980407c36b3a939eda4e5c24eec4998427f9957 100644 (file)
Binary files a/coded.dat and b/coded.dat differ
index a7c6f8cce21abee5bca5cfbff55739ff0e323ef3..36feb657544e0fbfcb19b4e955bad5c3031ecf8c 100644 (file)
@@ -87,7 +87,7 @@ void RansEncFlush(uint rans, inout uint rans_offset)
        rans_output[rans_offset + 3] = uint8_t(rans >> 24);
 }
 
-void encode_coeff(uint coeff, uint bits, inout RansEncoder enc)
+void encode_coeff(uint coeff, uint bits, uint sign_bias, inout RansEncoder enc)
 {
        // Sign-extend to recover the coefficient.
        // FIXME: not needed for the bits == 8 case!
@@ -100,10 +100,12 @@ void encode_coeff(uint coeff, uint bits, inout RansEncoder enc)
                k = ESCAPE_LIMIT;
        }
 
-       uvec2 sym = ransdist[enc.lut_base + (k - 1) & (NUM_SYMS - 1)];
+       uvec2 sym = ransdist[enc.lut_base + (k + NUM_SYMS - 1) & (NUM_SYMS - 1)];
        RansEncPut(enc.rans, enc.rans_offset, sym.x, sym.y, prob_bits);
        
-       // fix some bias stuff here
+       if (signed_k < 0) {
+               enc.rans += sign_bias;
+       }
 }
 
 void encode_end(inout RansEncoder enc)
@@ -118,14 +120,17 @@ void encode_9_7(uint streamgroup_num, uint coeff_row, layout(r16ui) restrict rea
        RansEncInit(streamgroup_num, coeff_row, col1, dist1, enc1);
        RansEncInit(streamgroup_num, coeff_row, col2, dist2, enc2);
 
+       uint sign_bias1 = ransdist[enc1.lut_base + 255].x + ransdist[enc1.lut_base + 255].y;
+       uint sign_bias2 = ransdist[enc2.lut_base + 255].x + ransdist[enc2.lut_base + 255].y;
+
        for (uint subblock_idx = BLOCKS_PER_STREAM; subblock_idx --> 0; ) {
                // TODO: Use SSBOs instead of a texture?
                uint x = (streamgroup_num * BLOCKS_PER_STREAM + subblock_idx) % 160;
                uint y = (streamgroup_num * BLOCKS_PER_STREAM + subblock_idx) / 160;
                uint f = imageLoad(tex, ivec2(x, y * 8 + coeff_row)).x;
 
-               encode_coeff(f & 0x1ffu, 9, enc1);
-               encode_coeff(f >> 9, 7, enc2);
+               encode_coeff(f & 0x1ffu, 9, sign_bias1, enc1);
+               encode_coeff(f >> 9, 7, sign_bias2, enc2);
        }
 
        encode_end(enc1);
@@ -137,13 +142,15 @@ void encode_8(uint streamgroup_num, uint coeff_row, layout(r8i) restrict readonl
        RansEncoder enc;
        RansEncInit(streamgroup_num, coeff_row, col, dist, enc);
 
+       uint sign_bias = ransdist[enc.lut_base + 255].x + ransdist[enc.lut_base + 255].y;
+
        for (uint subblock_idx = BLOCKS_PER_STREAM; subblock_idx --> 0; ) {
                // TODO: Use SSBOs instead of a texture?
                uint x = (streamgroup_num * BLOCKS_PER_STREAM + subblock_idx) % 160;
                uint y = (streamgroup_num * BLOCKS_PER_STREAM + subblock_idx) / 160;
                int f = imageLoad(tex, ivec2(x, y * 8 + coeff_row)).x;
 
-               encode_coeff(f, 8, enc);
+               encode_coeff(f, 8, sign_bias, enc);
        }
 
        encode_end(enc);