Skip to content

Commit

Permalink
Fix some bugs in meshlet viewer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed Jan 5, 2024
1 parent d3b10ff commit daae414
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
2 changes: 2 additions & 0 deletions tests/assets/shaders/meshlet_cull.comp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ layout(local_size_x = 32) in;
#if MESHLET_RENDER_PHASE == 2
#define MESHLET_RENDER_HIZ_BINDING 8
#endif
#if MESHLET_RENDER_PHASE >= 1
#define MESHLET_RENDER_OCCLUDER_BINDING 9
#endif
#define MESHLET_RENDER_TASKS_BINDING 2
#include "meshlet_render.h"

Expand Down
2 changes: 2 additions & 0 deletions tests/assets/shaders/meshlet_debug.mesh
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ void main()
vTangent[out_vert_index] = vec4(mat3(M) * NT[1].xyz, NT[1].w);
}

#if 0
if (gl_LocalInvocationIndex == 0)
{
atomicAdd(stats.invocations, gl_WorkGroupSize.x * gl_WorkGroupSize.y);
atomicAdd(stats.prim, shared_active_prim_count_total);
atomicAdd(stats.vert, shared_active_vert_count_total);
}
#endif
}
2 changes: 2 additions & 0 deletions tests/assets/shaders/meshlet_debug.task
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ layout(local_size_x = 32) in;
#if MESHLET_RENDER_PHASE == 2
#define MESHLET_RENDER_HIZ_BINDING 11
#endif
#if MESHLET_RENDER_PHASE >= 1
#define MESHLET_RENDER_OCCLUDER_BINDING 12
#endif

#include "meshlet_render.h"

Expand Down
2 changes: 2 additions & 0 deletions tests/assets/shaders/meshlet_debug_plain.mesh
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,12 @@ void main()
vDrawID[gl_LocalInvocationIndex] = task.meshlet_index;
}

#if 0
if (gl_LocalInvocationIndex == 0)
{
atomicAdd(stats.invocations, gl_WorkGroupSize.x * gl_WorkGroupSize.y);
atomicAdd(stats.prim, shared_active_prim_count_total);
atomicAdd(stats.vert, shared_active_vert_count_total);
}
#endif
}
37 changes: 25 additions & 12 deletions tests/meshlet_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,30 +1016,43 @@ struct MeshletViewerApplication : Granite::Application, Granite::EventHandler //
auto encoding = device.get_resource_manager().get_mesh_encoding();
if (encoding != ResourceManager::MeshEncoding::Classic)
{
if (readback_fence[readback_index] &&
readback_ring_phase1[readback_index] &&
readback_ring_phase2[readback_index])
if (readback_fence[readback_index])
{
readback_fence[readback_index]->wait();

auto *mapped1 = static_cast<const uint32_t *>(
device.map_host_buffer(*readback_ring_phase1[readback_index],
MEMORY_ACCESS_READ_BIT));
auto *mapped2 = static_cast<const uint32_t *>(
device.map_host_buffer(*readback_ring_phase2[readback_index],
MEMORY_ACCESS_READ_BIT));
auto &ring1 = readback_ring_phase1[readback_index];
auto &ring2 = readback_ring_phase2[readback_index];

auto *mapped1 = ring1 ? static_cast<const uint32_t *>(
device.map_host_buffer(*ring1, MEMORY_ACCESS_READ_BIT)) : nullptr;
auto *mapped2 = ring2 ? static_cast<const uint32_t *>(
device.map_host_buffer(*ring2, MEMORY_ACCESS_READ_BIT)) : nullptr;

if (encoding != ResourceManager::MeshEncoding::VBOAndIBOMDI)
{
last_mesh_invocations = mapped1[0] + mapped2[0];
last_prim = mapped1[1] + mapped2[1];
last_vert = mapped1[2] + mapped2[2];
last_mesh_invocations = 0;
last_prim = 0;
last_vert = 0;

const auto accum_draws = [&](const uint32_t *mapped) {
if (mapped)
{
last_mesh_invocations += mapped[0];
last_prim += mapped[1];
last_vert += mapped[2];
}
};

accum_draws(mapped1);
accum_draws(mapped2);
}
else
{
last_mesh_invocations = 0;

const auto accum_draws = [&](const uint32_t *mapped) {
if (!mapped)
return;
uint32_t draws = mapped[0];
mapped += 256 / sizeof(uint32_t);

Expand Down

0 comments on commit daae414

Please sign in to comment.