Skip to content

Commit c68e99e

Browse files
committed
Fix various DX12 + Vulkan issue for null geometry input (draw procedural)
1 parent c9ca639 commit c68e99e

File tree

6 files changed

+100
-9
lines changed

6 files changed

+100
-9
lines changed

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,5 +330,12 @@ Pass
330330

331331
$splice(PostGraphIncludes)
332332

333+
// --------------------------------------------------
334+
// Visual Effect Vertex Invocations
335+
336+
#ifdef HAVE_VFX_MODIFICATION
337+
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl"
338+
#endif
339+
333340
ENDHLSL
334341
}

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/VFX/Config.template.hlsl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ $splice(VFXDefineSpace)
22

33
$splice(VFXDefines)
44

5+
#define NULL_GEOMETRY_INPUT defined(HAVE_VFX_PLANAR_PRIMITIVE)
6+
57
// Explicitly defined here for now (similar to how it was done in the previous VFX code-gen)
68
#define HAS_ATTRIBUTES 1
79

@@ -183,20 +185,20 @@ bool GetInterpolatorAndElementData(inout VaryingsMeshType output, inout Attribut
183185
void BuildWorldToElement(VaryingsMeshType input)
184186
{
185187
#ifdef VARYINGS_NEED_WORLD_TO_ELEMENT
186-
UNITY_MATRIX_I_M[0] = input.worldToElement0;
187-
UNITY_MATRIX_I_M[1] = input.worldToElement1;
188-
UNITY_MATRIX_I_M[2] = input.worldToElement2;
189-
UNITY_MATRIX_I_M[3] = float4(0,0,0,1);
188+
worldToElement[0] = input.worldToElement0;
189+
worldToElement[1] = input.worldToElement1;
190+
worldToElement[2] = input.worldToElement2;
191+
worldToElement[3] = float4(0,0,0,1);
190192
#endif
191193
}
192194

193195
void BuildElementToWorld(VaryingsMeshType input)
194196
{
195197
#ifdef VARYINGS_NEED_ELEMENT_TO_WORLD
196-
UNITY_MATRIX_M[0] = input.elementToWorld0;
197-
UNITY_MATRIX_M[1] = input.elementToWorld1;
198-
UNITY_MATRIX_M[2] = input.elementToWorld2;
199-
UNITY_MATRIX_M[3] = float4(0,0,0,1);
198+
elementToWorld[0] = input.elementToWorld0;
199+
elementToWorld[1] = input.elementToWorld1;
200+
elementToWorld[2] = input.elementToWorld2;
201+
elementToWorld[3] = float4(0,0,0,1);
200202
#endif
201203
}
202204

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/VFX/ConfigPlanarPrimitive.template.hlsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#define VFX_NON_UNIFORM_SCALE VFX_LOCAL_SPACE
88

9+
#define HAVE_VFX_PLANAR_PRIMITIVE
10+
911
bool GetMeshAndElementIndex(inout AttributesMesh input, inout AttributesElement element)
1012
{
1113
uint id = input.vertexID;

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using UnityEditor.ShaderGraph;
77
using UnityEditor.ShaderGraph.Internal;
88
using UnityEditor.VFX;
9+
using UnityEngine.Rendering;
910

1011
namespace UnityEditor.Rendering.HighDefinition.ShaderGraph
1112
{
@@ -98,7 +99,7 @@ out var vertexPropertiesAssignDescriptor
9899

99100
passDescriptor.pragmas = new PragmaCollection
100101
{
101-
passDescriptor.pragmas,
102+
ModifyVertexEntry(passDescriptor.pragmas),
102103
Pragma.MultiCompileInstancing
103104
};
104105

@@ -129,6 +130,36 @@ out var vertexPropertiesAssignDescriptor
129130
return subShaderDescriptor;
130131
}
131132

133+
private static readonly GraphicsDeviceType[] s_RequiresModifiedVertexEntry = new GraphicsDeviceType[]
134+
{
135+
GraphicsDeviceType.Direct3D12,
136+
GraphicsDeviceType.Vulkan
137+
};
138+
139+
static PragmaCollection ModifyVertexEntry(PragmaCollection pragmas)
140+
{
141+
// Only modify the entry for the required APIs.
142+
var graphicsAPI = PlayerSettings.GetGraphicsAPIs(EditorUserBuildSettings.activeBuildTarget)[0];
143+
if (s_RequiresModifiedVertexEntry.All(o => o != graphicsAPI))
144+
return pragmas;
145+
146+
// Replace the default vertex shader entry with one defined by VFX.
147+
// NOTE: Assumes they are named "Vert" for all shader passes, which they are.
148+
const string k_CoreBasicVertex = "#pragma vertex Vert";
149+
150+
var pragmaVFX = new PragmaCollection();
151+
152+
foreach (var pragma in pragmas)
153+
{
154+
if (pragma.value != k_CoreBasicVertex)
155+
pragmaVFX.Add(pragma.descriptor);
156+
else
157+
pragmaVFX.Add(Pragma.Vertex("VertVFX"));
158+
}
159+
160+
return pragmaVFX;
161+
}
162+
132163
static StructDescriptor AttributesMeshVFX = new StructDescriptor()
133164
{
134165
name = "AttributesMesh",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Wrapper vertex invocations for VFX. Necesarry to work around various null input geometry issues for vertex input layout on DX12 and Vulkan.
2+
// These entrypoints will only be called in the case of DX12/Vulkan.
3+
#if NULL_GEOMETRY_INPUT
4+
#ifdef MOTION_VEC_VERTEX_COMMON_INCLUDED
5+
PackedVaryingsType VertVFX(uint vertexID : VERTEXID_SEMANTIC, uint instanceID : INSTANCEID_SEMANTIC)
6+
{
7+
AttributesMesh inputMesh;
8+
ZERO_INITIALIZE(AttributesMesh, inputMesh);
9+
10+
AttributesPass inputPass;
11+
ZERO_INITIALIZE(AttributesPass, inputPass);
12+
13+
inputMesh.vertexID = vertexID;
14+
inputMesh.instanceID = instanceID;
15+
16+
return Vert(inputMesh, inputPass);
17+
}
18+
#else
19+
PackedVaryingsType VertVFX(uint vertexID : VERTEXID_SEMANTIC, uint instanceID : INSTANCEID_SEMANTIC)
20+
{
21+
AttributesMesh inputMesh;
22+
ZERO_INITIALIZE(AttributesMesh, inputMesh);
23+
24+
inputMesh.vertexID = vertexID;
25+
inputMesh.instanceID = instanceID;
26+
27+
return Vert(inputMesh);
28+
}
29+
#endif
30+
#else
31+
#ifdef MOTION_VEC_VERTEX_COMMON_INCLUDED
32+
PackedVaryingsType VertVFX(AttributesMesh inputMesh, AttributesPass inputPass)
33+
{
34+
return Vert(inputMesh, inputPass);
35+
}
36+
#else
37+
PackedVaryingsType VertVFX(AttributesMesh inputMesh)
38+
{
39+
return Vert(inputMesh);
40+
}
41+
#endif
42+
#endif

com.unity.render-pipelines.high-definition/Runtime/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.

0 commit comments

Comments
 (0)