DRW: Add support for compute indirect command.

This just expose the GPU API through DRW.
This commit is contained in:
2022-03-16 09:06:06 +01:00
parent d7df0dcccb
commit e5c2bfb341
4 changed files with 25 additions and 0 deletions

View File

@@ -467,6 +467,10 @@ void DRW_shgroup_call_compute(DRWShadingGroup *shgroup,
* \warning this keeps the ref to groups_ref until it actually dispatch.
*/
void DRW_shgroup_call_compute_ref(DRWShadingGroup *shgroup, int groups_ref[3]);
/**
* \note No need for a barrier. \a indirect_buf is internally synchronized.
*/
void DRW_shgroup_call_compute_indirect(DRWShadingGroup *shgroup, GPUStorageBuf *indirect_buf);
void DRW_shgroup_call_procedural_points(DRWShadingGroup *sh, Object *ob, uint point_count);
void DRW_shgroup_call_procedural_lines(DRWShadingGroup *sh, Object *ob, uint line_count);
void DRW_shgroup_call_procedural_triangles(DRWShadingGroup *sh, Object *ob, uint tri_count);

View File

@@ -191,6 +191,7 @@ typedef enum {
/* Compute Commands. */
DRW_CMD_COMPUTE = 8,
DRW_CMD_COMPUTE_REF = 9,
DRW_CMD_COMPUTE_INDIRECT = 10,
/* Other Commands */
DRW_CMD_BARRIER = 11,
@@ -240,6 +241,10 @@ typedef struct DRWCommandComputeRef {
int *groups_ref;
} DRWCommandComputeRef;
typedef struct DRWCommandComputeIndirect {
GPUStorageBuf *indirect_buf;
} DRWCommandComputeIndirect;
typedef struct DRWCommandBarrier {
eGPUBarrier type;
} DRWCommandBarrier;
@@ -282,6 +287,7 @@ typedef union DRWCommand {
DRWCommandDrawProcedural procedural;
DRWCommandCompute compute;
DRWCommandComputeRef compute_ref;
DRWCommandComputeIndirect compute_indirect;
DRWCommandBarrier barrier;
DRWCommandSetMutableState state;
DRWCommandSetStencil stencil;

View File

@@ -820,6 +820,12 @@ static void drw_command_compute_ref(DRWShadingGroup *shgroup, int groups_ref[3])
cmd->groups_ref = groups_ref;
}
static void drw_command_compute_indirect(DRWShadingGroup *shgroup, GPUStorageBuf *indirect_buf)
{
DRWCommandComputeIndirect *cmd = drw_command_create(shgroup, DRW_CMD_COMPUTE_INDIRECT);
cmd->indirect_buf = indirect_buf;
}
static void drw_command_barrier(DRWShadingGroup *shgroup, eGPUBarrier type)
{
DRWCommandBarrier *cmd = drw_command_create(shgroup, DRW_CMD_BARRIER);
@@ -958,6 +964,12 @@ void DRW_shgroup_call_compute_ref(DRWShadingGroup *shgroup, int groups_ref[3])
drw_command_compute_ref(shgroup, groups_ref);
}
void DRW_shgroup_call_compute_indirect(DRWShadingGroup *shgroup, GPUStorageBuf *indirect_buf)
{
BLI_assert(GPU_compute_shader_support());
drw_command_compute_indirect(shgroup, indirect_buf);
}
void DRW_shgroup_barrier(DRWShadingGroup *shgroup, eGPUBarrier type)
{
BLI_assert(GPU_compute_shader_support());

View File

@@ -1051,6 +1051,9 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
cmd->compute_ref.groups_ref[1],
cmd->compute_ref.groups_ref[2]);
break;
case DRW_CMD_COMPUTE_INDIRECT:
GPU_compute_dispatch_indirect(shgroup->shader, cmd->compute_indirect.indirect_buf);
break;
case DRW_CMD_BARRIER:
GPU_memory_barrier(cmd->barrier.type);
break;