Skip to content

Commit

Permalink
Improve shader reloading usability
Browse files Browse the repository at this point in the history
We now color-code R* marker in green when shaders got reloaded
successfully and in red when shader compilation failed.
  • Loading branch information
zeux committed Dec 20, 2024
1 parent d01a31a commit 6dcf754
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
32 changes: 23 additions & 9 deletions src/niagara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int debugGuiMode = 1;
int debugLodStep = 0;

bool reloadShaders = false;
uint32_t reloadShadersColor = 0xffffffff;
double reloadShadersTimer = 0;

VkSemaphore createSemaphore(VkDevice device)
Expand Down Expand Up @@ -1173,8 +1174,18 @@ int main(int argc, const char** argv)
VK_CHECK(vkDeviceWaitIdle(device));

pipelines();

reloadShadersColor = 0x00ff00;
}
else
{
reloadShadersColor = 0xffffff;
}
}
else
{
reloadShadersColor = 0xff0000;
}

reloadShadersTimer = glfwGetTime() + 1;
}
Expand Down Expand Up @@ -1804,16 +1815,16 @@ int main(int argc, const char** argv)

if (debugGuiMode % 3)
{
auto debugtext = [&](int line, const char* format, ...)
auto debugtext = [&](int line, uint32_t color, const char* format, ...)
#ifdef __GNUC__
__attribute__((format(printf, 3, 4)))
__attribute__((format(printf, 4, 5)))
#endif
{
TextData textData = {};
textData.offsetX = 1;
textData.offsetY = line + 1;
textData.scale = 2;
textData.color = 0xffffffff;
textData.color = color;

va_list args;
va_start(args, format);
Expand Down Expand Up @@ -1856,26 +1867,29 @@ int main(int argc, const char** argv)
double trianglesPerSec = double(triangleCount) / double(frameGpuAvg * 1e-3);
double drawsPerSec = double(draws.size()) / double(frameGpuAvg * 1e-3);

debugtext(0, "%scpu: %.2f ms; gpu: %.2f ms", reloadShaders ? "R* " : "", frameCpuAvg, frameGpuAvg);
debugtext(0, ~0u, "%scpu: %.2f ms; gpu: %.2f ms", reloadShaders ? " " : "", frameCpuAvg, frameGpuAvg);

if (reloadShaders)
debugtext(0, reloadShadersColor, "R*");

if (debugGuiMode % 3 == 2)
{
debugtext(2, "cull: %.2f ms, pyramid: %.2f ms, render: %.2f ms, shadows: %.2f ms, shadow blur: %.2f ms, final: %.2f ms",
debugtext(2, ~0u, "cull: %.2f ms, pyramid: %.2f ms, render: %.2f ms, shadows: %.2f ms, shadow blur: %.2f ms, final: %.2f ms",
cullGpuTime + culllateGpuTime + cullpostGpuTime,
pyramidGpuTime,
renderGpuTime + renderlateGpuTime + renderpostGpuTime,
shadowsGpuTime, shadowblurGpuTime,
finalGpuTime);
debugtext(3, "triangles %.2fM; %.1fB tri / sec, %.1fM draws / sec",
debugtext(3, ~0u, "triangles %.2fM; %.1fB tri / sec, %.1fM draws / sec",
double(triangleCount) * 1e-6, trianglesPerSec * 1e-9, drawsPerSec * 1e-6);

debugtext(5, "frustum culling %s, occlusion culling %s, level-of-detail %s",
debugtext(5, ~0u, "frustum culling %s, occlusion culling %s, level-of-detail %s",
cullingEnabled ? "ON" : "OFF", occlusionEnabled ? "ON" : "OFF", lodEnabled ? "ON" : "OFF");
debugtext(6, "mesh shading %s, task shading %s, cluster occlusion culling %s",
debugtext(6, ~0u, "mesh shading %s, task shading %s, cluster occlusion culling %s",
taskSubmit ? "ON" : "OFF", taskSubmit && taskShadingEnabled ? "ON" : "OFF",
clusterOcclusionEnabled ? "ON" : "OFF");

debugtext(8, "RT shading %s, shadow blur %s, shadow quality %d, shadow checkerboard %s",
debugtext(8, ~0u, "RT shading %s, shadow blur %s, shadow quality %d, shadow checkerboard %s",
raytracingSupported && shadingEnabled ? "ON" : "OFF",
raytracingSupported && shadingEnabled && shadowblurEnabled ? "ON" : "OFF",
shadowQuality, shadowCheckerboard ? "ON" : "OFF");
Expand Down
4 changes: 2 additions & 2 deletions src/shaders/debugtext.comp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ void main()
if ((texbit0 | texbit1) == 0)
return;

vec4 color = texbit1 == 1 ? unpackUnorm4x8(text.color) : vec4(0.0);
vec3 color = texbit1 == 1 ? unpackUnorm4x8(text.color).bgr : vec3(0.0);

for (int y = 0; y < text.scale; ++y)
for (int x = 0; x < text.scale; ++x)
imageStore(outImage, (text.offset * size + pos) * text.scale + ivec2(x, y), color);
imageStore(outImage, (text.offset * size + pos) * text.scale + ivec2(x, y), vec4(color, 1.0));
}

0 comments on commit 6dcf754

Please sign in to comment.