-
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.
Parse command line options, fix swizzle
- Loading branch information
1 parent
004b918
commit 4066581
Showing
11 changed files
with
117 additions
and
48 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,38 @@ | ||
using System; | ||
|
||
namespace HlslDecompiler | ||
{ | ||
public class CommandLineOptions | ||
{ | ||
public string InputFilename { get; } | ||
public bool DoAstAnalysis { get; } | ||
|
||
public static CommandLineOptions Parse(string[] args) | ||
{ | ||
return new CommandLineOptions(args); | ||
} | ||
|
||
private CommandLineOptions(string[] args) | ||
{ | ||
foreach (string arg in args) | ||
{ | ||
if (arg.StartsWith("--")) | ||
{ | ||
string option = arg.Substring(2); | ||
if (option == "ast") | ||
{ | ||
DoAstAnalysis = true; | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Unknown option: --" + option); | ||
} | ||
} | ||
else | ||
{ | ||
InputFilename = arg; | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
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
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,2 +1,35 @@ | ||
# HlslDecompiler | ||
Decompiles Shader Model 3.0 shaders into HLSL code | ||
|
||
## Usage | ||
`HlslDecompiler [--ast] shader.fxc` | ||
|
||
The program will output the assembly listing in shader.asm, e.g. | ||
``` | ||
ps_3_0 | ||
def c0, 1, 0, 2, 0 | ||
dcl_texcoord v0.xz | ||
mov oC0.x, -v0.z_abs | ||
mad oC0.yzw, v0.xxx, c0.xyy, c0.yxz | ||
``` | ||
and the decompiled HLSL code in shader.fx: | ||
``` | ||
float4 main(float3 texcoord : TEXCOORD) : COLOR | ||
{ | ||
float4 o; | ||
o.x = -abs(texcoord.z); | ||
o.yzw = texcoord.xxx * float3(1, 0, 0) + float3(0, 1, 2); | ||
return o; | ||
} | ||
``` | ||
|
||
With the --ast option, the program will attempt generate more readable HLSL. | ||
It does this by taking the shader bytecode, constructing an abstract syntax tree, simplyfying it and compiling to HLSL: | ||
``` | ||
float4 main(float3 texcoord : TEXCOORD) : COLOR | ||
{ | ||
return float4(-abs(texcoord.z), texcoord.x, 1, 2); | ||
} | ||
``` |