Skip to content

Commit

Permalink
Add radio button for debug pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelarius committed Mar 30, 2024
1 parent 92ae60c commit e6a4f7e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/pt/hybrid_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,41 @@ void HybridRenderer::render(
wgpuQueueSubmit(gpuContext.queue, 1, &cmdBuffer);
}

void HybridRenderer::renderDebug(
const GpuContext& gpuContext,
const glm::mat4& viewProjectionMat,
const WGPUTextureView textureView)
{
wgpuDeviceTick(gpuContext.device);

const WGPUCommandEncoder encoder = [&gpuContext]() {
const WGPUCommandEncoderDescriptor cmdEncoderDesc{
.nextInChain = nullptr,
.label = "Command encoder",
};
return wgpuDeviceCreateCommandEncoder(gpuContext.device, &cmdEncoderDesc);
}();

mGbufferPass.render(
gpuContext,
viewProjectionMat,
encoder,
mDepthTextureView,
mAlbedoTextureView,
mNormalTextureView);

mDebugPass.render(mGbufferBindGroup, encoder, textureView);

const WGPUCommandBuffer cmdBuffer = [encoder]() {
const WGPUCommandBufferDescriptor cmdBufferDesc{
.nextInChain = nullptr,
.label = "HybridRenderer command buffer",
};
return wgpuCommandEncoderFinish(encoder, &cmdBufferDesc);
}();
wgpuQueueSubmit(gpuContext.queue, 1, &cmdBuffer);
}

void HybridRenderer::resize(const GpuContext& gpuContext, const Extent2u& newSize)
{
NLRS_ASSERT(newSize.x > 0 && newSize.y > 0);
Expand Down
1 change: 1 addition & 0 deletions src/pt/hybrid_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class HybridRenderer
const glm::vec3& cameraPosition,
const Sky& sky,
WGPUTextureView targetTextureView);
void renderDebug(const GpuContext&, const glm::mat4&, WGPUTextureView);
void resize(const GpuContext&, const Extent2u&);

private:
Expand Down
9 changes: 9 additions & 0 deletions src/pt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum RendererType
{
RendererType_PathTracer,
RendererType_Hybrid,
RendererType_Debug,
};

struct UiState
Expand Down Expand Up @@ -313,6 +314,8 @@ try
ImGui::RadioButton("path tracer", &appState.ui.rendererType, RendererType_PathTracer);
ImGui::SameLine();
ImGui::RadioButton("hybrid", &appState.ui.rendererType, RendererType_Hybrid);
ImGui::SameLine();
ImGui::RadioButton("debug", &appState.ui.rendererType, RendererType_Debug);
ImGui::Separator();

ImGui::Text("Renderer stats");
Expand Down Expand Up @@ -439,6 +442,12 @@ try
textureBlitter.textureView());
break;
}
case RendererType_Debug:
{
const glm::mat4 viewProjectionMat = appState.cameraController.viewProjectionMatrix();
hybridRenderer.renderDebug(gpuContext, viewProjectionMat, textureBlitter.textureView());
break;
}
}
textureBlitter.render(gpuContext, gui, swapChain);
};
Expand Down

0 comments on commit e6a4f7e

Please sign in to comment.