forked from mellinoe/ShaderGen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More groundwork for HLSL generation.
- Loading branch information
Showing
7 changed files
with
265 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<add key="dotnet-myget dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" /> | ||
<add key="dotnet-myget dotnet-corefxlab" value="https://dotnet.myget.org/F/dotnet-corefxlab/api/v3/index.json" /> | ||
</packageSources> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace ShaderGen | ||
{ | ||
public static class HlslKnownTypes | ||
{ | ||
private static readonly Dictionary<string, string> s_knownTypes = new Dictionary<string, string>() | ||
{ | ||
{ "System.Numerics.Vector2", "float2" }, | ||
{ "System.Numerics.Vector3", "float3" }, | ||
{ "System.Numerics.Vector4", "float4" }, | ||
{ "System.Numerics.Matrix4x4", "float4x4" }, | ||
}; | ||
|
||
public static string GetMappedName(string name) | ||
{ | ||
if (s_knownTypes.TryGetValue(name, out string mapped)) | ||
{ | ||
return mapped; | ||
} | ||
else | ||
{ | ||
return name; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace ShaderGen | ||
{ | ||
public class HlslWriter | ||
{ | ||
private readonly List<StructDefinition> _structs; | ||
private readonly List<UniformDefinition> _uniforms; | ||
|
||
public HlslWriter(List<StructDefinition> structs, List<UniformDefinition> uniforms) | ||
{ | ||
_structs = structs; | ||
_uniforms = uniforms; | ||
} | ||
|
||
public string GetHlslText() | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
foreach (UniformDefinition ud in _uniforms) | ||
{ | ||
sb.AppendLine($"cbuffer {ud.Name}Buffer : register(b{ud.Binding})"); | ||
sb.AppendLine("{"); | ||
sb.AppendLine($" {HlslKnownTypes.GetMappedName(ud.Type.Name.Trim())} {ud.Name.Trim()};"); | ||
sb.AppendLine("}"); | ||
sb.AppendLine(); | ||
} | ||
|
||
foreach (StructDefinition sd in _structs) | ||
{ | ||
sb.AppendLine($"struct {sd.Name}"); | ||
sb.AppendLine("{"); | ||
foreach (FieldDefinition field in sd.Fields) | ||
{ | ||
sb.AppendLine($" {HlslKnownTypes.GetMappedName(field.Type.Name.Trim())} {field.Name.Trim()};"); | ||
} | ||
sb.AppendLine("};"); | ||
sb.AppendLine(); | ||
} | ||
|
||
return sb.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.