Skip to content

Commit

Permalink
FidelityFX SPD release v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aurolou committed May 5, 2020
1 parent 8370800 commit 0e82a6f
Show file tree
Hide file tree
Showing 35 changed files with 734 additions and 609 deletions.
101 changes: 35 additions & 66 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,88 +1,57 @@
variables:
SampleName: SPDSample
SolutionDirDX12: sample\build\DX12
SolutionDX12: SPDSample_DX12.sln
SolutionDirVK: sample\build\VK
SolutionVK: SPDSample_VK.sln
GIT_SUBMODULE_STRATEGY: normal

before_script:
- 'for /f "usebackq delims=" %%i in (`vswhere.exe -version "[15.0,16.0)" -products Microsoft.VisualStudio.Product.BuildTools -property installationPath`) do set MSBUILD_PATH=%%i'
- 'call "%MSBUILD_PATH%\VC\Auxiliary\Build\vcvars64.bat"'
- 'cd sample\build'
- 'call GenerateSolutions.bat -T v141'
- 'cd ..\..'

stages:
- build
- deploy

build d3d12 and vulkan sample release:
build_dx12:
tags:
- windows
- amd64
stage: deploy
except:
- tags
stage: build
script:
- echo Building "%SolutionVK%"
- cd %SolutionDirVK%
- 'msbuild.exe "%SolutionVK%" /p:Configuration=Release /p:Platform=x64'
- cd ../../..
- echo Building "%SolutionDX12%"
- cd %SolutionDirDX12%
- 'msbuild.exe "%SolutionDX12%" /p:Configuration=Release /p:Platform=x64'
- cd ../../..
- mkdir %SampleName%
- move sample\bin %SampleName%
- move sample\media %SampleName%
- move sample\README.md %SampleName%
- echo cd .\%SampleName%\bin\ > %SampleName%_VK.bat
- echo start %SampleName%_VK.exe >> %SampleName%_VK.bat
- echo cd .\%SampleName%\bin\ > %SampleName%_DX12.bat
- echo start %SampleName%_DX12.exe >> %SampleName%_DX12.bat
- 'cmake -S sample -B sample/build/DX12 -G "Visual Studio 15 2017" -A x64 -DGFX_API=DX12'
- 'cmake --build sample/build/DX12 --config Release'
artifacts:
name: "%SampleName%-%CI_COMMIT_REF_NAME%-%CI_COMMIT_SHORT_SHA%"
paths:
- "%SampleName%/bin/"
- "%SampleName%/media/"
- "%SampleName%/README.md"
- "%SampleName%_DX12.bat"
- "%SampleName%_VK.bat"
paths:
- sample/bin/

build_vk:
tags:
- windows
- amd64
stage: build
script:
- 'cmake -S sample -B sample/build/VK -G "Visual Studio 15 2017" -A x64 -DGFX_API=VK'
- 'cmake --build sample/build/VK --config Release'
artifacts:
paths:
- sample/bin/

build d3d12 and vulkan sample release tagged:
package_sample:
tags:
- windows
- amd64
stage: deploy
only:
- tags
dependencies:
- build_dx12
- build_vk
script:
- echo Building "%SolutionVK%"
- cd %SolutionDirVK%
- 'msbuild.exe "%SolutionVK%" /p:Configuration=Release /p:Platform=x64'
- cd ../../..
- echo Building "%SolutionDX12%"
- cd %SolutionDirDX12%
- 'msbuild.exe "%SolutionDX12%" /p:Configuration=Release /p:Platform=x64'
- cd ../../..
- mkdir %SampleName%
- move sample\bin %SampleName%
- move sample\media %SampleName%
- move sample\README.md %SampleName%
- move sample\screenshot.png %SampleName%
- move NOTICES.txt %SampleName%
- echo cd .\%SampleName%\bin\ > %SampleName%_VK.bat
- echo start %SampleName%_VK.exe >> %SampleName%_VK.bat
- echo cd .\%SampleName%\bin\ > %SampleName%_DX12.bat
- echo start %SampleName%_DX12.exe >> %SampleName%_DX12.bat
- echo "Packaging build"
- copy %VULKAN_SDK%\Bin\glslc.exe .\sample\bin
- echo cd .\sample\bin\ > %SampleName%_VK.bat
- echo start %SampleName%_VK.exe >> %SampleName%_VK.bat
- echo cd .\sample\bin\ > %SampleName%_DX12.bat
- echo start %SampleName%_DX12.exe >> %SampleName%_DX12.bat
artifacts:
name: "%SampleName%-%CI_COMMIT_TAG%"
name: "%SampleName%-%CI_COMMIT_TAG%-%CI_COMMIT_REF_NAME%-%CI_COMMIT_SHORT_SHA%"
paths:
- "%SampleName%/bin/"
- "%SampleName%/media/"
- "%SampleName%/NOTICES.txt"
- "%SampleName%/README.md"
- "%SampleName%/screenshot.png"
- "NOTICES.txt"
- "sample/bin/"
- "sample/media/"
- "docs/"
- "readme.md"
- "%SampleName%_VK.bat"
- "%SampleName%_DX12.bat"
- "%SampleName%_VK.bat"
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
19 changes: 19 additions & 0 deletions NOTICES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ Downsampler
- SPD CS linear sampler: uses the SPD library and for sampling the source texture a linear sampler

SPD Versions
- WaveOps: uses Intrinsics and LDS to share the data between threads - this is the recommended version
- NO-WaveOps: uses only LDS to share the data between threads
- WaveOps: uses Intrinsics and LDS to share the data between threads

SPD Non-Packed / Packed Version
- Non-Packed: uses fp32
- Packed: uses fp16, reduced register pressure

# Known issues
DX12, No-WaveOps, Non-Packed: Corruptions on Nvidia when using DXC compiler.

# Recommendations
We recommend to use the WapeOps path when supported. If higher precision is not needed, you can enable the packed mode - it has less register pressure and can run a bit faster as well.
Binary file added docs/FidelityFX_SPD.pdf
Binary file not shown.
6 changes: 3 additions & 3 deletions ffx-spd/ffx_spd.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

// // global atomic counter - MUST be initialized to 0
// // GLSL:
// layout(std430, set=0, binding=2) buffer globalAtomicBuffer
// layout(std430, set=0, binding=2) coherent buffer globalAtomicBuffer
// {
// uint counter;
// } globalAtomic;
Expand All @@ -69,7 +69,7 @@
// {
// uint counter;
// };
// [[vk::binding(2)]] RWStructuredBuffer<globalAtomicBuffer> globalAtomic;
// [[vk::binding(2)]] globallycoherent RWStructuredBuffer<globalAtomicBuffer> globalAtomic;

// // [SAMPLER] add sampler
// GLSL: layout(set=0, binding=3) uniform sampler srcSampler;
Expand All @@ -81,7 +81,7 @@
// // GLSL:
// layout(push_constant) uniform pushConstants {
// uint mips; // needed to opt out earlier if mips are < 12
// uint numWorkGroups; // number of total thread groups, so numWorkGroupsX * numWorkGroupsY * numWorkGroupsZ
// uint numWorkGroups; // number of total thread groups, so numWorkGroupsX * numWorkGroupsY * 1
// } spdConstants;
// // HLSL:
// [[vk::push_constant]]
Expand Down
5 changes: 1 addition & 4 deletions sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ Downsampler
- SPD CS linear sampler: uses the SPD library and for sampling the source texture a linear sampler

SPD Versions
- WaveOps: uses Intrinsics and LDS to share the data between threads - this is the recommended version
- NO-WaveOps: uses only LDS to share the data between threads
- WaveOps: uses Intrinsics and LDS to share the data between threads

SPD Non-Packed / Packed Version
- Non-Packed: uses fp32
- Packed: uses fp16, reduced register pressure

# Known issues
DX12, No-WaveOps, Non-Packed: Corruptions on Nvidia when using DXC compiler.

# Recommendations
We recommend to use the WapeOps path when supported. If higher precision is not needed, you can enable the packed mode - it has less register pressure and can run a bit faster as well.
2 changes: 1 addition & 1 deletion sample/libs/cauldron
18 changes: 14 additions & 4 deletions sample/src/DX12/CSDownsampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ namespace CAULDRON_DX12
1,
0,
D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS),
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);

// Create views for the mip chain
//
Expand Down Expand Up @@ -172,7 +172,17 @@ namespace CAULDRON_DX12

void CSDownsampler::OnDestroy()
{
m_pRootSignature->Release();
if (m_pPipeline != NULL)
{
m_pPipeline->Release();
m_pPipeline = NULL;
}

if (m_pRootSignature != NULL)
{
m_pRootSignature->Release();
m_pRootSignature = NULL;
}
}

void CSDownsampler::Draw(ID3D12GraphicsCommandList* pCommandList)
Expand All @@ -183,7 +193,7 @@ namespace CAULDRON_DX12
//
for (int i = 0; i < m_mipCount; i++)
{
pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_result.GetResource(), D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, i));
pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_result.GetResource(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, i));

D3D12_GPU_VIRTUAL_ADDRESS cbHandle;
uint32_t* pConstMem;
Expand Down Expand Up @@ -219,7 +229,7 @@ namespace CAULDRON_DX12
uint32_t dispatchZ = 1;
pCommandList->Dispatch(dispatchX, dispatchY, dispatchZ);

pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_result.GetResource(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, i));
pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_result.GetResource(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, i));
}
}

Expand Down
24 changes: 19 additions & 5 deletions sample/src/DX12/SPD_CS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ namespace CAULDRON_DX12
1,
0,
D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS),
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);

// Create views for the mip chain
//
Expand All @@ -178,12 +178,23 @@ namespace CAULDRON_DX12

void SPD_CS::OnDestroyWindowSizeDependentResources()
{
m_globalCounterBuffer.OnDestroy();
m_result.OnDestroy();
}

void SPD_CS::OnDestroy()
{
m_pRootSignature->Release();
if (m_pPipeline != NULL)
{
m_pPipeline->Release();
m_pPipeline = NULL;
}

if (m_pRootSignature != NULL)
{
m_pRootSignature->Release();
m_pRootSignature = NULL;
}
}

void SPD_CS::Draw(ID3D12GraphicsCommandList2* pCommandList)
Expand Down Expand Up @@ -229,13 +240,16 @@ namespace CAULDRON_DX12
D3D12_WRITEBUFFERIMMEDIATE_PARAMETER pParams = { m_globalCounterBuffer.GetResource()->GetGPUVirtualAddress(), 0 };
pCommandList->WriteBufferImmediate(1, &pParams, NULL);

pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_globalCounterBuffer.GetResource(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, 0));
D3D12_RESOURCE_BARRIER resourceBarriers[2] = {
CD3DX12_RESOURCE_BARRIER::Transition(m_globalCounterBuffer.GetResource(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, 0),
CD3DX12_RESOURCE_BARRIER::Transition(m_result.GetResource(), D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_UNORDERED_ACCESS)
};
pCommandList->ResourceBarrier(2, resourceBarriers);

// Dispatch
//
pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_result.GetResource(), D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_UNORDERED_ACCESS));
pCommandList->Dispatch(dispatchX, dispatchY, dispatchZ);
pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_result.GetResource(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE));
pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_result.GetResource(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE));
}

void SPD_CS::Gui()
Expand Down
24 changes: 19 additions & 5 deletions sample/src/DX12/SPD_CS_Linear_Sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ namespace CAULDRON_DX12
1,
0,
D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS),
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);

// Create views for the mip chain
//
Expand All @@ -193,12 +193,23 @@ namespace CAULDRON_DX12

void SPD_CS_Linear_Sampler::OnDestroyWindowSizeDependentResources()
{
m_globalCounterBuffer.OnDestroy();
m_result.OnDestroy();
}

void SPD_CS_Linear_Sampler::OnDestroy()
{
m_pRootSignature->Release();
if (m_pPipeline != NULL)
{
m_pPipeline->Release();
m_pPipeline = NULL;
}

if (m_pRootSignature != NULL)
{
m_pRootSignature->Release();
m_pRootSignature = NULL;
}
}

void SPD_CS_Linear_Sampler::Draw(ID3D12GraphicsCommandList2* pCommandList)
Expand Down Expand Up @@ -246,13 +257,16 @@ namespace CAULDRON_DX12
D3D12_WRITEBUFFERIMMEDIATE_PARAMETER pParams = { m_globalCounterBuffer.GetResource()->GetGPUVirtualAddress(), 0 };
pCommandList->WriteBufferImmediate(1, &pParams, NULL);

pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_globalCounterBuffer.GetResource(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, 0));
D3D12_RESOURCE_BARRIER resourceBarriers[2] = {
CD3DX12_RESOURCE_BARRIER::Transition(m_globalCounterBuffer.GetResource(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, 0),
CD3DX12_RESOURCE_BARRIER::Transition(m_result.GetResource(), D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_UNORDERED_ACCESS)
};
pCommandList->ResourceBarrier(2, resourceBarriers);

// Dispatch
//
pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_result.GetResource(), D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_UNORDERED_ACCESS));
pCommandList->Dispatch(dispatchX, dispatchY, dispatchZ);
pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_result.GetResource(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE));
pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_result.GetResource(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE));
}

void SPD_CS_Linear_Sampler::Gui()
Expand Down
Loading

0 comments on commit 0e82a6f

Please sign in to comment.