Skip to content

Commit

Permalink
Handle arbitrary size in encoded path as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed Jan 13, 2024
1 parent 1ea6798 commit b890855
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
6 changes: 3 additions & 3 deletions assets/shaders/inc/meshlet_primitive_cull.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ uint meshlet_get_meshlet_index()
return gl_WorkGroupSize.y == 8 ? gl_WorkGroupID.x : gl_WorkGroupID.y;
}

uint meshlet_get_sublet_index(uint meshlet_index, uint sublet_index)
uint meshlet_get_sublet_index(uint sublet_index)
{
if (gl_WorkGroupSize.y == 8)
return 8u * meshlet_index + sublet_index;
return sublet_index;
else
return 8u * meshlet_index + gl_WorkGroupSize.y * gl_WorkGroupID.x + sublet_index;
return gl_WorkGroupSize.y * gl_WorkGroupID.x + sublet_index;
}

void meshlet_emit_primitive(uvec3 prim, vec4 clip_pos, vec4 viewport)
Expand Down
36 changes: 20 additions & 16 deletions tests/assets/shaders/meshlet_debug.mesh
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ layout(set = 0, binding = 10) buffer Stats
uint vert;
} stats;

const uint STRIDE = 4; // TODO: Spec constant or push constant

void main()
{
uint compacted_meshlet_index = meshlet_get_meshlet_index() + 0x8000 * gl_DrawIDARB;
uint linear_index = gl_LocalInvocationIndex;

#if defined(MESHLET_RENDER_TASK_HIERARCHICAL) && !MESHLET_RENDER_TASK_HIERARCHICAL
CompactedDrawInfo task = mesh_payload.info;
Expand All @@ -91,35 +92,38 @@ void main()
CompactedDrawInfo task = mesh_payload.infos[compacted_meshlet_index];
#endif

const uint STRIDE = 4;
MeshletMetaRuntime meta = meshlet_metas_runtime.data[task.meshlet_index];
meta.stream_offset += STRIDE * gl_WorkGroupID.x;

mat4 M = transforms.data[task.node_offset];

uint lane_index;

uint linear_index, sublet_index;
if (gl_SubgroupSize == 32)
lane_index = gl_SubgroupInvocationID;
{
linear_index = gl_SubgroupInvocationID;
sublet_index = gl_SubgroupID;
}
else
lane_index = gl_LocalInvocationID.x;
{
linear_index = gl_LocalInvocationID.x;
sublet_index = gl_LocalInvocationID.y;
}

meshlet_setup_local_invocation(uvec2(lane_index, 0));
meshlet_setup_local_invocation(uvec2(linear_index, sublet_index));
MeshletMetaRuntime meta = meshlet_metas_runtime.data[task.meshlet_index];
meta.stream_offset += STRIDE * meshlet_get_sublet_index(sublet_index);

MeshletInfo info = meshlet_get_meshlet_info(meta.stream_offset);
uvec3 decoded_index_buffer = uvec3(0);
vec3 world_pos;
vec4 clip_pos = vec4(-1.0);

if (lane_index < info.primitive_count)
decoded_index_buffer = meshlet_decode_index_buffer(meta.stream_offset, lane_index);
if (linear_index < info.primitive_count)
decoded_index_buffer = meshlet_decode_index_buffer(meta.stream_offset, linear_index);

if (lane_index < info.vertex_count)
if (linear_index < info.vertex_count)
{
int exponent;
i16vec3 ipos = meshlet_decode_snorm_scaled_i16x3(
meta.stream_offset + MESHLET_STREAM_TYPE_POSITION,
lane_index, exponent);
linear_index, exponent);
vec3 pos = ldexp(vec3(ipos), ivec3(exponent));
world_pos = (M * vec4(pos, 1.0)).xyz;
clip_pos = VP * vec4(world_pos, 1.0);
Expand All @@ -135,10 +139,10 @@ void main()
bool t_sign;
u8vec4 nt = meshlet_decode_normal_tangent_oct8(
meta.stream_offset + MESHLET_STREAM_TYPE_NORMAL_TANGENT_OCT8,
lane_index, t_sign);
linear_index, t_sign);
i16vec2 uv = meshlet_decode_snorm_scaled_i16x2(
meta.stream_offset + MESHLET_STREAM_TYPE_UV,
lane_index, exponent);
linear_index, exponent);

#ifdef MESHLET_PRIMITIVE_CULL_SHARED_INDEX
shared_clip_pos[out_vert_index] = clip_pos;
Expand Down
23 changes: 13 additions & 10 deletions tests/assets/shaders/meshlet_debug_plain.mesh
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,20 @@ void main()
CompactedDrawInfo task = mesh_payload.infos[compacted_meshlet_index];
#endif

#if defined(MESHLET_PRIMITIVE_CULL_WAVE32) && MESHLET_PRIMITIVE_CULL_WAVE32
uint linear_index = gl_SubgroupInvocationID;
uint sublet_index = gl_SubgroupID;
#else
uint linear_index = gl_LocalInvocationID.x;
uint sublet_index = gl_LocalInvocationID.y;
#endif
uint linear_index, sublet_index;
if (gl_SubgroupSize == 32)
{
linear_index = gl_SubgroupInvocationID;
sublet_index = gl_SubgroupID;
}
else
{
linear_index = gl_LocalInvocationID.x;
sublet_index = gl_LocalInvocationID.y;
}

sublet_index = meshlet_get_sublet_index(task.meshlet_index, sublet_index);
meshlet_setup_local_invocation(uvec2(linear_index, sublet_index));
sublet_index = 8u * task.meshlet_index + meshlet_get_sublet_index(sublet_index);
IndirectDrawMesh meshlet = indirect_commands_mesh.draws[sublet_index];

mat4 M = transforms.data[task.node_offset];
Expand All @@ -137,8 +142,6 @@ void main()
vec3 world_pos = (M * vec4(pos, 1.0)).xyz;
vec4 clip_pos = VP * vec4(world_pos, 1.0);

meshlet_setup_local_invocation(gl_LocalInvocationID.xy);

uvec3 prim = uvec3(0);
if (linear_index < meshlet.primitive_count)
prim = uvec3(ibo.data[meshlet.primitive_offset + linear_index]);
Expand Down

0 comments on commit b890855

Please sign in to comment.