Skip to content

Commit

Permalink
Fix sorting of custom type declarations in HLSL
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Dec 18, 2023
1 parent fb415b6 commit fc567fc
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ public static void WriteTopDeclarations(
writer.WriteLine(skipIfPresent: true);
}

// Declared types (these have to be declared early on in the shader so that even if
// forward declarations for types are not supported, like is the case for D2D shaders
// using the FXC compiler, the resulting HLSL code is valid in case any forward
// declaration of methods in the shader has one of these types in its signature).
foreach (HlslUserType userType in typeDeclarations)
{
writer.WriteLine(skipIfPresent: true);
writer.WriteLine(userType.Definition);
}

writer.WriteLine(skipIfPresent: true);

// Forward declarations of shader/static methods
foreach (HlslMethod method in processedMethods)
{
Expand All @@ -91,15 +103,6 @@ public static void WriteTopDeclarations(
}

writer.WriteLine(skipIfPresent: true);

// Declared types
foreach (HlslUserType userType in typeDeclarations)
{
writer.WriteLine(skipIfPresent: true);
writer.WriteLine(userType.Definition);
}

writer.WriteLine(skipIfPresent: true);
}

/// <summary>
Expand Down

0 comments on commit fc567fc

Please sign in to comment.