PDA

View Full Version : what is 'indirect' in glDispatchComputeIndirect?



harsha
09-23-2013, 07:22 AM
I am not getting how to assign value to 'indirect' to use it in glDispatchComputeIndirect().

As per my understanding, when a buffer is bound using GL_DISPATCH_INDIRECT_BUFFER, that data can be altered in compute shader using the work group size using offset provided in this indirect ptr.

But not getting should indirect be a struct ptr with 3 uint variables having value for x, y, z dimensions or an integer ptr?

Can anyone please help in understanding it.

Thanks.

thokra
09-23-2013, 07:59 AM
You pass the offset into the buffer to glDispatchComputeIndirect(). At the address that is computed with this offset, the GL expects 3, tighly packed uints. That's it.

What the GL does under the hood is effectively equivalent to:



typedef struct {
uint num_groups_x;
uint num_groups_y;
uint num_groups_z;
} DispatchIndirectCommand;

void glDispatchComputeIndirect(GLintptr indirect)
{
cmd = (const DispatchIndirectCommand *)(bufferBaseAddress + indirect);
glDispatchCompute(cmd->num_groups_x, cmd->num_groups_y, cmd->num_groups_z);
}


As long as you're not pointing to some invalid adress and as long as your parameter pack is valid, there shouldn't be any problems.

eraasha
09-24-2013, 02:00 AM
You pass the offset into the buffer to glDispatchComputeIndirect(). At the address that is computed with this offset, the GL expects 3, tighly packed uints. That's it.

What the GL does under the hood is effectively equivalent to:



typedef struct {
uint num_groups_x;
uint num_groups_y;
uint num_groups_z;
} DispatchIndirectCommand;

void glDispatchComputeIndirect(GLintptr indirect)
{
cmd = (const DispatchIndirectCommand *)(bufferBaseAddress + indirect);
glDispatchCompute(cmd->num_groups_x, cmd->num_groups_y, cmd->num_groups_z);
}


As long as you're not pointing to some invalid adress and as long as your parameter pack is valid, there shouldn't be any problems.


Hi thokra,

Does this mean doing something like :

struct __attribute__ ((packed)){
GLuint x, y,z;
}s;
struct s obj;

obj.x=1;
obj.y=1;
obj.z =1;

glGenBuffers(1, &buffer_obj)
glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, buffer_obj);
glBufferData(GL_DISPATCH_INDIRECT_BUFFER, sizeof(s), obj, GL_STREAN_READ );
glDispatchComputeIndirect(0);

Else can you give any example?

thokra
09-24-2013, 04:35 AM
That should do it. Only it would make more sense to write the values of x,y and z from inside a shader. In essence, what you absolutely need to do is allocate enough space for at least one group of uints in the buffer object's data store. Otherwise, indirect dispatch doesn't make much sense. Note that the attribute specifier is GCC specific.