Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Refactor of UAV clearing - bug fixes and etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
fstrugar committed Dec 28, 2021
1 parent d59ffcb commit 0d177ce
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 36 deletions.
43 changes: 43 additions & 0 deletions Source/Rendering/Shaders/vaMisc.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016-2021, Intel Corporation
//
// SPDX-License-Identifier: MIT
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Author(s): Filip Strugar ([email protected])
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "vaPostProcessShared.h"

#if defined( VA_POSTPROCESS_CLEAR_UAV_TEX1D_1F ) // 1D textures
RWTexture1D<float> g_clearTarget : register( u0 );
[numthreads(64, 1, 1)] void CSClearUAV_Tex1D_1F( uint dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[min(dispatchThreadID, g_postProcessConsts.Bounds.x)] = g_postProcessConsts.Bounds.x; }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_TEX1D_4F )
RWTexture1D<float4> g_clearTarget : register( u0 );
[numthreads(64, 1, 1)] void CSClearUAV_Tex1D_4F( uint dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[min(dispatchThreadID, g_postProcessConsts.Bounds.x)] = g_postProcessConsts.Bounds.xyzw; }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_TEX1D_1U )
RWTexture1D<uint> g_clearTarget : register( u0 );
[numthreads(64, 1, 1)] void CSClearUAV_Tex1D_1U( uint dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[min(dispatchThreadID, g_postProcessConsts.Bounds.x)] = asuint(g_postProcessConsts.Bounds.x); }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_TEX1D_4U )
RWTexture1D<uint4> g_clearTarget : register( u0 );
[numthreads(64, 1, 1)] void CSClearUAV_Tex1D_4U( uint dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[min(dispatchThreadID, g_postProcessConsts.Bounds.x)] = asuint(g_postProcessConsts.Bounds.xyzw); }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_TEX2D_1F ) // 2D textures
RWTexture2D<float> g_clearTarget : register( u0 );
[numthreads(8, 8, 1)] void CSClearUAV_Tex2D_1F( uint2 dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[min(dispatchThreadID, g_postProcessConsts.Bounds.xy)] = g_postProcessConsts.Bounds.x; }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_TEX2D_4F )
RWTexture2D<float4> g_clearTarget : register( u0 );
[numthreads(8, 8, 1)] void CSClearUAV_Tex2D_4F( uint2 dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[min(dispatchThreadID, g_postProcessConsts.Bounds.xy)] = g_postProcessConsts.Bounds.xyzw; }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_TEX2D_1U )
RWTexture2D<uint> g_clearTarget : register( u0 );
[numthreads(8, 8, 1)] void CSClearUAV_Tex2D_1U( uint2 dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[min(dispatchThreadID, g_postProcessConsts.Bounds.xy)] = asuint(g_postProcessConsts.Bounds.x); }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_TEX2D_4U )
RWTexture2D<uint4> g_clearTarget : register( u0 );
[numthreads(8, 8, 1)] void CSClearUAV_Tex2D_4U( uint2 dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[min(dispatchThreadID, g_postProcessConsts.Bounds.xy)] = asuint(g_postProcessConsts.Bounds.xyzw); }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_BUFF_1U ) // buffers
RWBuffer<uint> g_clearTarget : register( u0 );
[numthreads(64, 1, 1)] void CSClearUAV_Buff_1U( uint dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[min(dispatchThreadID, g_postProcessConsts.Bounds.x)] = asuint(g_postProcessConsts.Bounds.x); }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_BUFF_4U )
RWBuffer<uint4> g_clearTarget : register( u0 );
[numthreads(64, 1, 1)] void CSClearUAV_Buff_4U( uint dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[min(dispatchThreadID, g_postProcessConsts.Bounds.x)] = asuint(g_postProcessConsts.Bounds.xyzw); }
#endif
32 changes: 0 additions & 32 deletions Source/Rendering/Shaders/vaPostProcess.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -461,35 +461,3 @@ void CSGenerateMotionVectors( uint2 dispatchThreadID : SV_DispatchThreadID )
}

#endif

#if defined( VA_POSTPROCESS_CLEAR_UAV_TEX1D_1F ) // 1D textures
RWTexture1D<float> g_clearTarget : register( u0 );
[numthreads(64, 1, 1)] void CSClearUAV_Tex1D_1F( uint dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[dispatchThreadID] = g_postProcessConsts.Param1.x; }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_TEX1D_4F )
RWTexture1D<float4> g_clearTarget : register( u0 );
[numthreads(64, 1, 1)] void CSClearUAV_Tex1D_4F( uint dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[dispatchThreadID] = g_postProcessConsts.Param1.xyzw; }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_TEX1D_1U )
RWTexture1D<uint> g_clearTarget : register( u0 );
[numthreads(64, 1, 1)] void CSClearUAV_Tex1D_1U( uint dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[dispatchThreadID] = asuint(g_postProcessConsts.Param1.x); }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_TEX1D_4U )
RWTexture1D<uint4> g_clearTarget : register( u0 );
[numthreads(64, 1, 1)] void CSClearUAV_Tex1D_4U( uint dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[dispatchThreadID] = asuint(g_postProcessConsts.Param1.xyzw); }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_TEX2D_1F ) // 2D textures
RWTexture2D<float> g_clearTarget : register( u0 );
[numthreads(8, 8, 1)] void CSClearUAV_Tex2D_1F( uint2 dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[dispatchThreadID] = g_postProcessConsts.Param1.x; }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_TEX2D_4F )
RWTexture2D<float4> g_clearTarget : register( u0 );
[numthreads(8, 8, 1)] void CSClearUAV_Tex2D_4F( uint2 dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[dispatchThreadID] = g_postProcessConsts.Param1.xyzw; }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_TEX2D_1U )
RWTexture2D<uint> g_clearTarget : register( u0 );
[numthreads(8, 8, 1)] void CSClearUAV_Tex2D_1U( uint2 dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[dispatchThreadID] = asuint(g_postProcessConsts.Param1.x); }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_TEX2D_4U )
RWTexture2D<uint4> g_clearTarget : register( u0 );
[numthreads(8, 8, 1)] void CSClearUAV_Tex2D_4U( uint2 dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[dispatchThreadID] = asuint(g_postProcessConsts.Param1.xyzw); }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_BUFF_1U ) // buffers
RWBuffer<uint> g_clearTarget : register( u0 );
[numthreads(64, 1, 1)] void CSClearUAV_Buff_1U( uint dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[dispatchThreadID] = asuint(g_postProcessConsts.Param1.x); }
#elif defined( VA_POSTPROCESS_CLEAR_UAV_BUFF_4U )
RWBuffer<uint4> g_clearTarget : register( u0 );
[numthreads(64, 1, 1)] void CSClearUAV_Buff_4U( uint dispatchThreadID : SV_DispatchThreadID ) { g_clearTarget[dispatchThreadID] = asuint(g_postProcessConsts.Param1.xyzw); }
#endif
1 change: 1 addition & 0 deletions Source/Rendering/Shaders/vaPostProcessShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace Vanilla
vaVector4 Param2;
vaVector4 Param3;
vaVector4 Param4;
vaVector4ui Bounds;
};

// all of this is unused at the moment
Expand Down
16 changes: 13 additions & 3 deletions Source/Rendering/vaRenderDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,11 +663,14 @@ vaDrawResultFlags vaRenderDevice::ClearUAV( vaRenderDeviceContext & renderContex
assert( false ); // codepath never tested/debugged through, sorry - test it and remove assert please :)
assert( !vaResourceFormatHelpers::IsFloat(buffer->GetResourceFormat()) );
assert( vaResourceFormatHelpers::GetChannelCount(buffer->GetResourceFormat()) == 4 );
assert( buffer->GetElementCount() > 0 );
// clear data
PostProcessConstants consts; reinterpret_cast<vaVector4ui&>(consts.Param1) = clearValue;
PostProcessConstants consts; memset( &consts, 0, sizeof(consts) ); reinterpret_cast<vaVector4ui&>(consts.Param1) = clearValue;
consts.Bounds.x = (int)buffer->GetElementCount()-1;
m_PPConstants->Upload( renderContext, &consts, sizeof(consts) );
// setup dispatch
vaComputeItem computeItem;
computeItem.ConstantBuffers[POSTPROCESS_CONSTANTSBUFFERSLOT] = m_PPConstants;
computeItem.ComputeShader = m_CSClearUAV_Buff_4U;
computeItem.SetDispatch( (uint32)(buffer->GetElementCount() + 63) / 64 );
return renderContext.ExecuteSingleItem( computeItem, vaRenderOutputs::FromUAVs( buffer ), nullptr );
Expand All @@ -678,20 +681,27 @@ vaDrawResultFlags vaRenderDevice::ClearUAV( vaRenderDeviceContext & renderContex
assert( false ); // codepath never tested/debugged through, sorry - test it and remove assert please :)
assert( !vaResourceFormatHelpers::IsFloat(buffer->GetResourceFormat()) );
assert( vaResourceFormatHelpers::GetChannelCount(buffer->GetResourceFormat()) == 1 );
assert( buffer->GetElementCount() > 0 );
// clear data
PostProcessConstants consts; reinterpret_cast<vaVector4ui&>(consts.Param1).x = clearValue;
PostProcessConstants consts; memset( &consts, 0, sizeof(consts) ); reinterpret_cast<vaVector4ui&>(consts.Param1).x = clearValue;
consts.Bounds.x = (int)buffer->GetElementCount()-1;
m_PPConstants->Upload( renderContext, &consts, sizeof(consts) );
// setup dispatch
vaComputeItem computeItem;
computeItem.ConstantBuffers[POSTPROCESS_CONSTANTSBUFFERSLOT] = m_PPConstants;
computeItem.ComputeShader = m_CSClearUAV_Buff_1U;
computeItem.SetDispatch( (uint32)(buffer->GetElementCount() + 63) / 64 );
return renderContext.ExecuteSingleItem( computeItem, vaRenderOutputs::FromUAVs( buffer ), nullptr );
}

vaDrawResultFlags vaRenderDevice::ClearTextureUAVGeneric( vaRenderDeviceContext & renderContext, const shared_ptr<vaTexture> & texture, const shared_ptr<vaComputeShader> & computeShader, const PostProcessConstants & clearValue )
vaDrawResultFlags vaRenderDevice::ClearTextureUAVGeneric( vaRenderDeviceContext & renderContext, const shared_ptr<vaTexture> & texture, const shared_ptr<vaComputeShader> & computeShader, PostProcessConstants clearValue )
{
clearValue.Bounds.x = texture->GetWidth()-1;
clearValue.Bounds.y = texture->GetHeight()-1;

m_PPConstants->Upload( renderContext, &clearValue, sizeof(clearValue) );
vaComputeItem computeItem;
computeItem.ConstantBuffers[POSTPROCESS_CONSTANTSBUFFERSLOT] = m_PPConstants;
computeItem.ComputeShader = computeShader;
if( texture->GetType() == vaTextureType::Texture1D )
computeItem.SetDispatch( (uint32)(texture->GetWidth() + 63) / 64 );
Expand Down
2 changes: 1 addition & 1 deletion Source/Rendering/vaRenderDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ namespace Vanilla
vaDrawResultFlags ClearUAV( vaRenderDeviceContext & renderContext, const shared_ptr<vaTexture> & texture, uint clearValue );
vaDrawResultFlags ClearUAV( vaRenderDeviceContext & renderContext, const shared_ptr<vaTexture> & texture, const vaVector4ui & clearValue );
private:
vaDrawResultFlags ClearTextureUAVGeneric( vaRenderDeviceContext & renderContext, const shared_ptr<vaTexture> & texture, const shared_ptr<vaComputeShader> & computeShader, const PostProcessConstants & clearValue );
vaDrawResultFlags ClearTextureUAVGeneric( vaRenderDeviceContext & renderContext, const shared_ptr<vaTexture> & texture, const shared_ptr<vaComputeShader> & computeShader, PostProcessConstants clearValue );
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public:
Expand Down
5 changes: 5 additions & 0 deletions VisualStudio/AllModules/AllModules.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@
<FileType>Document</FileType>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\Source\Rendering\Shaders\vaMisc.hlsl">
<FileType>Document</FileType>
</ClInclude>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{30430E2D-C12E-4537-866E-52B1B49F6410}</ProjectGuid>
<RootNamespace>Vanilla</RootNamespace>
Expand Down
3 changes: 3 additions & 0 deletions VisualStudio/AllModules/AllModules.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,9 @@
<ClInclude Include="..\..\Source\Rendering\vaPathTracerDenoisers.h">
<Filter>Rendering</Filter>
</ClInclude>
<ClInclude Include="..\..\Source\Rendering\Shaders\vaMisc.hlsl">
<Filter>Rendering\Shaders</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\Source\Core\vaGeometry.inl">
Expand Down

0 comments on commit 0d177ce

Please sign in to comment.