Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,58 @@
<ClCompile Include="SampleCore\util\Win32Application.cpp" />
</ItemGroup>
<ItemGroup>
<FxCompile Include="RTAO\Shaders\Denoising\CalculateMeanVarianceCS_WaveReadLaneAt.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Compute</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">6.3</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">6.3</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Compute</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">6.3</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">6.3</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">Compute</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Profile|ARM64'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">6.3</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Profile|ARM64'">6.3</ShaderModel>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)CompiledShaders\%(Filename).hlsl.h</HeaderFileOutput>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(IntDir)CompiledShaders\%(Filename).hlsl.h</HeaderFileOutput>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)CompiledShaders\%(Filename).hlsl.h</HeaderFileOutput>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(IntDir)CompiledShaders\%(Filename).hlsl.h</HeaderFileOutput>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">$(IntDir)CompiledShaders\%(Filename).hlsl.h</HeaderFileOutput>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Profile|ARM64'">$(IntDir)CompiledShaders\%(Filename).hlsl.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">g_p%(Filename)</VariableName>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">g_p%(Filename)</VariableName>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">g_p%(Filename)</VariableName>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">g_p%(Filename)</VariableName>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">g_p%(Filename)</VariableName>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Profile|ARM64'">g_p%(Filename)</VariableName>
</FxCompile>
<FxCompile Include="RTAO\Shaders\Denoising\DisocclusionBlur3x3CS_WaveReadLaneAt.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Compute</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">6.3</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">6.3</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Compute</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">6.3</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">6.3</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">Compute</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Profile|ARM64'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">6.3</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Profile|ARM64'">6.3</ShaderModel>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)CompiledShaders\%(Filename).hlsl.h</HeaderFileOutput>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(IntDir)CompiledShaders\%(Filename).hlsl.h</HeaderFileOutput>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)CompiledShaders\%(Filename).hlsl.h</HeaderFileOutput>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(IntDir)CompiledShaders\%(Filename).hlsl.h</HeaderFileOutput>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">$(IntDir)CompiledShaders\%(Filename).hlsl.h</HeaderFileOutput>
<HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Profile|ARM64'">$(IntDir)CompiledShaders\%(Filename).hlsl.h</HeaderFileOutput>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">g_p%(Filename)</VariableName>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">g_p%(Filename)</VariableName>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">g_p%(Filename)</VariableName>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">g_p%(Filename)</VariableName>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">g_p%(Filename)</VariableName>
<VariableName Condition="'$(Configuration)|$(Platform)'=='Profile|ARM64'">g_p%(Filename)</VariableName>
</FxCompile>
<FxCompile Include="RTAO\Shaders\Denoising\CalculateMeanVarianceCS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Compute</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Compute</ShaderType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@
<FxCompile Include="RTAO\Shaders\Denoising\DisocclusionBlur3x3CS.hlsl">
<Filter>Shaders\RTAO\Denoising\Filtering</Filter>
</FxCompile>
<FxCompile Include="RTAO\Shaders\Denoising\CalculateMeanVarianceCS_WaveReadLaneAt.hlsl">
<Filter>Shaders\RTAO\Denoising\Filtering</Filter>
</FxCompile>
<FxCompile Include="RTAO\Shaders\Denoising\DisocclusionBlur3x3CS_WaveReadLaneAt.hlsl">
<Filter>Shaders\RTAO\Denoising\Filtering</Filter>
</FxCompile>
<FxCompile Include="RTAO\Shaders\Denoising\EdgeStoppingFilter_Gaussian3x3CS.hlsl">
<Filter>Shaders\RTAO\Denoising\Filtering</Filter>
</FxCompile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "Denoiser.h"
#include "D3D12RaytracingRealTimeDenoisedAmbientOcclusion.h"
#include "Composition.h"
#include "DirectXRaytracingHelper.h"

using namespace std;
using namespace DX;
Expand Down Expand Up @@ -67,6 +68,16 @@ namespace Denoiser_Args
const WCHAR* Modes[RTAOGpuKernels::AtrousWaveletTransformCrossBilateralFilter::FilterType::Count] = { L"3x3", L"5x5" };
EnumVar Mode(L"Render/AO/Denoising/Fullscreen blur/Kernel", RTAOGpuKernels::AtrousWaveletTransformCrossBilateralFilter::FilterType::EdgeStoppingGaussian3x3, RTAOGpuKernels::AtrousWaveletTransformCrossBilateralFilter::FilterType::Count, Modes);

// Row-exchange implementation used by the mean/variance and disocclusion-blur compute shaders:
// - Groupshared: portable, correct on any device (default).
// - Wave intrinsics: faster, but relies on a wave width >= 16 AND threads being packed to
// lanes in row-major SV_GroupIndex order (not guaranteed by HLSL). This option is limited
// to Groupshared only on devices that can't run the wave path (see
// Denoiser::CreateAuxilaryDeviceResources).
namespace WaveFilterPath { enum Enum { Groupshared = 0, WaveIntrinsics, Count }; }
const WCHAR* WaveFilterPathNames[WaveFilterPath::Count] = { L"Groupshared (portable)", L"Wave intrinsics (fast)" };
EnumVar FilterRowExchange(L"Render/AO/Denoising/Filter row exchange", WaveFilterPath::Groupshared, WaveFilterPath::Count, WaveFilterPathNames);

}


Expand Down Expand Up @@ -105,6 +116,14 @@ void Denoiser::CreateAuxilaryDeviceResources()
m_atrousWaveletTransformFilter.Initialize(device, Sample::FrameCount);
m_calculateMeanVarianceKernel.Initialize(device, Sample::FrameCount);
m_disocclusionBlurKernel.Initialize(device, Sample::FrameCount, c_MaxNumDisocllusionBlurPasses);

// If the device can't run the wave-intrinsic filter path (needs wave ops + wave width >= 16),
// restrict the "Filter row exchange" UI option to the portable groupshared path only.
if (!SupportsWaveIntrinsicDenoiserFilterPath(device))
{
Denoiser_Args::FilterRowExchange.SetValue(Denoiser_Args::WaveFilterPath::Groupshared);
Denoiser_Args::FilterRowExchange.SetListLength(1);
}
}


Expand Down Expand Up @@ -291,7 +310,8 @@ void Denoiser::TemporalSupersamplingBlendWithCurrentFrame(RTAO& rtao)
m_localMeanVarianceResources[AOVarianceResource::Raw].gpuDescriptorWriteAccess,
Denoiser_Args::Variance_BilateralFilterKernelWidth,
isCheckerboardSamplingEnabled,
checkerboardLoadEvenPixels);
checkerboardLoadEvenPixels,
Denoiser_Args::FilterRowExchange == Denoiser_Args::WaveFilterPath::WaveIntrinsics);

// Interpolate the variance for the inactive cells from the valid checherkboard cells.
if (isCheckerboardSamplingEnabled)
Expand Down Expand Up @@ -421,7 +441,8 @@ void Denoiser::BlurDisocclusions(Pathtracer& pathtracer)
m_cbvSrvUavHeap->GetHeap(),
GBufferResources[GBufferResource::Depth].gpuDescriptorReadAccess,
m_disocclusionBlurStrength.gpuDescriptorReadAccess,
inOutResource);
inOutResource,
Denoiser_Args::FilterRowExchange == Denoiser_Args::WaveFilterPath::WaveIntrinsics);
filterStep *= 2;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "CompiledShaders\CountingSort_SortRays_64x128rayGroupCS.hlsl.h"
#include "CompiledShaders\AORayGenCS.hlsl.h"
#include "CompiledShaders\DisocclusionBlur3x3CS.hlsl.h"
#include "CompiledShaders\CalculateMeanVarianceCS_WaveReadLaneAt.hlsl.h"
#include "CompiledShaders\DisocclusionBlur3x3CS_WaveReadLaneAt.hlsl.h"
#include "CompiledShaders\FillInCheckerboard_CrossBox4TapFilterCS.hlsl.h"

using namespace std;
Expand Down Expand Up @@ -180,6 +182,19 @@ namespace RTAOGpuKernels
m_pipelineStateObject->SetName(L"Pipeline state object: DisocclusionBilateralFilter");
}

// Optionally create the wave-intrinsic fast-path pipeline state (see Run()); only used on
// devices with wave ops and a wave width >= 16, otherwise the groupshared default is used.
m_waveReadLanePathSupported = SupportsWaveIntrinsicDenoiserFilterPath(device);
if (m_waveReadLanePathSupported)
{
D3D12_COMPUTE_PIPELINE_STATE_DESC descComputePSO = {};
descComputePSO.pRootSignature = m_rootSignature.Get();
descComputePSO.CS = CD3DX12_SHADER_BYTECODE(static_cast<const void*>(g_pDisocclusionBlur3x3CS_WaveReadLaneAt), ARRAYSIZE(g_pDisocclusionBlur3x3CS_WaveReadLaneAt));

ThrowIfFailed(device->CreateComputePipelineState(&descComputePSO, IID_PPV_ARGS(&m_pipelineStateObjectWaveReadLane)));
m_pipelineStateObjectWaveReadLane->SetName(L"Pipeline state object: DisocclusionBilateralFilter (wave read-lane)");
}

// Create shader resources
{
m_CB.Create(device, frameCount * numCallsPerFrame, L"Constant Buffer: DisocclusionBilateralFilter");
Expand All @@ -194,7 +209,8 @@ namespace RTAOGpuKernels
ID3D12DescriptorHeap* descriptorHeap,
D3D12_GPU_DESCRIPTOR_HANDLE inputDepthResourceHandle,
D3D12_GPU_DESCRIPTOR_HANDLE inputBlurStrengthResourceHandle,
GpuResource* inputOutputResource)
GpuResource* inputOutputResource,
bool useWaveReadLanePath)
{
using namespace RootSignature::DisocclusionBilateralFilter;
using namespace DefaultComputeShaderParams;
Expand Down Expand Up @@ -222,7 +238,8 @@ namespace RTAOGpuKernels
commandList->SetComputeRootDescriptorTable(Slot::Debug1, debugResources[0].gpuDescriptorWriteAccess);
commandList->SetComputeRootDescriptorTable(Slot::Debug2, debugResources[1].gpuDescriptorWriteAccess);

commandList->SetPipelineState(m_pipelineStateObject.Get());
const bool runWaveReadLanePath = useWaveReadLanePath && m_waveReadLanePathSupported && m_pipelineStateObjectWaveReadLane;
commandList->SetPipelineState((runWaveReadLanePath ? m_pipelineStateObjectWaveReadLane : m_pipelineStateObject).Get());
}

// Account for interleaved Group execution
Expand Down Expand Up @@ -447,6 +464,20 @@ namespace RTAOGpuKernels
m_pipelineStateObject->SetName(L"Pipeline state object: CalculateMeanVariance");
}

// Optionally create the wave-intrinsic fast-path pipeline state. It is only selected at
// run time on devices that report support (wave ops + wave width >= 16); otherwise the
// portable groupshared pipeline state above is always used (see Run()).
m_waveReadLanePathSupported = SupportsWaveIntrinsicDenoiserFilterPath(device);
if (m_waveReadLanePathSupported)
{
D3D12_COMPUTE_PIPELINE_STATE_DESC descComputePSO = {};
descComputePSO.pRootSignature = m_rootSignature.Get();
descComputePSO.CS = CD3DX12_SHADER_BYTECODE(static_cast<const void*>(g_pCalculateMeanVarianceCS_WaveReadLaneAt), ARRAYSIZE(g_pCalculateMeanVarianceCS_WaveReadLaneAt));

ThrowIfFailed(device->CreateComputePipelineState(&descComputePSO, IID_PPV_ARGS(&m_pipelineStateObjectWaveReadLane)));
m_pipelineStateObjectWaveReadLane->SetName(L"Pipeline state object: CalculateMeanVariance (wave read-lane)");
}

// Create shader resources.
{
m_CB.Create(device, frameCount * numCallsPerFrame, L"Constant Buffer: CalculateMeanVariance");
Expand All @@ -463,7 +494,8 @@ namespace RTAOGpuKernels
D3D12_GPU_DESCRIPTOR_HANDLE outputMeanVarianceResourceHandle,
UINT kernelWidth,
bool doCheckerboardSampling,
bool checkerboardLoadEvenPixels)
bool checkerboardLoadEvenPixels,
bool useWaveReadLanePath)
{
using namespace RootSignature::CalculateMeanVariance;
using namespace DefaultComputeShaderParams;
Expand All @@ -476,7 +508,8 @@ namespace RTAOGpuKernels
{
commandList->SetDescriptorHeaps(1, &descriptorHeap);
commandList->SetComputeRootSignature(m_rootSignature.Get());
commandList->SetPipelineState(m_pipelineStateObject.Get());
const bool runWaveReadLanePath = useWaveReadLanePath && m_waveReadLanePathSupported && m_pipelineStateObjectWaveReadLane;
commandList->SetPipelineState((runWaveReadLanePath ? m_pipelineStateObjectWaveReadLane : m_pipelineStateObject).Get());
commandList->SetComputeRootDescriptorTable(Slot::Input, inputValuesResourceHandle);
commandList->SetComputeRootDescriptorTable(Slot::OutputMeanVariance, outputMeanVarianceResourceHandle);

Expand Down Expand Up @@ -1088,4 +1121,4 @@ namespace RTAOGpuKernels
XMUINT2 groupSize(CeilDivide(width, ThreadGroup::Width), CeilDivide(height, ThreadGroup::Height));
commandList->Dispatch(groupSize.x, groupSize.y, 1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@ namespace RTAOGpuKernels
ID3D12DescriptorHeap* descriptorHeap,
D3D12_GPU_DESCRIPTOR_HANDLE inputDepthResourceHandle,
D3D12_GPU_DESCRIPTOR_HANDLE inputBlurStrengthResourceHandle,
GpuResource* inputOutputResource);
GpuResource* inputOutputResource,
bool useWaveReadLanePath = false);

private:
ComPtr<ID3D12RootSignature> m_rootSignature;
ComPtr<ID3D12PipelineState> m_pipelineStateObject;
ComPtr<ID3D12PipelineState> m_pipelineStateObject; // portable groupshared path (default)
ComPtr<ID3D12PipelineState> m_pipelineStateObjectWaveReadLane; // optional wave-intrinsic fast path
bool m_waveReadLanePathSupported = false;

ConstantBuffer<FilterConstantBuffer> m_CB;
UINT m_CBinstanceID = 0;
Expand Down Expand Up @@ -171,11 +174,14 @@ namespace RTAOGpuKernels
D3D12_GPU_DESCRIPTOR_HANDLE outputMeanVarianceResourceHandle,
UINT kernelWidth,
bool doCheckerboardSampling = false,
bool checkerboardLoadEvenPixels = false);
bool checkerboardLoadEvenPixels = false,
bool useWaveReadLanePath = false);

private:
ComPtr<ID3D12RootSignature> m_rootSignature;
ComPtr<ID3D12PipelineState> m_pipelineStateObject;
ComPtr<ID3D12PipelineState> m_pipelineStateObject; // portable groupshared path (default)
ComPtr<ID3D12PipelineState> m_pipelineStateObjectWaveReadLane; // optional wave-intrinsic fast path
bool m_waveReadLanePathSupported = false;
ConstantBuffer<CalculateMeanVarianceConstantBuffer> m_CB;
UINT m_CBinstanceID = 0;
};
Expand Down
Loading