Skip to content

Commit

Permalink
perf: fix skinning performance issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan hoffstadt authored and hoffstadt committed Jan 24, 2025
1 parent 36cda69 commit 06fb680
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
10 changes: 6 additions & 4 deletions extensions/pl_renderer_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -3497,8 +3497,8 @@ pl_refr_render_scene(uint32_t uSceneHandle, const uint32_t* auViewHandles, const
uJumpSteps = 1;

const plDispatch tDispach = {
.uGroupCountX = (uint32_t)tDimensions.x / 8,
.uGroupCountY = (uint32_t)tDimensions.y / 8,
.uGroupCountX = (uint32_t)ceilf(tDimensions.x / 8.0f),
.uGroupCountY = (uint32_t)ceilf(tDimensions.y / 8.0f),
.uGroupCountZ = 1,
.uThreadPerGroupX = 8,
.uThreadPerGroupY = 8,
Expand All @@ -3522,7 +3522,7 @@ pl_refr_render_scene(uint32_t uSceneHandle, const uint32_t* auViewHandles, const
.tTexture = ptView->atUVMaskTexture1,
.uSlot = 1,
.tType = PL_TEXTURE_BINDING_TYPE_STORAGE,
.tCurrentUsage = PL_TEXTURE_USAGE_STORAGE
.tCurrentUsage = PL_TEXTURE_USAGE_STORAGE
}
};

Expand Down Expand Up @@ -3577,7 +3577,9 @@ pl_refr_render_scene(uint32_t uSceneHandle, const uint32_t* auViewHandles, const

plDynamicBinding tDynamicBinding = pl__allocate_dynamic_data(ptDevice);
plVec4* ptJumpDistance = (plVec4*)tDynamicBinding.pcData;
ptJumpDistance->x = fJumpDistance;
ptJumpDistance->x = tDimensions.x;
ptJumpDistance->y = tDimensions.y;
ptJumpDistance->z = fJumpDistance;

gptGfx->bind_compute_bind_groups(ptJumpEncoder, gptData->tJFAShader, 0, 1, &atJFABindGroups[i % 2], 1, &tDynamicBinding);
gptGfx->dispatch(ptJumpEncoder, 1, &tDispach);
Expand Down
7 changes: 4 additions & 3 deletions extensions/pl_renderer_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ pl_refr_perform_skinning(plCommandBuffer* ptCommandBuffer, uint32_t uSceneHandle
int iSourceDataOffset;
int iDestDataOffset;
int iDestVertexOffset;
int iUnused;
uint32_t uMaxSize;
} SkinDynamicData;

if(uSkinCount)
Expand All @@ -772,12 +772,13 @@ pl_refr_perform_skinning(plCommandBuffer* ptCommandBuffer, uint32_t uSceneHandle
ptDynamicData->iSourceDataOffset = ptScene->sbtSkinData[i].iSourceDataOffset;
ptDynamicData->iDestDataOffset = ptScene->sbtSkinData[i].iDestDataOffset;
ptDynamicData->iDestVertexOffset = ptScene->sbtSkinData[i].iDestVertexOffset;
ptDynamicData->uMaxSize = ptScene->sbtSkinData[i].uVertexCount;

const plDispatch tDispach = {
.uGroupCountX = ptScene->sbtSkinData[i].uVertexCount,
.uGroupCountX = (uint32_t)ceilf((float)ptScene->sbtSkinData[i].uVertexCount / 64.0f),
.uGroupCountY = 1,
.uGroupCountZ = 1,
.uThreadPerGroupX = 1,
.uThreadPerGroupX = 64,
.uThreadPerGroupY = 1,
.uThreadPerGroupZ = 1
};
Expand Down
5 changes: 4 additions & 1 deletion shaders/jumpfloodalgo.comp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ void main()
const int iXCoord = int(gl_WorkGroupID.x * 8 + gl_LocalInvocationID.x);
const int iYCoord = int(gl_WorkGroupID.y * 8 + gl_LocalInvocationID.y);

if(iXCoord >= tDynamicData.tJumpDistance.x || iYCoord >= tDynamicData.tJumpDistance.y)
return;

vec2 outColor = vec2(0.0, 0.0);

ivec2 jumpDist = ivec2(tDynamicData.tJumpDistance.x);
ivec2 jumpDist = ivec2(tDynamicData.tJumpDistance.z);

vec3 curr = vec3(1,1,9999999);
const ivec2 tMin = ivec2(iXCoord, iYCoord);
Expand Down
9 changes: 6 additions & 3 deletions shaders/skinning.comp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ layout(set = 3, binding = 0) uniform PL_DYNAMIC_DATA
int iSourceDataOffset;
int iDestDataOffset;
int iDestVertexOffset;
int iUnused;
uint uMaxSize;
} tObjectInfo;

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -108,13 +108,16 @@ get_skinning_matrix(vec4 inJoints0, vec4 inWeights0)
// [SECTION] entry
//-----------------------------------------------------------------------------

layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
layout (local_size_x = 64, local_size_y = 1, local_size_z = 1) in;

void
main()
{

const uint iVertexIndex = gl_WorkGroupID.x;
const uint iVertexIndex = gl_WorkGroupID.x * 64 + gl_LocalInvocationID.x;

if(iVertexIndex >= tObjectInfo.uMaxSize)
return;

vec4 inPosition = vec4(0.0, 0.0, 0.0, 1.0);
vec3 inNormal = vec3(0.0, 0.0, 0.0);
Expand Down

0 comments on commit 06fb680

Please sign in to comment.