Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render Graph Async Compute #552

Merged
merged 21 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2403c55
Handle deallocation/reallocation of resources when switching rendergr…
JulienIgnace-Unity Apr 22, 2020
c775689
AO and Post Processes.
JulienIgnace-Unity Apr 24, 2020
a147330
Prefixed all history buffers with camera name for readability in the …
JulienIgnace-Unity Apr 24, 2020
8bb3fe6
LIght volume debug and Volumetric (WIP)
JulienIgnace-Unity Apr 27, 2020
4baa326
Fixed volumetric
JulienIgnace-Unity Apr 29, 2020
c7cca48
Fixed deallocation of SSS buffers
JulienIgnace-Unity Apr 29, 2020
960c0a5
Review feedback fixes.
JulienIgnace-Unity Apr 29, 2020
4c67bfd
Init order fix for post process
JulienIgnace-Unity Apr 29, 2020
6c38c3f
WIP: refactoring of render graph compilation and resource allocation …
JulienIgnace-Unity May 5, 2020
1898564
Implementation of async resource synchronization.
JulienIgnace-Unity May 7, 2020
ac2166a
Fixed synchronization (only partial fix)
JulienIgnace-Unity May 7, 2020
d62e8a7
Added default profiling sampler for render graph passes not providing…
JulienIgnace-Unity May 7, 2020
9d7c910
Async WIP
JulienIgnace-Unity May 12, 2020
3a579d0
Fixed async synchronization by extending lifetime of resources freed …
JulienIgnace-Unity May 18, 2020
41178ed
Merge branch 'HDRP/staging' of https://github.com/Unity-Technologies/…
JulienIgnace-Unity May 19, 2020
96f5563
Post merge fix
JulienIgnace-Unity May 19, 2020
fdec415
Cleanup
JulienIgnace-Unity May 19, 2020
e5f8993
Removed comment.
JulienIgnace-Unity May 19, 2020
6728b7e
Disabled async contact shadows again.
JulienIgnace-Unity May 19, 2020
052aa74
Merge branch 'HDRP/staging' of https://github.com/Unity-Technologies/…
JulienIgnace-Unity May 20, 2020
6c7e6dd
Small cleanup
JulienIgnace-Unity May 20, 2020
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
Prev Previous commit
Next Next commit
LIght volume debug and Volumetric (WIP)
  • Loading branch information
JulienIgnace-Unity committed Apr 28, 2020
commit 8bb3fe65771374fa34496f9f8e69228334b539b0
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ public void InitData(RenderPipelineResources renderPipelineResources)

m_Blit = CoreUtils.CreateEngineMaterial(renderPipelineResources.shaders.blitPS);

InitializeNonRenderGraphResources();
}

public void ReleaseData()
{
CoreUtils.Destroy(m_Blit);
CoreUtils.Destroy(m_DebugLightVolumeMaterial);

CleanupNonRenderGraphResources();
}

public void InitializeNonRenderGraphResources()
{
m_LightCountBuffer = RTHandles.Alloc(Vector2.one, TextureXR.slices, dimension: TextureXR.dimension, colorFormat: GraphicsFormat.R32_SFloat, enableRandomWrite: false, useMipMap: false, name: "LightVolumeCount");
m_ColorAccumulationBuffer = RTHandles.Alloc(Vector2.one, TextureXR.slices, dimension: TextureXR.dimension, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite: false, useMipMap: false, name: "LightVolumeColorAccumulation");
m_DebugLightVolumesTexture = RTHandles.Alloc(Vector2.one, TextureXR.slices, dimension: TextureXR.dimension, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite: true, useMipMap: false, name: "LightVolumeDebugLightVolumesTexture");
Expand All @@ -63,16 +76,12 @@ public void InitData(RenderPipelineResources renderPipelineResources)
m_RTIDs[1] = m_ColorAccumulationBuffer;
}

public void ReleaseData()
public void CleanupNonRenderGraphResources()
{
CoreUtils.Destroy(m_Blit);

RTHandles.Release(m_DepthBuffer);
RTHandles.Release(m_DebugLightVolumesTexture);
RTHandles.Release(m_ColorAccumulationBuffer);
RTHandles.Release(m_LightCountBuffer);

CoreUtils.Destroy(m_DebugLightVolumeMaterial);
}

public struct RenderLightVolumesParameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,29 +445,40 @@ internal void CreateVolumetricLightingBuffers()
m_VisibleVolumeBoundsBuffer = new ComputeBuffer(k_MaxVisibleVolumeCount, Marshal.SizeOf(typeof(OrientedBBox)));
m_VisibleVolumeDataBuffer = new ComputeBuffer(k_MaxVisibleVolumeCount, Marshal.SizeOf(typeof(DensityVolumeEngineData)));

VolumetricInitializeNonRenderGraphResource();
}

internal void DestroyVolumetricLightingBuffers()
{
VolumetricCleanupNonRenderGraphResource();

CoreUtils.SafeRelease(m_VisibleVolumeDataBuffer);
CoreUtils.SafeRelease(m_VisibleVolumeBoundsBuffer);

m_VisibleVolumeData = null; // free()
m_VisibleVolumeBounds = null; // free()
}

void VolumetricInitializeNonRenderGraphResource()
{
// Allocate the smallest possible 3D texture.
// We will perform rescaling manually, in a custom manner, based on volume parameters.
const int minSize = 4;

m_DensityBuffer = RTHandles.Alloc(minSize, minSize, minSize, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, // 8888_sRGB is not precise enough
m_DensityBuffer = RTHandles.Alloc(minSize, minSize, minSize, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, // 8888_sRGB is not precise enough
dimension: TextureDimension.Tex3D, enableRandomWrite: true, name: "VBufferDensity");

m_LightingBuffer = RTHandles.Alloc(minSize, minSize, minSize, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, // 8888_sRGB is not precise enough
dimension: TextureDimension.Tex3D, enableRandomWrite: true, name: "VBufferLighting");
}

internal void DestroyVolumetricLightingBuffers()
void VolumetricCleanupNonRenderGraphResource()
{
RTHandles.Release(m_LightingBuffer);
RTHandles.Release(m_DensityBuffer);

CoreUtils.SafeRelease(m_VisibleVolumeDataBuffer);
CoreUtils.SafeRelease(m_VisibleVolumeBoundsBuffer);

m_VisibleVolumeData = null; // free()
m_VisibleVolumeBounds = null; // free()
}


// Must be called AFTER UpdateVolumetricBufferParams.
internal void ResizeVolumetricLightingBuffers(HDCamera hdCamera, int frameIndex)
{
Expand All @@ -488,14 +499,17 @@ internal void ResizeVolumetricLightingBuffers(HDCamera hdCamera, int frameIndex)
var currIdx = (frameIndex + 0) & 1;
var prevIdx = (frameIndex + 1) & 1;

var currentParams = hdCamera.vBufferParams[currIdx];

ResizeVolumetricBuffer(ref m_DensityBuffer, "VBufferDensity", currentParams.viewportSize.x,
currentParams.viewportSize.y,
currentParams.viewportSize.z);
ResizeVolumetricBuffer(ref m_LightingBuffer, "VBufferLighting", currentParams.viewportSize.x,
currentParams.viewportSize.y,
currentParams.viewportSize.z);
if (!m_EnableRenderGraph) // Render Texture are not allocated when render graph is enabled.
{
var currentParams = hdCamera.vBufferParams[currIdx];

ResizeVolumetricBuffer(ref m_DensityBuffer, "VBufferDensity", currentParams.viewportSize.x,
currentParams.viewportSize.y,
currentParams.viewportSize.z);
ResizeVolumetricBuffer(ref m_LightingBuffer, "VBufferLighting", currentParams.viewportSize.x,
currentParams.viewportSize.y,
currentParams.viewportSize.z);
}
}

void InitializeVolumetricLighting()
Expand Down Expand Up @@ -550,16 +564,13 @@ void UpdateShaderVariablesGlobalVolumetrics(ref ShaderVariablesGlobal cb, in RTH
int currIdx = (frameIndex + 0) & 1;

var currParams = hdCamera.vBufferParams[currIdx];

GizmoSubset,kgmsjrhl
// The lighting & density buffers are shared by all cameras.
// The history & feedback buffers are specific to the camera.
// These 2 types of buffers can have different sizes.
// Additionally, history buffers can have different sizes, since they are not resized at the same time.
Vector3Int lightingBufferSize = new Vector3Int(m_LightingBuffer.rt.width, m_LightingBuffer.rt.height, m_LightingBuffer.rt.volumeDepth);

Debug.Assert(m_LightingBuffer.rt.width == m_DensityBuffer.rt.width);
Debug.Assert(m_LightingBuffer.rt.height == m_DensityBuffer.rt.height);

var cvp = currParams.viewportSize;

// Adjust slices for XR rendering: VBuffer is shared for all single-pass views
Expand All @@ -576,18 +587,6 @@ void UpdateShaderVariablesGlobalVolumetrics(ref ShaderVariablesGlobal cb, in RTH
cb._VBufferRcpInstancedViewCount = 1.0f / hdCamera.viewCount;
}

void PushVolumetricLightingGlobalParams(HDCamera hdCamera, CommandBuffer cmd, int frameIndex)
{
if (!Fog.IsVolumetricFogEnabled(hdCamera))
{
cmd.SetGlobalTexture(HDShaderIDs._VBufferLighting, HDUtils.clearTexture3D);
}
else
{
cmd.SetGlobalTexture(HDShaderIDs._VBufferLighting, m_LightingBuffer);
}
}

DensityVolumeList PrepareVisibleDensityVolumeList(HDCamera hdCamera, CommandBuffer cmd, float time)
{
DensityVolumeList densityVolumes = new DensityVolumeList();
Expand Down Expand Up @@ -722,24 +721,12 @@ unsafe void UpdateShaderVariableslVolumetrics(ref ShaderVariablesVolumetric cb,
// The history & feedback buffers are specific to the camera.
// These 2 types of buffers can have different sizes.
// Additionally, history buffers can have different sizes, since they are not resized at the same time.
Vector3Int lightingBufferSize = new Vector3Int(m_LightingBuffer.rt.width, m_LightingBuffer.rt.height, m_LightingBuffer.rt.volumeDepth);

Debug.Assert(m_LightingBuffer.rt.width == m_DensityBuffer.rt.width);
Debug.Assert(m_LightingBuffer.rt.height == m_DensityBuffer.rt.height);

Vector3Int historyBufferSize = Vector3Int.zero;

if (hdCamera.IsVolumetricReprojectionEnabled())
{
RTHandle historyRT = hdCamera.volumetricHistoryBuffers[prevIdx];

historyBufferSize = new Vector3Int(historyRT.rt.width, historyRT.rt.height, historyRT.rt.volumeDepth);

// Handle case of first frame. When we are on the first frame, we reuse the value of original frame.
if (historyBufferSize.x == 0.0f && historyBufferSize.y == 0.0f)
{
historyBufferSize = lightingBufferSize;
}
}

cb._VBufferVoxelSize = currParams.voxelSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,8 @@ void InitializeNonRenderGraphResources()
m_ShadowManager.InitializeNonRenderGraphResources();
m_AmbientOcclusionSystem.InitializeNonRenderGraphResources();
m_PostProcessSystem.InitializeNonRenderGraphResources(asset);
VolumetricInitializeNonRenderGraphResource();
s_lightVolumes.InitializeNonRenderGraphResources();
}

void CleanupNonRenderGraphResources()
Expand All @@ -890,6 +892,8 @@ void CleanupNonRenderGraphResources()
m_ShadowManager.CleanupNonRenderGraphResources();
m_AmbientOcclusionSystem.CleanupNonRenderGraphResources();
m_PostProcessSystem.CleanupNonRenderGraphResources();
VolumetricCleanupNonRenderGraphResource();
s_lightVolumes.CleanupNonRenderGraphResources();
}

void InitializeDebugMaterials()
Expand Down Expand Up @@ -2135,7 +2139,7 @@ AOVRequestData aovRequest

if (m_EnableRenderGraph)
{
//ExecuteWithRenderGraph(renderRequest, aovRequest, aovBuffers, renderContext, cmd);
ExecuteWithRenderGraph(renderRequest, aovRequest, aovBuffers, renderContext, cmd);
return;
}

Expand Down