]> git.sesse.net Git - narabu/blobdiff - narabu-encoder.cpp
Start trying to count the rANS distributions from the encoding shader.
[narabu] / narabu-encoder.cpp
index 2ddd8992fd2fe0da3b56bd2b0ec90598ceb93461..e8d20e042af141d2f404c3f4a676bd463ea4918b 100644 (file)
@@ -334,6 +334,13 @@ int main(int argc, char **argv)
 
        glUseProgram(glsl_program_num);
 
+       // An SSBO for the rANS distributions.
+       GLuint ssbo;
+       glGenBuffers(1, &ssbo);
+       glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
+       glBufferData(GL_SHADER_STORAGE_BUFFER, 65536 * 4 * sizeof(uint32_t), nullptr, GL_DYNAMIC_COPY);
+       glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 9, ssbo);
+
        // Upload luma.
        GLuint y_tex;
        glGenTextures(1, &y_tex);
@@ -392,7 +399,7 @@ int main(int argc, char **argv)
        check_error();
 
        steady_clock::time_point start = steady_clock::now();
-       unsigned num_iterations = 1000;
+       unsigned num_iterations = 100;
        for (unsigned i = 0; i < num_iterations; ++i) {
                glDispatchCompute(WIDTH_BLOCKS, HEIGHT_BLOCKS, 1);
        }
@@ -575,4 +582,11 @@ int main(int argc, char **argv)
        printf("\n");
        printf("Each iteration took %.3f ms (but note that is DCT only, no rANS).\n", 1e3 * duration<double>(now - start).count() / num_iterations);
 
+#if 1
+       glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
+       const uint32_t *dist = (const uint32_t *)glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_ONLY);
+       for (int i = 0; i < 1024; ++i) {
+               printf("%d,%d: %u\n", i / 256, i % 256, dist[i] / num_iterations);
+       }
+#endif
 }