Skip to content

Commit c11b91f

Browse files
Fix null geometry support
It was causing an issue on vulkan & d3d12 (and a warning in dx11) for planar primitive. Took inspiration from the initial (dead code) "ModifyVertexEntry" : https://github.com/Unity-Technologies/Graphics/blob/2773810e9fb5e893e2d207ff048586414cc387e4/com.unity.render-pipelines.high-definition/Editor/VFXGraph/VFXHDRPSubTarget.cs#L132 There isn't a common factorization like @sebastienlagarde did with 2773810#diff-7174c990ca8df27503bf5973a949e19bc00cf239832d30b20b2a69167667272eL102 in URP, so, I'm restoring an optionnal "description" driven replacement of pragmas. See also this thread https://unity.slack.com/archives/C01Q3N39UEB/p1629821649001500
1 parent 2cadcdb commit c11b91f

File tree

10 files changed

+68
-4
lines changed

10 files changed

+68
-4
lines changed

com.unity.render-pipelines.high-definition/Editor/VFXGraph/VFXHDRPBinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public override IEnumerable<KeyValuePair<Type, string>> GetUnsupportedShaderProp
130130
HDStructFields.AttributesMesh.indices,
131131

132132
// VertexID without the Preprocessor.
133-
new FieldDescriptor(HDStructFields.AttributesMesh.name, "vertexID", "ATTRIBUTES_NEED_VERTEXID", ShaderValueType.Uint, "SV_VertexID")
133+
new FieldDescriptor(HDStructFields.AttributesMesh.name, "vertexID", "ATTRIBUTES_NEED_VERTEXID", ShaderValueType.Uint, "VERTEXID_SEMANTIC")
134134
}
135135
};
136136

com.unity.render-pipelines.universal/Editor/ShaderGraph/Templates/ShaderPass.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,11 @@ $features.graphPixel: $include("SharedCode.template.hlsl")
128128

129129
$splice(PostGraphIncludes)
130130

131+
// --------------------------------------------------
132+
// Visual Effect Vertex Invocations
133+
#ifdef HAVE_VFX_MODIFICATION
134+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/VisualEffectVertex.hlsl"
135+
#endif
136+
131137
ENDHLSL
132138
}

com.unity.render-pipelines.universal/Editor/ShaderGraph/Templates/VFX/Config.template.hlsl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ $splice(VFXDefineSpace)
55
//VFXDefines splice
66
$splice(VFXDefines)
77

8-
//TODOPAUL See VisualEffectVertex.hlsl in HDRP, special case for null geometry
9-
//TODOPAUL Test on vulkan/DX12
108
#define NULL_GEOMETRY_INPUT defined(HAVE_VFX_PLANAR_PRIMITIVE)
119

1210
// Explicitly defined here for now (similar to how it was done in the previous VFX code-gen)

com.unity.render-pipelines.universal/Editor/ShaderGraph/Templates/VFX/ConfigPlanarPrimitive.template.hlsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
// Output Type: Planar Primitive (Triangle, Quad, Octagon)
2+
//TODOPAUL : Factorize this file with HDRP moving it in VFX
23

34
#if defined(HAS_STRIPS) && !defined(VFX_PRIMITIVE_QUAD)
45
#error VFX_PRIMITIVE_QUAD must be defined when HAS_STRIPS is.
56
#endif
67

78
#define VFX_NON_UNIFORM_SCALE VFX_LOCAL_SPACE
89

10+
#define HAVE_VFX_PLANAR_PRIMITIVE
11+
912
bool GetMeshAndElementIndex(inout Attributes input, inout AttributesElement element)
1013
{
1114
uint id = input.vertexID;

com.unity.render-pipelines.universal/Editor/VFXGraph/VFXURPBinder.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public override VFXAbstractRenderedOutput.BlendMode GetBlendModeFromMaterial(VFX
9090
StructFields.Attributes.indices,
9191

9292
// VertexID without the Preprocessor.
93-
new FieldDescriptor(StructFields.Attributes.name, "vertexID", "ATTRIBUTES_NEED_VERTEXID", ShaderValueType.Uint, "SV_VertexID")
93+
new FieldDescriptor(StructFields.Attributes.name, "vertexID", "ATTRIBUTES_NEED_VERTEXID", ShaderValueType.Uint, "VERTEXID_SEMANTIC")
9494
}
9595
};
9696

@@ -187,6 +187,10 @@ public override ShaderGraphBinder GetShaderGraphDescriptor(VFXContext context, V
187187
},
188188

189189
fieldDependencies = ElementSpaceDependencies,
190+
pragmasReplacement = new (PragmaDescriptor, PragmaDescriptor)[]
191+
{
192+
( Pragma.Vertex("vert"), Pragma.Vertex("VertVFX") )
193+
},
190194
useFragInputs = false
191195
};
192196
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Wrapper vertex invocations for VFX. Necesarry to work around various null input geometry issues for vertex input layout on DX12 and Vulkan.
2+
#if NULL_GEOMETRY_INPUT
3+
PackedVaryings VertVFX(uint vertexID : VERTEXID_SEMANTIC, uint instanceID : INSTANCEID_SEMANTIC)
4+
{
5+
Attributes input;
6+
ZERO_INITIALIZE(Attributes, input);
7+
8+
input.vertexID = vertexID;
9+
input.instanceID = instanceID;
10+
11+
return vert(input);
12+
}
13+
#else
14+
PackedVaryings VertVFX(Attributes input)
15+
{
16+
return vert(input);
17+
}
18+
#endif

com.unity.render-pipelines.universal/ShaderLibrary/VisualEffectVertex.hlsl.meta

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

com.unity.shadergraph/Editor/Generation/Templates/PassMesh.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,11 @@ Pass
127127

128128
$splice(PostGraphIncludes)
129129

130+
// --------------------------------------------------
131+
// Visual Effect Vertex Invocations
132+
#ifdef HAVE_VFX_MODIFICATION
133+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/VisualEffectVertex.hlsl"
134+
#endif
135+
130136
ENDHLSL
131137
}

com.unity.visualeffectgraph/Editor/Core/VFXSRPBinder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public struct ShaderGraphBinder
1818
{
1919
public StructCollection structs;
2020
public DependencyCollection fieldDependencies;
21+
public (PragmaDescriptor oldDesc, PragmaDescriptor newDesc)[] pragmasReplacement;
2122
public bool useFragInputs;
2223
}
2324

com.unity.visualeffectgraph/Editor/ShaderGraph/VFXSubTarget.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,25 @@ static AdditionalCommandDescriptor GenerateFragInputs(VFXContext context, VFXCon
231231
return new AdditionalCommandDescriptor("FragInputsVFX", builder.ToString());
232232
}
233233

234+
static PragmaCollection ApplyPragmaReplacement(PragmaCollection pragmas, VFXSRPBinder.ShaderGraphBinder shaderGraphSRPInfo)
235+
{
236+
if (shaderGraphSRPInfo.pragmasReplacement != null)
237+
{
238+
var overridenPragmas = new PragmaCollection();
239+
foreach (var pragma in pragmas)
240+
{
241+
var currentPragma = pragma;
242+
var replacement = shaderGraphSRPInfo.pragmasReplacement.FirstOrDefault(o => o.oldDesc.value == pragma.descriptor.value);
243+
if (!string.IsNullOrEmpty(replacement.newDesc.value))
244+
currentPragma = new PragmaCollection.Item(replacement.newDesc, pragma.fieldConditions);
245+
246+
overridenPragmas.Add(currentPragma.descriptor, currentPragma.fieldConditions);
247+
}
248+
return overridenPragmas;
249+
}
250+
return pragmas;
251+
}
252+
234253
internal static SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor subShaderDescriptor, VFXContext context, VFXContextCompiledData data)
235254
{
236255
var srp = VFXLibrary.currentSRPBinder;
@@ -280,6 +299,8 @@ out var vertexPropertiesAssignDescriptor
280299
{
281300
var passDescriptor = passes[i].descriptor;
282301

302+
passDescriptor.pragmas = ApplyPragmaReplacement(passDescriptor.pragmas, shaderGraphSRPInfo);
303+
283304
// Warning: We are replacing the struct provided in the regular pass. It is ok as for now the VFX editor don't support
284305
// tessellation or raytracing
285306
passDescriptor.structs = new StructCollection();

0 commit comments

Comments
 (0)