-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86e9b74
commit 02bff80
Showing
17 changed files
with
174 additions
and
127 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
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,6 @@ | ||
namespace HlslDecompiler.Hlsl.FlowControl | ||
{ | ||
public class BreakStatement : IStatement | ||
{ | ||
} | ||
} |
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,12 @@ | ||
namespace HlslDecompiler.Hlsl.FlowControl | ||
{ | ||
public class ClipStatement : IStatement | ||
{ | ||
public HlslTreeNode Value { get; } | ||
|
||
public ClipStatement(HlslTreeNode value) | ||
{ | ||
Value = value; | ||
} | ||
} | ||
} |
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,6 @@ | ||
namespace HlslDecompiler.Hlsl.FlowControl | ||
{ | ||
public interface IStatement | ||
{ | ||
} | ||
} |
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,65 @@ | ||
using HlslDecompiler.DirectXShaderModel; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace HlslDecompiler.Hlsl.FlowControl | ||
{ | ||
public class StatementSequence : IStatement | ||
{ | ||
public Dictionary<RegisterComponentKey, HlslTreeNode> Outputs { get; set; } | ||
|
||
public Dictionary<RegisterKey, HlslTreeNode> GroupAssignments() | ||
{ | ||
return GroupComponents(Outputs.Where(IsAssignment)); | ||
} | ||
|
||
public Dictionary<RegisterKey, HlslTreeNode> GroupOutputs() | ||
{ | ||
return GroupComponents(Outputs.Where(IsOutput)); | ||
} | ||
|
||
private static Dictionary<RegisterKey, HlslTreeNode> GroupComponents(IEnumerable<KeyValuePair<RegisterComponentKey, HlslTreeNode>> outputsByComponent) | ||
{ | ||
return outputsByComponent | ||
.OrderBy(o => o.Key.ComponentIndex) | ||
.GroupBy(o => o.Key.RegisterKey) | ||
.ToDictionary( | ||
o => o.Key, | ||
o => (HlslTreeNode)new GroupNode(o.Select(o => o.Value).ToArray())); | ||
} | ||
|
||
private static bool IsAssignment(KeyValuePair<RegisterComponentKey, HlslTreeNode> operation) | ||
{ | ||
if (operation.Key.RegisterKey is D3D9RegisterKey key9) | ||
{ | ||
return key9.Type == RegisterType.Temp; | ||
} | ||
else if (operation.Key.RegisterKey is D3D10RegisterKey key10) | ||
{ | ||
return key10.OperandType == OperandType.Temp; | ||
} | ||
else | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
private static bool IsOutput(KeyValuePair<RegisterComponentKey, HlslTreeNode> operation) | ||
{ | ||
if (operation.Key.RegisterKey is D3D9RegisterKey key9) | ||
{ | ||
RegisterType type = key9.Type; | ||
return type == RegisterType.Output || type == RegisterType.ColorOut || type == RegisterType.DepthOut; | ||
} | ||
else if (operation.Key.RegisterKey is D3D10RegisterKey key10) | ||
{ | ||
return key10.OperandType == OperandType.Output; | ||
} | ||
else | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,62 +1,17 @@ | ||
using HlslDecompiler.DirectXShaderModel; | ||
using HlslDecompiler.Hlsl.TemplateMatch; | ||
using System; | ||
using HlslDecompiler.Hlsl.FlowControl; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace HlslDecompiler.Hlsl | ||
{ | ||
public class HlslAst | ||
{ | ||
public List<StatementSequence> Statements { get; private set; } | ||
public List<IStatement> Statements { get; private set; } | ||
public RegisterState RegisterState { get; private set; } | ||
|
||
public HlslAst(List<StatementSequence> statements, RegisterState registerState) | ||
public HlslAst(List<IStatement> statements, RegisterState registerState) | ||
{ | ||
Statements = statements; | ||
RegisterState = registerState; | ||
} | ||
|
||
public List<Dictionary<RegisterKey, HlslTreeNode>> ReduceTree(NodeGrouper nodeGrouper) | ||
{ | ||
var templateMatcher = new TemplateMatcher(nodeGrouper); | ||
return Statements | ||
.Select(GroupOutputs) | ||
.Select(outputs => outputs.ToDictionary(r => r.Key, r => templateMatcher.Reduce(r.Value))) | ||
.ToList(); | ||
} | ||
|
||
public static Dictionary<RegisterKey, HlslTreeNode> GroupOutputs(StatementSequence statements) | ||
{ | ||
IEnumerable<KeyValuePair<RegisterComponentKey, HlslTreeNode>> outputsByComponent = | ||
statements.Outputs.Where(o => | ||
{ | ||
if (o.Value is ClipOperation) | ||
{ | ||
return true; | ||
} | ||
|
||
if (o.Key.RegisterKey is D3D9RegisterKey key9) | ||
{ | ||
RegisterType type = key9.Type; | ||
return type == RegisterType.Output || type == RegisterType.ColorOut || type == RegisterType.DepthOut; | ||
} | ||
else if (o.Key.RegisterKey is D3D10RegisterKey key10) | ||
{ | ||
return key10.OperandType == OperandType.Output; | ||
} | ||
else | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
}); | ||
var outputsByRegister = outputsByComponent | ||
.OrderBy(o => o.Key.ComponentIndex) | ||
.GroupBy(o => o.Key.RegisterKey) | ||
.ToDictionary( | ||
o => o.Key, | ||
o => (HlslTreeNode)new GroupNode(o.Select(o => o.Value).ToArray())); | ||
return outputsByRegister; | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.