Search code examples
openglglslbuffer-overflowopengl-4

How to detect access violation on SSBO in OpenGL?


Suppose I have an SSBO in the glsl shader as follows.

layout(std430, binding = 10) buffer myData
{
  uint64_t intArray[];
};

On the host, I will dynamically allocate the SSBO. In the shader, I will write data to this 'intArray' variable. How do I detect whether my shader code is accessing within the boundary of the array? Are there any tools to do the check (similar to valgrind, pageheap, -fsanitize, ... on CPU)?

Edit: In general, are there any ways to analyze the glsl code and figure out the memory issue?


Solution

  • The simplest way to figure out whether you're accessing within the array is to get the size of the array and check to see if the index you're about to use accesses past it or not. intArray.length() will give you the runtime length of the array, based on the size range of the buffer you have bound to that SSBO binding point.