Skip to content

Commit 2fa5187

Browse files
NzollnerEvergreen
authored andcommitted
[Graphics]Adding mip level and slices to color and depth attachment for RG
This PR is related to the [URP-2105](https://jira.unity3d.com/browse/URP-2105) jira epic. The purpose of this PR is to add missing functionality by adding mip level and slices to RG's SetInputAttachment and SetRenderAttachment functions. This PR also introduces helper functions for Copy and Blit as well as a test to ensure the newly added functionality and the helper functions work as expected. There is also a fix for invalid texture description for imported textures
1 parent 08bb870 commit 2fa5187

33 files changed

+2606
-179
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using UnityEngine.Rendering;
2+
using UnityEngine.Rendering.RenderGraphModule.Util;
3+
4+
namespace UnityEditor.Rendering.RenderGraphModule.Util
5+
{
6+
class RenderGraphUtilsResourcesStripper : IRenderPipelineGraphicsSettingsStripper<RenderGraphUtilsResources>
7+
{
8+
public bool active => true;
9+
10+
public bool CanRemoveSettings(RenderGraphUtilsResources settings) => false;
11+
}
12+
}

Packages/com.unity.render-pipelines.core/Editor/RenderGraph/RenderGraphUtilsResourceStripper.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,18 @@ public ref ResourceReaderData ResourceReader(ResourceHandle h, int i)
136136
public NativeList<SubPassDescriptor> nativeSubPassData; //Tighty packed list of per nrp subpasses
137137

138138
// resources can be added as fragment both as input and output so make sure not to add them twice (return true upon new addition)
139-
public bool AddToFragmentList(ResourceHandle h, AccessFlags accessFlags, int listFirstIndex, int numItems)
139+
public bool AddToFragmentList(TextureAccess access, int listFirstIndex, int numItems)
140140
{
141141
#if DEVELOPMENT_BUILD || UNITY_EDITOR
142-
if (h.type != RenderGraphResourceType.Texture) new Exception("Only textures can be used as a fragment attachment.");
142+
if (access.textureHandle.handle.type != RenderGraphResourceType.Texture) new Exception("Only textures can be used as a fragment attachment.");
143143
#endif
144144
for (var i = listFirstIndex; i < listFirstIndex + numItems; ++i)
145145
{
146146
ref var fragment = ref fragmentData.ElementAt(i);
147-
if (fragment.resource.index == h.index)
147+
if (fragment.resource.index == access.textureHandle.handle.index)
148148
{
149149
#if DEVELOPMENT_BUILD || UNITY_EDITOR
150-
if (fragment.resource.version != h.version)
150+
if (fragment.resource.version != access.textureHandle.handle.version)
151151
{
152152
//this would mean you're trying to attach say both v1 and v2 of a resource to the same pass as an attachment
153153
//this is not allowed
@@ -164,8 +164,10 @@ public bool AddToFragmentList(ResourceHandle h, AccessFlags accessFlags, int lis
164164

165165
fragmentData.Add(new PassFragmentData()
166166
{
167-
resource = h,
168-
accessFlags = accessFlags
167+
resource = access.textureHandle.handle,
168+
accessFlags = access.flags,
169+
mipLevel = access.mipLevel,
170+
depthSlice = access.depthSlice,
169171
});
170172
return true;
171173
}

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,26 +175,24 @@ void BuildGraph()
175175
ctxPass.firstFragment = ctx.fragmentData.Length;
176176

177177
// Depth attachment is always at index 0
178-
if (inputPass.depthBuffer.handle.IsValid())
178+
if (inputPass.depthAccess.textureHandle.handle.IsValid())
179179
{
180180
ctxPass.fragmentInfoHasDepth = true;
181181

182-
var resource = inputPass.depthBuffer.handle;
183-
if (ctx.AddToFragmentList(resource, inputPass.depthBufferAccessFlags, ctxPass.firstFragment, ctxPass.numFragments))
182+
if (ctx.AddToFragmentList(inputPass.depthAccess, ctxPass.firstFragment, ctxPass.numFragments))
184183
{
185-
ctxPass.AddFragment(resource, ctx);
184+
ctxPass.AddFragment(inputPass.depthAccess.textureHandle.handle, ctx);
186185
}
187186
}
188187

189188
for (var ci = 0; ci < inputPass.colorBufferMaxIndex + 1; ++ci)
190189
{
191190
// Skip unused color slots
192-
if (!inputPass.colorBuffers[ci].handle.IsValid()) continue;
191+
if (!inputPass.colorBufferAccess[ci].textureHandle.handle.IsValid()) continue;
193192

194-
var resource = inputPass.colorBuffers[ci].handle;
195-
if (ctx.AddToFragmentList(resource, inputPass.colorBufferAccessFlags[ci], ctxPass.firstFragment, ctxPass.numFragments))
193+
if (ctx.AddToFragmentList(inputPass.colorBufferAccess[ci], ctxPass.firstFragment, ctxPass.numFragments))
196194
{
197-
ctxPass.AddFragment(resource, ctx);
195+
ctxPass.AddFragment(inputPass.colorBufferAccess[ci].textureHandle.handle, ctx);
198196
}
199197
}
200198

@@ -203,14 +201,13 @@ void BuildGraph()
203201

204202
for (var ci = 0; ci < inputPass.fragmentInputMaxIndex + 1; ++ci)
205203
{
206-
ref var currInpFragment = ref inputPass.fragmentInputs[ci].handle;
207204
// Skip unused fragment input slots
208-
if (!currInpFragment.IsValid()) continue;
205+
if (!inputPass.fragmentInputAccess[ci].textureHandle.IsValid()) continue;
209206

210-
var resource = inputPass.fragmentInputs[ci].handle;
211-
if (ctx.AddToFragmentList(resource, inputPass.fragmentInputAccessFlags[ci], ctxPass.firstFragmentInput, ctxPass.numFragmentInputs))
207+
var resource = inputPass.fragmentInputAccess[ci].textureHandle;
208+
if (ctx.AddToFragmentList(inputPass.fragmentInputAccess[ci], ctxPass.firstFragmentInput, ctxPass.numFragmentInputs))
212209
{
213-
ctxPass.AddFragmentInput(resource, ctx);
210+
ctxPass.AddFragmentInput(inputPass.fragmentInputAccess[ci].textureHandle.handle, ctx);
214211
}
215212
}
216213

@@ -885,6 +882,8 @@ void PrepareNativeRenderPass(ref NativePassData nativePass)
885882
ref var currStoreAudit = ref nativePass.storeAudit[idx];
886883
#endif
887884
currAttachment.handle = fragment.resource;
885+
currAttachment.mipLevel = fragment.mipLevel;
886+
currAttachment.depthSlice = fragment.depthSlice;
888887

889888
// Don't care by default
890889
currAttachment.loadAction = UnityEngine.Rendering.RenderBufferLoadAction.DontCare;
@@ -1212,7 +1211,7 @@ internal unsafe void ExecuteBeginRenderPass(InternalRenderGraphContext rgContext
12121211
//but that is why we mark this as a hack and future work to fix.
12131212
//The proper (and planned) solution would be to move away from the render texture duality.
12141213
RenderTargetIdentifier rtidAllSlices = rtHandle;
1215-
currBeginAttachment.loadStoreTarget = new RenderTargetIdentifier(rtidAllSlices, 0, CubemapFace.Unknown, -1);
1214+
currBeginAttachment.loadStoreTarget = new RenderTargetIdentifier(rtidAllSlices, attachments[i].mipLevel, CubemapFace.Unknown, attachments[i].depthSlice);
12161215

12171216
if (attachments[i].storeAction == RenderBufferStoreAction.Resolve ||
12181217
attachments[i].storeAction == RenderBufferStoreAction.StoreAndResolve)
@@ -1231,7 +1230,7 @@ internal unsafe void ExecuteBeginRenderPass(InternalRenderGraphContext rgContext
12311230
currBeginAttachment.clearColor = Color.red;
12321231
currBeginAttachment.clearDepth = 1.0f;
12331232
currBeginAttachment.clearStencil = 0;
1234-
var desc = resources.GetTextureResourceDesc(currAttachmentHandle);
1233+
var desc = resources.GetTextureResourceDesc(currAttachmentHandle, true);
12351234
if (i == 0 && nativePass.hasDepth)
12361235
{
12371236
// TODO: There seems to be no clear depth specified ?!?!

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,24 @@ internal struct PassFragmentData
2727
{
2828
public ResourceHandle resource;
2929
public AccessFlags accessFlags;
30+
public int mipLevel;
31+
public int depthSlice;
3032

3133
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3234
public override int GetHashCode()
3335
{
3436
var hash = resource.GetHashCode();
3537
hash = hash * 23 + accessFlags.GetHashCode();
38+
hash = hash * 23 + mipLevel.GetHashCode();
39+
hash = hash * 23 + depthSlice.GetHashCode();
3640
return hash;
3741
}
3842

3943
public static bool EqualForMerge(PassFragmentData x, PassFragmentData y)
4044
{
4145
// We ignore the version for now we assume if one pass writes version x and the next y they can
4246
// be merged in the same native render pass
43-
return x.resource.index == y.resource.index && x.accessFlags == y.accessFlags;
47+
return x.resource.index == y.resource.index && x.accessFlags == y.accessFlags && x.mipLevel == y.mipLevel && x.depthSlice == y.depthSlice;
4448
}
4549
}
4650

@@ -366,6 +370,8 @@ internal struct NativePassAttachment
366370
public UnityEngine.Rendering.RenderBufferLoadAction loadAction;
367371
public UnityEngine.Rendering.RenderBufferStoreAction storeAction;
368372
public bool memoryless;
373+
public int mipLevel;
374+
public int depthSlice;
369375
}
370376

371377
internal enum LoadReason

0 commit comments

Comments
 (0)