Skip to content

Instantly share code, notes, and snippets.

@rygorous
Created February 11, 2023 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rygorous/2b634ec49a4eb73eae2a0b9425a04a25 to your computer and use it in GitHub Desktop.
Save rygorous/2b634ec49a4eb73eae2a0b9425a04a25 to your computer and use it in GitHub Desktop.
Another old repro from 2014
#version 430 core
layout(local_size_x=1) in;
layout(binding=0) uniform isamplerBuffer coeff_data;
layout(binding=0, std430) restrict buffer debug_buf {
uint debug[];
};
shared uvec2 ac_nonzero[1]; // x=lo, y=hi
int coeff_data_v(uint offs)
{
return texelFetch(coeff_data, int(offs)).x;
}
void main()
{
// fetch coeff data offset
int blah = coeff_data_v(0);
if (blah >= 0)
{
uint ptr = uint(coeff_data_v(1));
if (ptr != 0)
{
// at start, ptr points to "flags"
uint flags = uint(coeff_data_v(ptr));
debug[0] = ptr;
debug[1] = flags;
// read ac_nonzero flags
// NB this if is always true! (local_size_x == 1)
if (gl_LocalInvocationID.x == 0)
{
debug[4] = 0x12345678; // proof we made it here
// default is zero
uvec2 nonzero_mask = uvec2(0, 0);
// some blocks are flagged as having ACs
if ((flags & 1) != 0)
{
nonzero_mask = uvec2(coeff_data_v(ptr + 1), coeff_data_v(ptr + 2));
debug[8] = 0xcafebabe; // proof we made it here
}
else
{
debug[12] = 0x0debac1e; // proof we made it here
}
ac_nonzero[0] = nonzero_mask;
}
groupMemoryBarrier();
debug[0x20] = ac_nonzero[0].x;
debug[0x21] = ac_nonzero[0].y;
}
}
}
#include <stdio.h>
#include <GL/gl3w.h>
#include "util.h"
#include "radglx.h"
int main(int argc, char **argv)
{
int ret = 0;
glx_context * glx = glx_init( "bink2test", 1280, 720 );
// Coeff data buffers
static const GLuint ac_coeff_data[] =
{
0, 2, 0xf00d0000, 0xdeadbeef, 0xfacefeed
};
GLuint luma_ac_buf = glx_make_buffer( GL_TEXTURE_BUFFER, sizeof( ac_coeff_data ), ac_coeff_data, GL_STATIC_DRAW );
GLuint luma_ac_tex;
glGenTextures( 1, &luma_ac_tex );
glBindTexture( GL_TEXTURE_BUFFER, luma_ac_tex );
glTexBuffer( GL_TEXTURE_BUFFER, GL_R32I, luma_ac_buf );
// NOTE: just leave luma_ac_tex bound for program!
// Debug buffer
GLuint debug_vals[128] = {0};
GLuint debug_buf = glx_make_buffer( GL_SHADER_STORAGE_BUFFER, sizeof( debug_vals ), debug_vals, GL_DYNAMIC_READ );
// Create test program
GLuint repro_prog = glx_compute_program_file( "c_dct_repro_block.glsl" );
if ( !repro_prog )
return 1;
// Run it
glUseProgram( repro_prog );
glBindBufferBase( GL_SHADER_STORAGE_BUFFER, 0, debug_buf );
glDispatchCompute( 1, 1, 1 );
// Finish (brute force, just to make sure)
glUseProgram( 0 );
glMemoryBarrier( GL_SHADER_STORAGE_BARRIER_BIT );
glFinish();
// Dump contents of debug (output) buffer
glBindBuffer( GL_SHADER_STORAGE_BUFFER, debug_buf );
glGetBufferSubData( GL_SHADER_STORAGE_BUFFER, 0, sizeof( debug_vals ), debug_vals );
printf( "\ndebug_buf:\n" );
dump_dwords( debug_vals, sizeof(debug_vals)/sizeof(*debug_vals) );
if ( debug_vals[4] == 0x12345678 && debug_vals[8] == 0 && debug_vals[12] == 0x0debac1e )
printf( "\nlooks OK.\n" );
else
{
printf( "\nERROR!\n" );
ret = 1;
}
// clean up
glDeleteBuffers( 1, &luma_ac_buf );
glDeleteBuffers( 1, &debug_buf );
glDeleteTextures( 1, &luma_ac_tex );
glDeleteProgram( repro_prog );
glx_shutdown( glx );
return ret;
}
// vim:et:sw=4
// @cdep pre $DefaultsConsoleGL
// @cdep post $BuildConsoleGL( , )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment