Skip to content

Commit ee884d0

Browse files
authored
Merge pull request #8276 from Unity-Technologies/internal/6000.4/staging
Mirror Internal/6000.4/staging
2 parents a91b63e + bce62e4 commit ee884d0

48 files changed

Lines changed: 736 additions & 289 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Packages/com.unity.render-pipelines.core/Editor/PathTracing/LightBakerStrangler.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,16 +940,18 @@ internal static Result ExecuteLightmapRequests(
940940
bool debugDispatches = integrationSettings.DebugDispatches;
941941
bool doDirectionality = AnyLightmapRequestHasOutput(lightmapRequestData.requests, LightmapRequestOutputType.DirectionalityDirect) || AnyLightmapRequestHasOutput(lightmapRequestData.requests, LightmapRequestOutputType.DirectionalityIndirect);
942942

943-
// Find the max index count in any mesh, so we can pre-allocate various buffers based on it.
943+
// Find the max index and vertex count in any mesh, so we can pre-allocate various buffers based on it.
944944
uint maxIndexCount = 1;
945+
uint maxVertexCount = 1;
945946
for (int meshIdx = 0; meshIdx < world.Meshes.Length; ++meshIdx)
946947
{
947948
maxIndexCount = Math.Max(maxIndexCount, world.Meshes[meshIdx].GetTotalIndexCount());
949+
maxVertexCount = Math.Max(maxVertexCount, (uint)world.Meshes[meshIdx].vertexCount);
948950
}
949951

950952
(int width, int height)[] atlasSizes = lightmapRequestData.atlassing.m_AtlasSizes;
951953
int initialLightmapResolution = atlasSizes.Length > 0 ? atlasSizes[0].width : 1024;
952-
if (!lightmappingContext.Initialize(deviceContext, initialLightmapResolution, initialLightmapResolution, world, maxIndexCount, lightmapResourceLib))
954+
if (!lightmappingContext.Initialize(deviceContext, initialLightmapResolution, initialLightmapResolution, world, maxIndexCount, maxVertexCount, lightmapResourceLib))
953955
return Result.InitializeFailure;
954956

955957
lightmappingContext.IntegratorContext.Initialize(samplingResources, lightmapResourceLib, !useLegacyBakingBehavior);

Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeVolume.hlsl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,7 @@ struct APVResources
7777

7878
struct APVResourcesRW
7979
{
80-
#ifdef SHADER_API_METAL
81-
// We need to use float4 on Metal, since HLSLcc will generate invalid MSL otherwise.
82-
// See https://jira.unity3d.com/browse/UUM-127198
83-
RWTexture3D<float4> L0_L1Rx;
84-
#else
8580
RWTexture3D<half4> L0_L1Rx;
86-
#endif
8781
RWTexture3D<unorm float4> L1G_L1Ry;
8882
RWTexture3D<unorm float4> L1B_L1Rz;
8983
RWTexture3D<unorm float4> L2_0;

Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeVolumeBlendStates.compute

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ Texture3D<float4> _State1_L0_L1Rx;
1515
Texture3D<float4> _State1_L1G_L1Ry;
1616
Texture3D<float4> _State1_L1B_L1Rz;
1717

18-
#ifdef SHADER_API_METAL
19-
// We need to use float4 on Metal, since HLSLcc will generate invalid MSL otherwise.
20-
// See https://jira.unity3d.com/browse/UUM-127198
21-
RWTexture3D<float4> _Out_L0_L1Rx;
22-
#else
2318
RWTexture3D<half4> _Out_L0_L1Rx;
24-
#endif
2519
RWTexture3D<unorm float4> _Out_L1G_L1Ry;
2620
RWTexture3D<unorm float4> _Out_L1B_L1Rz;
2721

Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeVolumeUploadData.compute

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@
99
#pragma multi_compile_local _ PROBE_VOLUMES_SKY_SHADING_DIRECTION
1010
#pragma multi_compile_local _ PROBE_VOLUMES_PROBE_OCCLUSION
1111

12-
#ifdef SHADER_API_METAL
13-
// We need to use float4 on Metal, since HLSLcc will generate invalid MSL otherwise.
14-
// See https://jira.unity3d.com/browse/UUM-127198
15-
RWTexture3D<float4> _Out_L0_L1Rx;
16-
#else
1712
RWTexture3D<half4> _Out_L0_L1Rx;
18-
#endif
1913
RWTexture3D<unorm float4> _Out_L1G_L1Ry;
2014
RWTexture3D<unorm float4> _Out_L1B_L1Rz;
2115

Packages/com.unity.render-pipelines.core/Runtime/PathTracing/LightmappingContext.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ internal bool InitializeExpandedBuffer(UInt64 expandedSize)
130130
return true;
131131
}
132132

133-
internal bool Initialize(UnityComputeDeviceContext deviceContext, int width, int height, UnityComputeWorld world, uint maxIndexCount, LightmapResourceLibrary resources)
133+
internal bool Initialize(UnityComputeDeviceContext deviceContext, int width, int height, UnityComputeWorld world, uint maxIndexCount, uint maxVertexCount, LightmapResourceLibrary resources)
134134
{
135135
_deviceContext = deviceContext;
136136
World = world;
137137
IntegratorContext = new LightmapIntegratorContext();
138138
ResourceCache = new LightmapIntegrationResourceCache();
139139

140140
ChartRasterizer = new ChartRasterizer(resources.SoftwareChartRasterizationShader, resources.HardwareChartRasterizationShader);
141-
InitializeChartRasterizationBuffers(maxIndexCount);
141+
InitializeChartRasterizationBuffers(maxIndexCount, maxVertexCount);
142142

143143
return SetOutputResolution(width, height);
144144
}
@@ -189,7 +189,7 @@ public void InitializeTraceScratchBuffer(uint width, uint height, uint expandedS
189189
}
190190
}
191191

192-
private void InitializeChartRasterizationBuffers(uint maxIndexCount)
192+
private void InitializeChartRasterizationBuffers(uint maxIndexCount, uint maxVertexCount)
193193
{
194194
ChartRasterizerBuffers.vertex?.Dispose();
195195
ChartRasterizerBuffers.vertex = null;
@@ -198,10 +198,11 @@ private void InitializeChartRasterizationBuffers(uint maxIndexCount)
198198
ChartRasterizerBuffers.vertexToChartID?.Dispose();
199199
ChartRasterizerBuffers.vertexToChartID = null;
200200

201-
// We base the size of the temporary buffers on the triangle count of the mesh with the most triangles, to avoid constant reallocations.
202-
ChartRasterizerBuffers.vertex = new GraphicsBuffer(GraphicsBuffer.Target.Structured, (int)maxIndexCount, UnsafeUtility.SizeOf<Vector2>());
203-
ChartRasterizerBuffers.vertexToOriginalVertex = new GraphicsBuffer(GraphicsBuffer.Target.Structured, (int)maxIndexCount, sizeof(uint));
204-
ChartRasterizerBuffers.vertexToChartID = new GraphicsBuffer(GraphicsBuffer.Target.Structured, (int)maxIndexCount, sizeof(uint));
201+
// We base the size of the temporary buffers on the vertex count or index count of the mesh with the most vertices / indices, to avoid constant reallocations.
202+
uint maxCount = Math.Max(maxIndexCount, maxVertexCount);
203+
ChartRasterizerBuffers.vertex = new GraphicsBuffer(GraphicsBuffer.Target.Structured, (int)maxCount, UnsafeUtility.SizeOf<Vector2>());
204+
ChartRasterizerBuffers.vertexToOriginalVertex = new GraphicsBuffer(GraphicsBuffer.Target.Structured, (int)maxCount, sizeof(uint));
205+
ChartRasterizerBuffers.vertexToChartID = new GraphicsBuffer(GraphicsBuffer.Target.Structured, (int)maxCount, sizeof(uint));
205206
}
206207

207208
public CommandBuffer GetCommandBuffer()

Packages/com.unity.render-pipelines.core/Runtime/PathTracing/Shaders/Lightmapping/ChartRasterizerSoftware.shader

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Shader "Hidden/ChartRasterizerSoftware"
1111
#pragma fragment frag
1212
#include "GeometryUtils.hlsl"
1313

14+
#define PARALLEL_EPS 1e-6f
15+
1416
struct v2f
1517
{
1618
float4 vertex : SV_POSITION;
@@ -34,7 +36,7 @@ Shader "Hidden/ChartRasterizerSoftware"
3436
uint2 resolution = uint2(g_Width, g_Height);
3537
float2 tri[3];
3638
ReadParentTriangle(g_VertexBuffer, vertexId, g_ScaleAndOffset, tri);
37-
ExpandTriangleForConservativeRasterization(resolution, tri, vertexId, o.aabb, o.vertex);
39+
ExpandTriangleForConservativeRasterization(resolution, tri, vertexId, o.aabb, o.vertex, PARALLEL_EPS);
3840

3941
// Get the chart index.
4042
uint originalVertexId = g_VertexToOriginalVertex[vertexId];

Packages/com.unity.render-pipelines.core/Runtime/PathTracing/Shaders/Lightmapping/GeometryUtils.hlsl

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void OffsetEdge(float2 v1, float2 v2, float2 pixelSize, out float2 v1Offset, out
1616
}
1717

1818
// Given 2 lines defined by 2 points each, find the intersection point.
19-
float2 LineIntersect(float2 p1, float2 p2, float2 p3, float2 p4)
19+
float2 LineIntersect(float2 p1, float2 p2, float2 p3, float2 p4, float eps = 0.0f)
2020
{
2121
// Line p1p2 represented as a1x + b1y = c1
2222
float a1 = p2.y - p1.y;
@@ -29,7 +29,7 @@ float2 LineIntersect(float2 p1, float2 p2, float2 p3, float2 p4)
2929
float c2 = a2 * p3.x + b2 * p3.y;
3030

3131
float determinant = a1 * b2 - a2 * b1;
32-
if (determinant == 0) // Parallel lines - return any valid point.
32+
if (abs(determinant) <= eps) // Parallel lines - return any valid point.
3333
return p1;
3434

3535
float x = b2 * c1 - b1 * c2;
@@ -46,7 +46,7 @@ bool IsInside(float2 p, float2 cp1, float2 cp2, float eps = 0.0f)
4646

4747
// Clip a polygon with a line defined by two points, in place.
4848
// https://en.wikipedia.org/wiki/Sutherland-Hodgman_algorithm
49-
void ClipPolygonWithLine(inout float2 polygon[6], inout uint polygonLength, float2 cp1, float2 cp2)
49+
void ClipPolygonWithLine(inout float2 polygon[6], inout uint polygonLength, float2 cp1, float2 cp2, float inside_eps = 0.0f, float parallel_eps = 0.0f)
5050
{
5151
float2 result[6];
5252
uint resultLength = 0;
@@ -56,19 +56,19 @@ void ClipPolygonWithLine(inout float2 polygon[6], inout uint polygonLength, floa
5656
float2 s = polygon[i];
5757
float2 e = polygon[(i + 1) % polygonLength];
5858

59-
if (IsInside(e, cp1, cp2)) // At least one endpoint is inside
59+
if (IsInside(e, cp1, cp2, inside_eps)) // At least one endpoint is inside
6060
{
61-
if (!IsInside(s, cp1, cp2)) // Only the end point is inside, add the intersection
61+
if (!IsInside(s, cp1, cp2, inside_eps)) // Only the end point is inside, add the intersection
6262
{
63-
result[resultLength] = LineIntersect(cp1, cp2, s, e);
63+
result[resultLength] = LineIntersect(cp1, cp2, s, e, parallel_eps);
6464
resultLength++;
6565
}
6666
result[resultLength] = e;
6767
resultLength++;
6868
}
69-
else if (IsInside(s, cp1, cp2)) // Only the start point is inside, add the intersection
69+
else if (IsInside(s, cp1, cp2, inside_eps)) // Only the start point is inside, add the intersection
7070
{
71-
result[resultLength] = LineIntersect(cp1, cp2, s, e);
71+
result[resultLength] = LineIntersect(cp1, cp2, s, e, parallel_eps);
7272
resultLength++;
7373
}
7474
}
@@ -79,7 +79,7 @@ void ClipPolygonWithLine(inout float2 polygon[6], inout uint polygonLength, floa
7979
}
8080

8181
// Clip a polygon to the bounding box of a texel at the given position
82-
bool ClipPolygonWithTexel(float2 texelPosition, inout float2 polygon[6], inout uint polygonLength)
82+
bool ClipPolygonWithTexel(float2 texelPosition, inout float2 polygon[6], inout uint polygonLength, float inside_eps = 0.0f, float parallel_eps = 0.0f)
8383
{
8484
// Get the bounding box of the texel to clip with.
8585
float2 clipPolygon[4] =
@@ -93,7 +93,7 @@ bool ClipPolygonWithTexel(float2 texelPosition, inout float2 polygon[6], inout u
9393
// Clip to each edge of the quad
9494
for (uint edge = 0; edge < 4; edge++)
9595
{
96-
ClipPolygonWithLine(polygon, polygonLength, clipPolygon[edge], clipPolygon[(edge + 1) % 4]);
96+
ClipPolygonWithLine(polygon, polygonLength, clipPolygon[edge], clipPolygon[(edge + 1) % 4], inside_eps, parallel_eps);
9797
}
9898

9999
return polygonLength > 0;
@@ -128,7 +128,8 @@ void ExpandTriangleForConservativeRasterization(
128128
float2 tri[3],
129129
uint vertexId,
130130
out float4 triangleAABB,
131-
out float4 vertex)
131+
out float4 vertex,
132+
float eps = 0.0f)
132133
{
133134
float2 pixelSize = (1.0 / resolution);
134135

@@ -146,9 +147,9 @@ void ExpandTriangleForConservativeRasterization(
146147
OffsetEdge(tri[2], tri[0], pixelSize, v3Off3, v1Off3);
147148

148149
// Find their intersections. This is the new triangle
149-
tri[0] = LineIntersect(v1Off1, v2Off1, v3Off3, v1Off3);
150-
tri[1] = LineIntersect(v2Off2, v3Off2, v1Off1, v2Off1);
151-
tri[2] = LineIntersect(v3Off3, v1Off3, v2Off2, v3Off2);
150+
tri[0] = LineIntersect(v1Off1, v2Off1, v3Off3, v1Off3, eps);
151+
tri[1] = LineIntersect(v2Off2, v3Off2, v1Off1, v2Off1, eps);
152+
tri[2] = LineIntersect(v3Off3, v1Off3, v2Off2, v3Off2, eps);
152153
vertex = float4(tri[vertexId % 3]*2-1, 0, 1);
153154
#if UNITY_UV_STARTS_AT_TOP
154155
vertex.y = -vertex.y;

Packages/com.unity.render-pipelines.core/Runtime/PathTracing/Shaders/Lightmapping/UVFallbackBufferGeneration.shader

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Shader "Hidden/UVFallbackBufferGeneration"
1212
#pragma target 5.0
1313
#include "GeometryUtils.hlsl"
1414

15+
#define INSIDE_EPS 0.01f // Epsilon chosen to be 1 order of magnitude larger than the maximum
16+
// distance between subsequent floats in range [0; 8192]
17+
#define PARALLEL_EPS 1e-6f
18+
1519
struct v2f
1620
{
1721
float4 vertex : SV_POSITION;
@@ -32,8 +36,9 @@ Shader "Hidden/UVFallbackBufferGeneration"
3236
uint2 resolution = uint2(g_Width, g_Height);
3337
float2 tri[3];
3438
float4 unusedAABB;
39+
const float eps = 0.01f;
3540
ReadParentTriangle(g_VertexBuffer, vertexId, float4(g_WidthScale, g_HeightScale, 0, 0), tri);
36-
ExpandTriangleForConservativeRasterization(resolution, tri, vertexId, unusedAABB, o.vertex);
41+
ExpandTriangleForConservativeRasterization(resolution, tri, vertexId, unusedAABB, o.vertex, PARALLEL_EPS);
3742

3843
// Scale the triangle to screen coordinates, pass it to fragment shader.
3944
o.vertices[0] = tri[0] * resolution;
@@ -54,8 +59,7 @@ Shader "Hidden/UVFallbackBufferGeneration"
5459
// as our intersector cannot handle such points. Epsilon chosen to be 1 order of magnitude larger than the maximum
5560
// distance between subsequent floats in range [0; 8192]
5661
float2 texelCenter = i.vertex.xy;
57-
const float eps = 0.01f;
58-
if (IsInside(texelCenter, c, b, eps) && IsInside(texelCenter, b, a, eps) && IsInside(texelCenter, a, c, eps))
62+
if (IsInside(texelCenter, c, b, INSIDE_EPS) && IsInside(texelCenter, b, a, INSIDE_EPS) && IsInside(texelCenter, a, c, INSIDE_EPS))
5963
{
6064
#if UNITY_REVERSED_Z
6165
depth = 1.0;
@@ -70,7 +74,7 @@ Shader "Hidden/UVFallbackBufferGeneration"
7074
uint resultSize = 3;
7175

7276
// Clip to the texel.
73-
ClipPolygonWithTexel(texelCenter, result, resultSize);
77+
ClipPolygonWithTexel(texelCenter, result, resultSize, INSIDE_EPS, PARALLEL_EPS);
7478

7579
// Discard removed triangles.
7680
if (resultSize <= 0)

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ internal enum TextureUVOriginSelection
9797
/// </summary>
9898
[DebuggerDisplay("Texture ({handle.index})")]
9999
[MovedFrom(true, "UnityEngine.Experimental.Rendering.RenderGraphModule", "UnityEngine.Rendering.RenderGraphModule")]
100-
public readonly struct TextureHandle
100+
public readonly struct TextureHandle : IEquatable<TextureHandle>
101101
{
102102
private static TextureHandle s_NullHandle = new TextureHandle();
103103

@@ -151,6 +151,52 @@ internal TextureHandle(int handle, bool shared = false, bool builtin = false)
151151
/// <returns>Resource as a RTHandle.</returns>
152152
public static implicit operator RTHandle(TextureHandle texture) => texture.IsValid() ? RenderGraphResourceRegistry.current.GetTexture(texture) : null;
153153

154+
/// <summary>
155+
/// Determines whether this instance and another specified <see cref="TextureHandle"/> object have the same underlying resource handle.
156+
/// </summary>
157+
/// <param name="other">The texture handle to compare with the current instance.</param>
158+
/// <returns>
159+
/// True if both texture handles reference the same underlying resource; otherwise, false.
160+
/// </returns>
161+
public bool Equals(TextureHandle other) => handle.Equals(other.handle);
162+
163+
/// <summary>
164+
/// Determines whether the specified object is equal to the current <see cref="TextureHandle"/>.
165+
/// </summary>
166+
/// <param name="obj">The object to compare with the current instance.</param>
167+
/// <returns>
168+
/// True if the specified object is a <see cref="TextureHandle"/> and references the same underlying resource; otherwise, false.
169+
/// </returns>
170+
public override bool Equals(object obj) => obj is TextureHandle other && Equals(other);
171+
172+
/// <summary>
173+
/// Returns the hash code for this <see cref="TextureHandle"/>.
174+
/// </summary>
175+
/// <returns>
176+
/// The hash code of the current <see cref="TextureHandle"/>.
177+
/// </returns>
178+
public override int GetHashCode() => handle.GetHashCode();
179+
180+
/// <summary>
181+
/// Determines whether two <see cref="TextureHandle"/> instances reference the same underlying resource.
182+
/// </summary>
183+
/// <param name="lhs">The first texture handle to compare.</param>
184+
/// <param name="rhs">The second texture handle to compare.</param>
185+
/// <returns>
186+
/// True if both handles reference the same underlying resource; otherwise, false.
187+
/// </returns>
188+
public static bool operator ==(TextureHandle lhs, TextureHandle rhs) => lhs.handle.Equals(rhs.handle);
189+
190+
/// <summary>
191+
/// Determines whether two <see cref="TextureHandle"/> instances reference different underlying resources.
192+
/// </summary>
193+
/// <param name="lhs">The first texture handle to compare.</param>
194+
/// <param name="rhs">The second texture handle to compare.</param>
195+
/// <returns>
196+
/// True if the handles reference different underlying resources; otherwise, false.
197+
/// </returns>
198+
public static bool operator !=(TextureHandle lhs, TextureHandle rhs) => !lhs.handle.Equals(rhs.handle);
199+
154200
/// <summary>
155201
/// Return true if the handle is valid.
156202
/// </summary>

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ public bool Equals(ResourceHandle hdl)
123123
{
124124
return hdl.m_Value == this.m_Value && hdl.m_Version == this.m_Version && hdl.type == this.type;
125125
}
126+
127+
public static bool operator ==(ResourceHandle lhs, ResourceHandle rhs) => lhs.Equals(rhs);
128+
129+
public static bool operator !=(ResourceHandle lhs, ResourceHandle rhs) => !lhs.Equals(rhs);
130+
131+
public override bool Equals(object obj) => obj is ResourceHandle other && Equals(other);
132+
133+
public override int GetHashCode()
134+
{
135+
var hashCode = HashFNV1A32.Create();
136+
hashCode.Append(m_Value);
137+
hashCode.Append(m_Version);
138+
hashCode.Append(m_Type);
139+
return hashCode.value;
140+
}
126141
}
127142

128143
class IRenderGraphResource

0 commit comments

Comments
 (0)