Skip to content

Commit 77f3a10

Browse files
committed
Imported changes from Oculus-VR:Unity-Graphics:6000.0/17.0.4-subpass
1 parent 65a7fde commit 77f3a10

21 files changed

Lines changed: 272 additions & 16 deletions

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/Compiler/CompilerContextData.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,26 @@ public ref ResourceReaderData ResourceReader(in ResourceHandle h, int i)
154154
// Data per native renderpas
155155
public NativeList<NativePassData> nativePassData;
156156
public NativeList<SubPassDescriptor> nativeSubPassData; //Tighty packed list of per nrp subpasses
157+
158+
public bool passMerged(int passId1, int passId2)
159+
{
160+
return passData[passId1].nativePassIndex == passData[passId2].nativePassIndex;
161+
}
162+
163+
public bool nativepassFragmentsContain(int passId, int fragIndex)
164+
{
165+
int nativePassId = passData[passId].nativePassIndex;
166+
if (nativePassId <= nativePassData.Length)
167+
{
168+
NativePassData data = nativePassData[nativePassId];
169+
for (int i = 0; i < data.fragments.size; i++)
170+
{
171+
if (data.fragments[i].resource.index == fragIndex)
172+
return true;
173+
}
174+
}
175+
return false;
176+
}
157177

158178
// resources can be added as fragment both as input and output so make sure not to add them twice (return true upon new addition)
159179
public bool TryAddToFragmentList(in TextureAccess access, int listFirstIndex, int numItems, out string errorMessage)

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/Compiler/NativePassCompiler.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,13 @@ public void ExecuteGraph(InternalRenderGraphContext rgContext, RenderGraphResour
20222022
ExecuteBeginRenderPass(rgContext, resources, ref nativePass);
20232023
nrpBegan = true;
20242024
inRenderPass = true;
2025+
2026+
for (int subpassIndex = nativePass.firstGraphPass; subpassIndex <= nativePass.lastGraphPass; subpassIndex++)
2027+
{
2028+
ref var subpassData = ref contextData.passData.ElementAt(subpassIndex);
2029+
rgContext.executingPass = passes[subpassData.passId];
2030+
passes[subpassData.passId].PreExecute(rgContext);
2031+
}
20252032
}
20262033
}
20272034
}

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/IRenderGraphBuilder.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,15 @@ void SetRenderAttachmentDepth(TextureHandle tex, AccessFlags flags = AccessFlags
273273
/// <param name="flags">How this pass will access the buffer. Default value is set to AccessFlag.Read.</param>
274274
/// <returns>The value passed to 'input'. You should not use the returned value it will be removed in the future.</returns>
275275
BufferHandle UseBufferRandomAccess(BufferHandle tex, int index, bool preserveCounterValue, AccessFlags flags = AccessFlags.Read);
276+
277+
/// <summary>
278+
/// Specify the pre-render function to use for this pass.
279+
/// The call happens when a native render pass starts
280+
/// </summary>
281+
/// <typeparam name="PassData">The Type of the class that provides data to the Render Pass.</typeparam>
282+
/// <param name="renderFunc">Render function for the pass.</param>
283+
public void SetPreRenderFunc<PassData>(BaseRenderFunc<PassData, RasterGraphContext> preRenderFunc)
284+
where PassData : class, new();
276285
}
277286

278287
/// <summary>

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.Compiler.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,10 @@ void ExecuteNativeRenderGraph()
4040
nativeCompiler.ExecuteGraph(m_RenderGraphContext, m_Resources, m_RenderPasses);
4141
}
4242
}
43+
44+
public bool IsPassUsingRenderTarget(int passId, int resourceId)
45+
{
46+
return nativeCompiler.contextData.nativepassFragmentsContain(passId, resourceId);
47+
}
4348
}
4449
}

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ public void FromInternalContext(InternalRenderGraphContext context)
209209
rastercmd.m_ExecutingPass = context.executingPass;
210210
cmd = rastercmd;
211211
}
212+
213+
public int CurrentRGPassId() {
214+
return cmd.m_ExecutingPass.index;
215+
}
212216

213217
/// <inheritdoc />
214218
public readonly TextureUVOrigin GetTextureUVOrigin(in TextureHandle textureHandle)

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphBuilders.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public void SetGlobalTextureAfterPass(in TextureHandle input, int propertyId)
350350

351351
// Shared validation between SetRenderAttachment/SetRenderAttachmentDepth
352352
[Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")]
353-
private void CheckUseFragment(in TextureHandle tex, bool isDepth)
353+
private void CheckUseFragment(in TextureHandle tex, bool isDepth, bool ignoreReadTextureCheck = false)
354354
{
355355
if (RenderGraph.enableValidityChecks)
356356
{
@@ -362,12 +362,15 @@ private void CheckUseFragment(in TextureHandle tex, bool isDepth)
362362
// SetRenderAttachment()
363363
// UseTexture(grab)
364364
// will work but not the other way around
365-
for (int i = 0; i < m_RenderPass.resourceReadLists[tex.handle.iType].Count; i++)
365+
if (!ignoreReadTextureCheck)
366366
{
367-
if (m_RenderPass.resourceReadLists[tex.handle.iType][i].index == tex.handle.index)
367+
for (int i = 0; i < m_RenderPass.resourceReadLists[tex.handle.iType].Count; i++)
368368
{
369-
alreadyUsed = true;
370-
break;
369+
if (m_RenderPass.resourceReadLists[tex.handle.iType][i].index == tex.handle.index)
370+
{
371+
alreadyUsed = true;
372+
break;
373+
}
371374
}
372375
}
373376

@@ -478,7 +481,12 @@ public void SetInputAttachment(TextureHandle tex, int index, AccessFlags flags,
478481
{
479482
CheckFrameBufferFetchEmulationIsSupported(tex);
480483

481-
CheckUseFragment(tex, false);
484+
// Depth texture can be bind as input attachment, bypass the depth format check inside CheckUseFragment
485+
m_Resources.GetRenderTargetInfo(tex.handle, out var info);
486+
bool isDepth = GraphicsFormatUtility.IsDepthFormat(info.format);
487+
// Bypass the already used check for texture read, so that an attachment can be used as depth and input in one subpass
488+
bool ignoreReadTextureCheck = true;
489+
CheckUseFragment(tex, isDepth, ignoreReadTextureCheck);
482490
var versionedTextureHandle = new TextureHandle(UseResource(tex.handle, flags));
483491
m_RenderPass.SetFragmentInputRaw(versionedTextureHandle, index, flags, mipLevel, depthSlice);
484492
}
@@ -518,6 +526,11 @@ public BufferHandle UseBufferRandomAccess(BufferHandle input, int index, bool pr
518526
m_RenderPass.SetRandomWriteResourceRaw(h.handle, index, preserveCounterValue, flags);
519527
return input;
520528
}
529+
530+
public void SetPreRenderFunc<PassData>(BaseRenderFunc<PassData, RasterGraphContext> preRenderFunc) where PassData : class, new()
531+
{
532+
((RasterRenderGraphPass<PassData>)m_RenderPass).preRenderFunc = preRenderFunc;
533+
}
521534

522535
public void SetRenderFunc<PassData>(BaseRenderFunc<PassData, ComputeGraphContext> renderFunc) where PassData : class, new()
523536
{

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphPass.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace UnityEngine.Rendering.RenderGraphModule
88
[DebuggerDisplay("RenderPass: {name} (Index:{index} Async:{enableAsyncCompute})")]
99
abstract class RenderGraphPass
1010
{
11+
public virtual void PreExecute(InternalRenderGraphContext renderGraphContext) { return; }
1112
public abstract void Execute(InternalRenderGraphContext renderGraphContext);
1213
public abstract void Release(RenderGraphObjectPool pool);
1314
public abstract bool HasRenderFunc();
@@ -701,6 +702,18 @@ internal sealed class RasterRenderGraphPass<PassData> : BaseRenderGraphPass<Pass
701702
where PassData : class, new()
702703
{
703704
internal static RasterGraphContext c = new RasterGraphContext();
705+
internal BaseRenderFunc<PassData, RasterGraphContext> preRenderFunc;
706+
707+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
708+
public override void PreExecute(InternalRenderGraphContext renderGraphContext)
709+
{
710+
if (preRenderFunc != null)
711+
{
712+
RasterGraphContext temp_c = new RasterGraphContext();
713+
temp_c.FromInternalContext(renderGraphContext);
714+
preRenderFunc(data, temp_c);
715+
}
716+
}
704717

705718
[MethodImpl(MethodImplOptions.AggressiveInlining)]
706719
public override void Execute(InternalRenderGraphContext renderGraphContext)

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceTexture.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ internal TextureHandle(int handle, bool shared = false, bool builtin = false)
217217
/// <param name="renderGraph">The rendergraph instance that was used to create the texture on. Texture handles are a lightweight object, all information is stored on the RenderGraph itself.</param>
218218
/// <returns>The texture descriptor for the given texture handle.</returns>
219219
public TextureDesc GetDescriptor(RenderGraph renderGraph) { return renderGraph.GetTextureDesc(this); }
220+
221+
public int GetResourceId() { return handle.index; }
220222
}
221223

222224
/// <summary>

Packages/com.unity.render-pipelines.core/Runtime/XR/XRSystem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ private static RenderTextureDescriptor XrRenderTextureDescToUnityRenderTextureDe
538538
rtDesc.volumeDepth = xrDesc.volumeDepth;
539539
rtDesc.vrUsage = xrDesc.vrUsage;
540540
rtDesc.sRGB = xrDesc.sRGB;
541+
rtDesc.msaaSamples = xrDesc.msaaSamples;
541542
rtDesc.shadowSamplingMode = xrDesc.shadowSamplingMode;
542543
return rtDesc;
543544
}

Packages/com.unity.render-pipelines.universal/Editor/RendererFeatures/RenderObjectsPassFeatureEditor.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ internal class Styles
5252
public static GUIContent overrideDepth = new GUIContent("Depth", "Select this option to specify how this Renderer Feature affects or uses the values in the Depth buffer.");
5353
public static GUIContent writeDepth = new GUIContent("Write Depth", "Choose to write depth to the screen.");
5454
public static GUIContent depthState = new GUIContent("Depth Test", "Choose a new depth test function.");
55+
public static GUIContent depthInput = new GUIContent("Depth Input", "Choose to bind depth as an input attachment.");
5556

5657
//Camera Settings
5758
public static GUIContent overrideCamera = new GUIContent("Camera", "Override camera matrices. Toggling this setting will make camera use perspective projection.");
@@ -86,6 +87,7 @@ internal class Styles
8687
private SerializedProperty m_OverrideDepth;
8788
private SerializedProperty m_WriteDepth;
8889
private SerializedProperty m_DepthState;
90+
private SerializedProperty m_DepthInput;
8991
//Stencil props
9092
private SerializedProperty m_StencilSettings;
9193
//Caemra props
@@ -140,6 +142,7 @@ private void Init(SerializedProperty property)
140142
m_OverrideDepth = property.FindPropertyRelative("overrideDepthState");
141143
m_WriteDepth = property.FindPropertyRelative("enableWrite");
142144
m_DepthState = property.FindPropertyRelative("depthCompareFunction");
145+
m_DepthInput = property.FindPropertyRelative("depthInput");
143146

144147
//Stencil
145148
m_StencilSettings = property.FindPropertyRelative("stencilSettings");
@@ -278,6 +281,13 @@ void DoDepthOverride(ref Rect rect)
278281
EditorGUI.indentLevel++;
279282
//Write depth
280283
EditorGUI.PropertyField(rect, m_WriteDepth, Styles.writeDepth);
284+
rect.y += Styles.defaultLineSpace;
285+
EditorGUI.PropertyField(rect, m_DepthInput, Styles.depthInput);
286+
if (m_DepthInput.boolValue && m_WriteDepth.boolValue) {
287+
Debug.LogWarning("Depth Input and Write Depth can't be used at the same time. Write Depth has been disabled.");
288+
m_WriteDepth.boolValue = false;
289+
}
290+
281291
rect.y += Styles.defaultLineSpace;
282292
//Depth testing options
283293
EditorGUI.PropertyField(rect, m_DepthState, Styles.depthState);

0 commit comments

Comments
 (0)