-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added debug visualization for intermediate render targets
- Loading branch information
1 parent
0905db1
commit b26080b
Showing
13 changed files
with
447 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/*************************************************************************** | ||
# Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# NVIDIA CORPORATION and its licensors retain all intellectual property | ||
# and proprietary rights in and to this software, related documentation | ||
# and any modifications thereto. Any use, reproduction, disclosure or | ||
# distribution of this software and related documentation without an express | ||
# license agreement from NVIDIA CORPORATION is strictly prohibited. | ||
**************************************************************************/ | ||
|
||
#ifndef PACKED_NORMAL_HLSL | ||
#define PACKED_NORMAL_HLSL | ||
|
||
#include "../ShaderParameters.h" | ||
|
||
#include <donut/shaders/utils.hlsli> | ||
|
||
Texture2D<uint> t_Normals : register(t0); | ||
RWTexture2D<float4> t_Output : register(u0); | ||
|
||
[numthreads(16, 16, 1)] | ||
void main(uint2 pixelPosition : SV_DispatchThreadID) | ||
{ | ||
uint packedNormal = t_Normals[pixelPosition]; | ||
float3 unpackedNormal = octToNdirUnorm32(packedNormal); | ||
t_Output[pixelPosition] = float4(unpackedNormal, 1.0); | ||
} | ||
|
||
#endif // PACKED_NORMAL_HLSL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/*************************************************************************** | ||
# Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# NVIDIA CORPORATION and its licensors retain all intellectual property | ||
# and proprietary rights in and to this software, related documentation | ||
# and any modifications thereto. Any use, reproduction, disclosure or | ||
# distribution of this software and related documentation without an express | ||
# license agreement from NVIDIA CORPORATION is strictly prohibited. | ||
**************************************************************************/ | ||
|
||
#ifndef PACKED_NORMAL_HLSL | ||
#define PACKED_NORMAL_HLSL | ||
|
||
#include "../ShaderParameters.h" | ||
|
||
#include <donut/shaders/packing.hlsli> | ||
|
||
Texture2D<uint> t_PackedVecs : register(t0); | ||
RWTexture2D<float4> t_Output : register(u0); | ||
|
||
[numthreads(16, 16, 1)] | ||
void main(uint2 pixelPosition : SV_DispatchThreadID) | ||
{ | ||
uint packedVec = t_PackedVecs[pixelPosition]; | ||
float3 unpackedVec = Unpack_R11G11B10_UFLOAT(packedVec); | ||
t_Output[pixelPosition] = float4(unpackedVec, 1.0); | ||
} | ||
|
||
#endif // PACKED_NORMAL_HLSL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/*************************************************************************** | ||
# Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# NVIDIA CORPORATION and its licensors retain all intellectual property | ||
# and proprietary rights in and to this software, related documentation | ||
# and any modifications thereto. Any use, reproduction, disclosure or | ||
# distribution of this software and related documentation without an express | ||
# license agreement from NVIDIA CORPORATION is strictly prohibited. | ||
**************************************************************************/ | ||
|
||
#ifndef PACKED_NORMAL_HLSL | ||
#define PACKED_NORMAL_HLSL | ||
|
||
#include "../ShaderParameters.h" | ||
|
||
#include <donut/shaders/packing.hlsli> | ||
|
||
Texture2D<uint> t_PackedVecs : register(t0); | ||
RWTexture2D<float4> t_Output : register(u0); | ||
|
||
[numthreads(16, 16, 1)] | ||
void main(uint2 pixelPosition : SV_DispatchThreadID) | ||
{ | ||
uint packedVec = t_PackedVecs[pixelPosition]; | ||
float4 unpackedVec = Unpack_R8G8B8A8_Gamma_UFLOAT(packedVec); | ||
t_Output[pixelPosition] = unpackedVec; | ||
} | ||
|
||
#endif // PACKED_NORMAL_HLSL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "DebugVizPasses.h" | ||
|
||
#include "../RenderTargets.h" | ||
|
||
DebugVizPasses::DebugVizPasses( | ||
nvrhi::IDevice* device, | ||
std::shared_ptr<donut::engine::ShaderFactory> shaderFactory, | ||
std::shared_ptr<donut::engine::Scene> scene, | ||
nvrhi::IBindingLayout* bindlessLayout) : | ||
m_GBufferNormalsViz(std::make_unique<PackedDataVizPass>(device, shaderFactory, scene, bindlessLayout)), | ||
m_GBufferGeoNormalsViz(std::make_unique<PackedDataVizPass>(device, shaderFactory, scene, bindlessLayout)), | ||
m_GBufferDiffuseAlbedoViz(std::make_unique<PackedDataVizPass>(device, shaderFactory, scene, bindlessLayout)), | ||
m_GBufferSpecularRoughnessViz(std::make_unique<PackedDataVizPass>(device, shaderFactory, scene, bindlessLayout)) | ||
{ | ||
|
||
} | ||
|
||
void DebugVizPasses::CreatePipelines() | ||
{ | ||
m_GBufferNormalsViz->CreatePipeline("app/DebugViz/NDirOctUNorm32Viz.hlsl"); | ||
m_GBufferGeoNormalsViz->CreatePipeline("app/DebugViz/NDirOctUNorm32Viz.hlsl"); | ||
m_GBufferDiffuseAlbedoViz->CreatePipeline("app/DebugViz/PackedR11G11B10UFloatViz.hlsl"); | ||
m_GBufferSpecularRoughnessViz->CreatePipeline("app/DebugViz/PackedR8G8B8A8GammaUFloatViz.hlsl"); | ||
} | ||
|
||
void DebugVizPasses::CreateBindingSets(RenderTargets& renderTargets, nvrhi::TextureHandle dst) | ||
{ | ||
m_GBufferNormalsViz->CreateBindingSet(renderTargets.GBufferNormals, renderTargets.PrevGBufferNormals, renderTargets.DebugColor); | ||
m_GBufferGeoNormalsViz->CreateBindingSet(renderTargets.GBufferGeoNormals, renderTargets.PrevGBufferGeoNormals, renderTargets.DebugColor); | ||
m_GBufferDiffuseAlbedoViz->CreateBindingSet(renderTargets.GBufferDiffuseAlbedo, renderTargets.PrevGBufferDiffuseAlbedo, renderTargets.DebugColor); | ||
m_GBufferSpecularRoughnessViz->CreateBindingSet(renderTargets.GBufferSpecularRough, renderTargets.PrevGBufferSpecularRough, renderTargets.DebugColor); | ||
} | ||
|
||
void DebugVizPasses::RenderUnpackedNormals(nvrhi::ICommandList* commandList, const donut::engine::IView& view) | ||
{ | ||
m_GBufferNormalsViz->Render(commandList, view); | ||
} | ||
|
||
void DebugVizPasses::RenderUnpackedGeoNormals(nvrhi::ICommandList* commandList, const donut::engine::IView& view) | ||
{ | ||
m_GBufferGeoNormalsViz->Render(commandList, view); | ||
} | ||
|
||
void DebugVizPasses::RenderUnpackedDiffuseAlbeo(nvrhi::ICommandList* commandList, const donut::engine::IView& view) | ||
{ | ||
m_GBufferDiffuseAlbedoViz->Render(commandList, view); | ||
} | ||
|
||
void DebugVizPasses::RenderUnpackedSpecularRoughness(nvrhi::ICommandList* commandList, const donut::engine::IView& view) | ||
{ | ||
m_GBufferSpecularRoughnessViz->Render(commandList, view); | ||
} | ||
|
||
void DebugVizPasses::NextFrame() | ||
{ | ||
m_GBufferNormalsViz->NextFrame(); | ||
m_GBufferGeoNormalsViz->NextFrame(); | ||
m_GBufferDiffuseAlbedoViz->NextFrame(); | ||
m_GBufferSpecularRoughnessViz->NextFrame(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include "PackedDataVizPass.h" | ||
|
||
class DebugVizPasses | ||
{ | ||
public: | ||
DebugVizPasses( | ||
nvrhi::IDevice* device, | ||
std::shared_ptr<donut::engine::ShaderFactory> shaderFactory, | ||
std::shared_ptr<donut::engine::Scene> scene, | ||
nvrhi::IBindingLayout* bindlessLayout); | ||
|
||
void CreatePipelines(); | ||
|
||
void CreateBindingSets(RenderTargets& renderTargets, nvrhi::TextureHandle dst); | ||
|
||
void RenderUnpackedNormals(nvrhi::ICommandList* commandList, const donut::engine::IView& view); | ||
void RenderUnpackedGeoNormals(nvrhi::ICommandList* commandList, const donut::engine::IView& view); | ||
void RenderUnpackedDiffuseAlbeo(nvrhi::ICommandList* commandList, const donut::engine::IView& view); | ||
void RenderUnpackedSpecularRoughness(nvrhi::ICommandList* commandList, const donut::engine::IView& view); | ||
|
||
void NextFrame(); | ||
|
||
private: | ||
std::unique_ptr<PackedDataVizPass> m_GBufferNormalsViz; | ||
std::unique_ptr<PackedDataVizPass> m_GBufferGeoNormalsViz; | ||
std::unique_ptr<PackedDataVizPass> m_GBufferDiffuseAlbedoViz; | ||
std::unique_ptr<PackedDataVizPass> m_GBufferSpecularRoughnessViz; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include "PackedDataVizPass.h" | ||
|
||
#include "../RenderTargets.h" | ||
#include "../SampleScene.h" | ||
#include "../UserInterface.h" | ||
|
||
#include <donut/engine/ShaderFactory.h> | ||
#include <donut/engine/View.h> | ||
#include <donut/engine/Scene.h> | ||
#include <donut/engine/CommonRenderPasses.h> | ||
#include <donut/core/log.h> | ||
#include <nvrhi/utils.h> | ||
|
||
#include <utility> | ||
|
||
using namespace donut::math; | ||
using namespace donut::engine; | ||
|
||
PackedDataVizPass::PackedDataVizPass( | ||
nvrhi::IDevice* device, | ||
std::shared_ptr<donut::engine::ShaderFactory> shaderFactory, | ||
std::shared_ptr<donut::engine::Scene> scene, | ||
nvrhi::IBindingLayout* bindlessLayout) : | ||
m_Device(device) | ||
, m_BindlessLayout(bindlessLayout) | ||
, m_ShaderFactory(std::move(shaderFactory)) | ||
, m_Scene(std::move(scene)) | ||
{ | ||
nvrhi::BindingLayoutDesc bindingLayoutDesc; | ||
bindingLayoutDesc.visibility = nvrhi::ShaderType::Compute; | ||
bindingLayoutDesc.bindings = { | ||
nvrhi::BindingLayoutItem::Texture_SRV(0), | ||
nvrhi::BindingLayoutItem::Texture_UAV(0), | ||
}; | ||
|
||
m_BindingLayout = m_Device->createBindingLayout(bindingLayoutDesc); | ||
} | ||
|
||
void PackedDataVizPass::CreatePipeline(const std::string& shaderPath) | ||
{ | ||
std::string debugMsg = "Initializing PackedDataVizPass with " + shaderPath + "..."; | ||
donut::log::debug(debugMsg.c_str()); | ||
gpuPerfMarker = "Packed Data Viz Pass:" + shaderPath; | ||
|
||
m_ComputeShader = m_ShaderFactory->CreateShader(shaderPath.c_str(), "main", nullptr, nvrhi::ShaderType::Compute); | ||
|
||
nvrhi::ComputePipelineDesc pipelineDesc; | ||
pipelineDesc.bindingLayouts = { m_BindingLayout, m_BindlessLayout }; | ||
pipelineDesc.CS = m_ComputeShader; | ||
m_ComputePipeline = m_Device->createComputePipeline(pipelineDesc); | ||
} | ||
|
||
void PackedDataVizPass::CreateBindingSet(nvrhi::TextureHandle src, nvrhi::TextureHandle prevSrc, nvrhi::TextureHandle dst) | ||
{ | ||
nvrhi::BindingSetDesc bindingSetDesc; | ||
|
||
bindingSetDesc.bindings = { | ||
// GBuffer bindings --- CAUTION: these items are addressed below to swap the even and odd frames | ||
nvrhi::BindingSetItem::Texture_SRV(0, src), | ||
nvrhi::BindingSetItem::Texture_UAV(0, dst) | ||
}; | ||
|
||
m_BindingSetEven = m_Device->createBindingSet(bindingSetDesc, m_BindingLayout); | ||
|
||
bindingSetDesc.bindings[0].resourceHandle = prevSrc; | ||
|
||
m_BindingSetOdd = m_Device->createBindingSet(bindingSetDesc, m_BindingLayout); | ||
} | ||
|
||
void PackedDataVizPass::Render( | ||
nvrhi::ICommandList* commandList, | ||
const donut::engine::IView& view) | ||
{ | ||
commandList->beginMarker(gpuPerfMarker.c_str()); | ||
|
||
nvrhi::ComputeState state; | ||
state.bindings = { m_BindingSetEven, m_Scene->GetDescriptorTable() }; | ||
state.pipeline = m_ComputePipeline; | ||
commandList->setComputeState(state); | ||
|
||
commandList->dispatch( | ||
dm::div_ceil(view.GetViewExtent().width(), 16), | ||
dm::div_ceil(view.GetViewExtent().height(), 16), | ||
1); | ||
|
||
commandList->endMarker(); | ||
} | ||
|
||
void PackedDataVizPass::NextFrame() | ||
{ | ||
std::swap(m_BindingSetEven, m_BindingSetOdd); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#pragma once | ||
|
||
#include <nvrhi/nvrhi.h> | ||
#include <memory> | ||
|
||
namespace donut::engine | ||
{ | ||
class Scene; | ||
class CommonRenderPasses; | ||
class ShaderFactory; | ||
class IView; | ||
} | ||
|
||
class RenderTargets; | ||
class EnvironmentLight; | ||
struct UIData; | ||
|
||
class PackedDataVizPass | ||
{ | ||
private: | ||
nvrhi::DeviceHandle m_Device; | ||
|
||
nvrhi::ShaderHandle m_ComputeShader; | ||
nvrhi::ComputePipelineHandle m_ComputePipeline; | ||
nvrhi::BindingLayoutHandle m_BindingLayout; | ||
nvrhi::BindingLayoutHandle m_BindlessLayout; | ||
nvrhi::BindingSetHandle m_BindingSetEven; | ||
nvrhi::BindingSetHandle m_BindingSetOdd; | ||
|
||
nvrhi::BufferHandle m_ConstantBuffer; | ||
|
||
std::shared_ptr<donut::engine::ShaderFactory> m_ShaderFactory; | ||
std::shared_ptr<donut::engine::Scene> m_Scene; | ||
std::string gpuPerfMarker; | ||
|
||
public: | ||
PackedDataVizPass( | ||
nvrhi::IDevice* device, | ||
std::shared_ptr<donut::engine::ShaderFactory> shaderFactory, | ||
std::shared_ptr<donut::engine::Scene> scene, | ||
nvrhi::IBindingLayout* bindlessLayout); | ||
|
||
void CreatePipeline(const std::string& shaderPath); | ||
|
||
void CreateBindingSet(nvrhi::TextureHandle src, nvrhi::TextureHandle prevSrc, nvrhi::TextureHandle dst); | ||
|
||
void Render( | ||
nvrhi::ICommandList* commandList, | ||
const donut::engine::IView& view); | ||
|
||
void NextFrame(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.