Skip to content

Commit 5db5bca

Browse files
Merge pull request #8205 from Unity-Technologies/internal/2022.3/staging
Internal/2022.3/staging
2 parents 25cc3f7 + fe00b0b commit 5db5bca

File tree

9 files changed

+122
-65
lines changed

9 files changed

+122
-65
lines changed

Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blitter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static void Initialize(Shader blitPS, Shader blitColorAndDepthPS)
6969
s_BlitTexArraySingleSlice.EnableKeyword("BLIT_SINGLE_SLICE");
7070
}
7171

72-
if (SystemInfo.graphicsShaderLevel < 30)
72+
if (SystemInfo.graphicsShaderLevel <= 30)
7373
{
7474
/*UNITY_NEAR_CLIP_VALUE*/
7575
float nearClipZ = -1;
@@ -186,15 +186,15 @@ static public Material GetBlitMaterial(TextureDimension dimension, bool singleSl
186186

187187
static private void DrawTriangle(CommandBuffer cmd, Material material, int shaderPass)
188188
{
189-
if (SystemInfo.graphicsShaderLevel < 30)
189+
if (SystemInfo.graphicsShaderLevel <= 30)
190190
cmd.DrawMesh(s_TriangleMesh, Matrix4x4.identity, material, 0, shaderPass, s_PropertyBlock);
191191
else
192192
cmd.DrawProcedural(Matrix4x4.identity, material, shaderPass, MeshTopology.Triangles, 3, 1, s_PropertyBlock);
193193
}
194194

195195
static internal void DrawQuad(CommandBuffer cmd, Material material, int shaderPass)
196196
{
197-
if (SystemInfo.graphicsShaderLevel < 30)
197+
if (SystemInfo.graphicsShaderLevel <= 30)
198198
cmd.DrawMesh(s_QuadMesh, Matrix4x4.identity, material, 0, shaderPass, s_PropertyBlock);
199199
else
200200
cmd.DrawProcedural(Matrix4x4.identity, material, shaderPass, MeshTopology.Quads, 4, 1, s_PropertyBlock);

Packages/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/CustomPass/CustomPassDrawer.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ void DoCommonSettingsGUI(ref Rect rect)
172172
{
173173
EditorGUI.PropertyField(rect, m_TargetDepthBuffer, Styles.targetDepthBuffer);
174174
rect.y += Styles.defaultLineSpace;
175+
176+
CustomPass.TargetBuffer requestedDepth = m_TargetDepthBuffer.GetEnumValue<CustomPass.TargetBuffer>();
177+
if (m_CustomPass.getConstrainedDepthBuffer() != requestedDepth)
178+
{
179+
Rect helpBoxRect = rect;
180+
float helpBoxHeight = EditorGUIUtility.singleLineHeight * 2;
181+
helpBoxRect.height = helpBoxHeight;
182+
EditorGUI.HelpBox(helpBoxRect, "Camera depth isn't supported when dynamic scaling is on. We will automatically fall back to not doing depth-testing for this pass.", MessageType.Warning);
183+
rect.y += helpBoxHeight;
184+
}
175185
}
176186

177187
if ((commonPassUIFlags & PassUIFlag.ClearFlags) != 0)
@@ -264,6 +274,13 @@ internal float GetPropertyHeight(SerializedProperty property, GUIContent label)
264274
}
265275

266276
height += Styles.defaultLineSpace * lines;
277+
278+
// Add height for the help box if it will be shown
279+
if ((commonPassUIFlags & PassUIFlag.TargetDepthBuffer) != 0 &&
280+
m_CustomPass.getConstrainedDepthBuffer() != m_TargetDepthBuffer.GetEnumValue<CustomPass.TargetBuffer>())
281+
{
282+
height += EditorGUIUtility.singleLineHeight * 2; // Help box height
283+
}
267284
}
268285

269286
return height + GetPassHeight(property);

Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BS
643643
#if SHADEROPTIONS_AREA_LIGHTS
644644
if (featureFlags & LIGHTFEATUREFLAGS_AREA)
645645
{
646-
uint lightCount, lightStart;
646+
uint lightCount, lightStart; // Start is the offset specific to the tile (or cluster)
647647

648648
#ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
649649
GetCountAndStart(posInput, LIGHTCATEGORY_AREA, lightStart, lightCount);
@@ -652,43 +652,57 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BS
652652
lightStart = _PunctualLightCount;
653653
#endif
654654

655-
// COMPILER BEHAVIOR WARNING!
656-
// If rectangle lights are before line lights, the compiler will duplicate light matrices in VGPR because they are used differently between the two types of lights.
657-
// By keeping line lights first we avoid this behavior and save substantial register pressure.
658-
// TODO: This is based on the current Lit.shader and can be different for any other way of implementing area lights, how to be generic and ensure performance ?
655+
bool fastPath = false;
656+
#if SCALARIZE_LIGHT_LOOP
657+
uint lightStartLane0;
658+
fastPath = IsFastPath(lightStart, lightStartLane0); // True if all pixels belong to the same tile (or cluster)
659659

660-
if (lightCount > 0)
660+
if (fastPath)
661661
{
662-
i = 0;
663-
664-
uint last = lightCount - 1;
665-
LightData lightData = FetchLight(lightStart, i);
662+
lightStart = lightStartLane0;
663+
}
664+
#endif
666665

667-
while (i <= last && lightData.lightType == GPULIGHTTYPE_TUBE)
668-
{
669-
lightData.lightType = GPULIGHTTYPE_TUBE; // Enforce constant propagation
670-
lightData.cookieMode = COOKIEMODE_NONE; // Enforce constant propagation
666+
// Scalarized loop. All lights that are in a tile/cluster touched by any pixel in the wave are loaded (scalar load), only the one relevant to current thread/pixel are processed.
667+
// For clarity, the following code will follow the convention: variables starting with s_ are meant to be wave uniform (meant for scalar register),
668+
// v_ are variables that might have different value for each thread in the wave (meant for vector registers).
669+
// This will perform more loads than it is supposed to, however, the benefits should offset the downside, especially given that light data accessed should be largely coherent.
670+
// Note that the above is valid only if wave intriniscs are supported.
671+
uint v_lightListOffset = 0;
672+
uint v_lightIdx = lightStart;
671673

672-
if (IsMatchingLightLayer(lightData.lightLayers, builtinData.renderingLayers))
673-
{
674-
DirectLighting lighting = EvaluateBSDF_Area(context, V, posInput, preLightData, lightData, bsdfData, builtinData);
675-
AccumulateDirectLighting(lighting, aggregateLighting);
676-
}
674+
#if NEED_TO_CHECK_HELPER_LANE
675+
// On some platform helper lanes don't behave as we'd expect, therefore we prevent them from entering the loop altogether.
676+
// IMPORTANT! This has implications if ddx/ddy is used on results derived from lighting, however given Lightloop is called in compute we should be
677+
// sure it will not happen.
678+
bool isHelperLane = WaveIsHelperLane();
679+
while (!isHelperLane && v_lightListOffset < lightCount)
680+
#else
681+
while (v_lightListOffset < lightCount)
682+
#endif
683+
{
684+
v_lightIdx = FetchIndex(lightStart, v_lightListOffset);
685+
#if SCALARIZE_LIGHT_LOOP
686+
uint s_lightIdx = ScalarizeElementIndex(v_lightIdx, fastPath);
687+
#else
688+
uint s_lightIdx = v_lightIdx;
689+
#endif
690+
if (s_lightIdx == -1)
691+
break;
677692

678-
lightData = FetchLight(lightStart, min(++i, last));
679-
}
693+
LightData s_lightData = FetchLight(s_lightIdx);
680694

681-
while (i <= last) // GPULIGHTTYPE_RECTANGLE
695+
// If current scalar and vector light index match, we process the light. The v_lightListOffset for current thread is increased.
696+
// Note that the following should really be ==, however, since helper lanes are not considered by WaveActiveMin, such helper lanes could
697+
// end up with a unique v_lightIdx value that is smaller than s_lightIdx hence being stuck in a loop. All the active lanes will not have this problem.
698+
if (s_lightIdx >= v_lightIdx)
682699
{
683-
lightData.lightType = GPULIGHTTYPE_RECTANGLE; // Enforce constant propagation
684-
685-
if (IsMatchingLightLayer(lightData.lightLayers, builtinData.renderingLayers))
700+
v_lightListOffset++;
701+
if (IsMatchingLightLayer(s_lightData.lightLayers, builtinData.renderingLayers))
686702
{
687-
DirectLighting lighting = EvaluateBSDF_Area(context, V, posInput, preLightData, lightData, bsdfData, builtinData);
703+
DirectLighting lighting = EvaluateBSDF_Area(context, V, posInput, preLightData, s_lightData, bsdfData, builtinData);
688704
AccumulateDirectLighting(lighting, aggregateLighting);
689705
}
690-
691-
lightData = FetchLight(lightStart, min(++i, last));
692706
}
693707
}
694708
}

Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPass.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ internal ProfilingSampler profilingSampler
5252
/// </summary>
5353
public TargetBuffer targetDepthBuffer;
5454

55+
// The actual depth buffer has to follow some constraints, and thus may not be the same result as the target
56+
// depth buffer that the user has requested. Apply these constraints and return a result.
57+
internal TargetBuffer getConstrainedDepthBuffer()
58+
{
59+
TargetBuffer depth = targetDepthBuffer;
60+
if (depth == TargetBuffer.Camera &&
61+
HDRenderPipeline.currentAsset.currentPlatformRenderPipelineSettings.dynamicResolutionSettings.enabled &&
62+
currentHDCamera.allowDynamicResolution &&
63+
injectionPoint == CustomPassInjectionPoint.AfterPostProcess)
64+
{
65+
// This custom pass is injected after postprocessing, and Dynamic Resolution Scaling is enabled, which
66+
// means an upscaler is active. In this case, the camera color buffer is the full display resolution,
67+
// but the camera depth buffer is a lower, pre-upscale resolution. So we cannot do depth testing here.
68+
depth = TargetBuffer.None;
69+
}
70+
return depth;
71+
}
72+
5573
/// <summary>
5674
/// What clear to apply when the color and depth buffer are bound
5775
/// </summary>
@@ -272,7 +290,7 @@ virtual internal void ExecuteInternal(RenderGraph renderGraph, HDCamera hdCamera
272290
customPass.isExecuting = false;
273291

274292
// Set back the camera color buffer if we were using a custom buffer as target
275-
if (customPass.targetDepthBuffer != TargetBuffer.Camera)
293+
if (customPass.getConstrainedDepthBuffer() != TargetBuffer.Camera)
276294
CoreUtils.SetRenderTarget(ctx.cmd, outputColorBuffer);
277295
});
278296
}
@@ -309,16 +327,17 @@ bool IsMSAAEnabled(HDCamera hdCamera)
309327
// This function must be only called from the ExecuteInternal method (requires current render target and current RT manager)
310328
void SetCustomPassTarget(CommandBuffer cmd)
311329
{
330+
TargetBuffer depth = getConstrainedDepthBuffer();
312331
// In case all the buffer are set to none, we can't bind anything
313-
if (targetColorBuffer == TargetBuffer.None && targetDepthBuffer == TargetBuffer.None)
332+
if (targetColorBuffer == TargetBuffer.None && depth == TargetBuffer.None)
314333
return;
315334

316335
RTHandle colorBuffer = (targetColorBuffer == TargetBuffer.Custom) ? currentRenderTarget.customColorBuffer.Value : currentRenderTarget.colorBufferRG;
317-
RTHandle depthBuffer = (targetDepthBuffer == TargetBuffer.Custom) ? currentRenderTarget.customDepthBuffer.Value : currentRenderTarget.depthBufferRG;
336+
RTHandle depthBuffer = (depth == TargetBuffer.Custom) ? currentRenderTarget.customDepthBuffer.Value : currentRenderTarget.depthBufferRG;
318337

319-
if (targetColorBuffer == TargetBuffer.None && targetDepthBuffer != TargetBuffer.None)
338+
if (targetColorBuffer == TargetBuffer.None && depth != TargetBuffer.None)
320339
CoreUtils.SetRenderTarget(cmd, depthBuffer, clearFlags);
321-
else if (targetColorBuffer != TargetBuffer.None && targetDepthBuffer == TargetBuffer.None)
340+
else if (targetColorBuffer != TargetBuffer.None && depth == TargetBuffer.None)
322341
CoreUtils.SetRenderTarget(cmd, colorBuffer, clearFlags);
323342
else
324343
{

Packages/com.unity.render-pipelines.universal/Editor/2D/LightBatchingDebugger/LightBatchingDebugger.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private void ViewBatch(int index)
162162

163163
foreach (var obj in batch1.Lights)
164164
{
165-
if(obj != null)
165+
if (obj != null)
166166
lightBubble1.Add(MakePill(obj));
167167
}
168168

@@ -241,7 +241,7 @@ private void CompareBatch(int index1, int index2)
241241
lightBubble1.Clear();
242242
foreach (var obj in lightSet1)
243243
{
244-
if(obj != null)
244+
if (obj != null)
245245
lightBubble1.Add(MakePill(obj));
246246
}
247247

@@ -255,7 +255,7 @@ private void CompareBatch(int index1, int index2)
255255
lightBubble2.Clear();
256256
foreach (var obj in lightSet2)
257257
{
258-
if(obj != null)
258+
if (obj != null)
259259
lightBubble2.Add(MakePill(obj));
260260
}
261261

@@ -391,7 +391,7 @@ private void OnSelectionChanged()
391391
var firstIndex = batchListView.selectedIndices.First();
392392
var secondIndex = batchListView.selectedIndices.Last();
393393

394-
if(secondIndex > firstIndex + 1 || secondIndex < firstIndex - 1)
394+
if (secondIndex > firstIndex + 1 || secondIndex < firstIndex - 1)
395395
{
396396
// Clamp since we do adjacent batch comparisons
397397
secondIndex = Mathf.Clamp(secondIndex, firstIndex - 1, firstIndex + 1);
@@ -408,7 +408,7 @@ private void OnSelectionChanged()
408408

409409
default:
410410
// Account for multiple select either with shift or ctrl keys
411-
if(batchListView.selectedIndices.Count() > 2)
411+
if (batchListView.selectedIndices.Count() > 2)
412412
{
413413
if (selectedIndices.Count == 1)
414414
{
@@ -466,8 +466,12 @@ private bool IsDirty()
466466
isDirty |= Light2DManager.GetCachedSortingLayer().Count() != batchList.Sum(x => x.LayerNames.Count());
467467
isDirty |= cachedSceneHandle != SceneManager.GetActiveScene().handle;
468468
isDirty |= cachedCamPos != Camera.main?.transform.position;
469-
isDirty |= totalLightCount != lightCullResult.visibleLights.Count();
470-
isDirty |= totalShadowCount != lightCullResult.visibleShadows.Count();
469+
470+
if (lightCullResult.IsGameView())
471+
{
472+
isDirty |= totalLightCount != lightCullResult.visibleLights.Count();
473+
isDirty |= totalShadowCount != lightCullResult.visibleShadows.Count();
474+
}
471475

472476
return isDirty;
473477
}

Packages/com.unity.render-pipelines.universal/Editor/2D/Renderer2DMenus.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ internal static void Place(GameObject go, GameObject parent)
7676

7777
static Light2D CreateLight(MenuCommand menuCommand, Light2D.LightType type, Vector3[] shapePath = null)
7878
{
79-
GameObject go = ObjectFactory.CreateGameObject("Light 2D", typeof(Light2D));
79+
var lightName = type != Light2D.LightType.Point ? type.ToString() : "Spot";
80+
GameObject go = ObjectFactory.CreateGameObject(lightName + " Light 2D", typeof(Light2D));
8081
Light2D light2D = go.GetComponent<Light2D>();
8182
light2D.lightType = type;
8283

Packages/com.unity.render-pipelines.universal/Shaders/Utils/ScreenSpaceShadows.shader

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ Shader "Hidden/Universal Render Pipeline/ScreenSpaceShadows"
2020
{
2121
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
2222

23-
#if UNITY_REVERSED_Z
24-
float deviceDepth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_PointClamp, input.texcoord.xy).r;
25-
#else
26-
float deviceDepth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_PointClamp, input.texcoord.xy).r;
23+
float deviceDepth = LoadSceneDepth(input.positionCS.xy);
24+
#if !UNITY_REVERSED_Z
2725
deviceDepth = deviceDepth * 2.0 - 1.0;
2826
#endif
2927

Packages/com.unity.shadergraph/Editor/Data/Nodes/UV/ParallaxOcclusionMappingNode.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace UnityEditor.ShaderGraph
1010
[Title("UV", "Parallax Occlusion Mapping")]
1111
[FormerName("UnityEditor.Experimental.Rendering.HDPipeline.ParallaxOcclusionMappingNode")]
1212
[FormerName("UnityEditor.Rendering.HighDefinition.ParallaxOcclusionMappingNode")]
13-
class ParallaxOcclusionMappingNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction, IMayRequireViewDirection, IMayRequireMeshUV
13+
class ParallaxOcclusionMappingNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction, IMayRequireViewDirection, IMayRequireMeshUV, IMayRequireTransform
1414
{
1515
public ParallaxOcclusionMappingNode()
1616
{
@@ -220,6 +220,8 @@ public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMo
220220
");
221221
}
222222

223+
public NeededTransform[] RequiresTransform(ShaderStageCapability stageCapability = ShaderStageCapability.All) => new[] { NeededTransform.WorldToObject };
224+
223225
public NeededCoordinateSpace RequiresViewDirection(ShaderStageCapability stageCapability = ShaderStageCapability.All)
224226
{
225227
return NeededCoordinateSpace.Tangent;

0 commit comments

Comments
 (0)