diff --git a/DirectXShaderModel/AsmWriter.cs b/DirectXShaderModel/AsmWriter.cs index 1c1337a..f4e664e 100644 --- a/DirectXShaderModel/AsmWriter.cs +++ b/DirectXShaderModel/AsmWriter.cs @@ -1,6 +1,5 @@ using HlslDecompiler.Util; using System; -using System.Globalization; using System.IO; namespace HlslDecompiler.DirectXShaderModel @@ -16,11 +15,6 @@ public AsmWriter(ShaderModel shader) this.shader = shader; } - void WriteLine() - { - asmWriter.WriteLine(); - } - void WriteLine(string value) { asmWriter.WriteLine(value); @@ -31,48 +25,11 @@ void WriteLine(string format, params object[] args) asmWriter.WriteLine(format, args); } - static string ApplyModifier(SourceModifier modifier, string value) - { - switch (modifier) - { - case SourceModifier.None: - return value; - case SourceModifier.Negate: - return $"-{value}"; - case SourceModifier.Bias: - return $"{value}_bias"; - case SourceModifier.BiasAndNegate: - return $"-{value}_bias"; - case SourceModifier.Sign: - return $"{value}_bx2"; - case SourceModifier.SignAndNegate: - return $"-{value}_bx2"; - case SourceModifier.Complement: - throw new NotImplementedException(); - case SourceModifier.X2: - return $"{value}_x2"; - case SourceModifier.X2AndNegate: - return $"-{value}_x2"; - case SourceModifier.DivideByZ: - return $"{value}_dz"; - case SourceModifier.DivideByW: - return $"{value}_dw"; - case SourceModifier.Abs: - return $"{value}_abs"; - case SourceModifier.AbsAndNegate: - return $"-{value}_abs"; - case SourceModifier.Not: - throw new NotImplementedException(); - default: - throw new NotImplementedException(); - } - } - string GetDestinationName(Instruction instruction) { int destIndex = instruction.GetDestinationParamIndex(); string registerName = instruction.GetParamRegisterName(destIndex); - if (instruction.Opcode == Opcode.Loop) + if (instruction is D3D9Instruction d3D9Instruction && d3D9Instruction.Opcode == Opcode.Loop) { return registerName; } @@ -85,13 +42,16 @@ string GetDestinationName(Instruction instruction) string GetSourceName(Instruction instruction, int srcIndex) { - string sourceRegisterName = instruction.GetParamRegisterName(srcIndex); - if (instruction.Opcode == Opcode.Loop) + string sourceName = instruction.GetParamRegisterName(srcIndex); + if (instruction is D3D9Instruction d3D9Instruction) { - return sourceRegisterName; + if (d3D9Instruction.Opcode != Opcode.Loop) + { + sourceName += instruction.GetSourceSwizzleName(srcIndex); + sourceName = ApplyModifier(d3D9Instruction.GetSourceModifier(srcIndex), sourceName); + } } - sourceRegisterName += instruction.GetSourceSwizzleName(srcIndex); - return ApplyModifier(instruction.GetSourceModifier(srcIndex), sourceRegisterName); + return sourceName; } public void Write(string asmFilename) @@ -104,14 +64,21 @@ public void Write(string asmFilename) foreach (Instruction instruction in shader.Instructions) { - WriteInstruction(instruction); + if (instruction is D3D10Instruction d3D10Instruction) + { + WriteD3D10Instruction(d3D10Instruction); + } + else + { + WriteInstruction(instruction as D3D9Instruction); + } } asmWriter.Dispose(); asmFile.Dispose(); } - private void WriteInstruction(Instruction instruction) + private void WriteInstruction(D3D9Instruction instruction) { switch (instruction.Opcode) { @@ -302,7 +269,30 @@ private void WriteInstruction(Instruction instruction) } } - private static string GetModifier(Instruction instruction) + private void WriteD3D10Instruction(D3D10Instruction instruction) + { + switch (instruction.Opcode) + { + case D3D10Opcode.Add: + break; + case D3D10Opcode.DclInputPS: + WriteLine("dcl_input_ps linear"); + break; + case D3D10Opcode.DclTemps: + WriteLine("dcl_temps {0}", instruction.GetParamInt(0)); + break; + case D3D10Opcode.Mov: + WriteLine("mov {0}, {1}", GetDestinationName(instruction), "v0.w"); + break; + default: + WriteLine(instruction.Opcode.ToString()); + Console.WriteLine(instruction.Opcode); + //throw new NotImplementedException(); + break; + } + } + + private static string GetModifier(D3D9Instruction instruction) { ResultModifier resultModifier = instruction.GetDestinationResultModifier(); switch (resultModifier) @@ -319,5 +309,42 @@ private static string GetModifier(Instruction instruction) throw new NotSupportedException("Not supported result modifier " + resultModifier); } } + + static string ApplyModifier(SourceModifier modifier, string value) + { + switch (modifier) + { + case SourceModifier.None: + return value; + case SourceModifier.Negate: + return $"-{value}"; + case SourceModifier.Bias: + return $"{value}_bias"; + case SourceModifier.BiasAndNegate: + return $"-{value}_bias"; + case SourceModifier.Sign: + return $"{value}_bx2"; + case SourceModifier.SignAndNegate: + return $"-{value}_bx2"; + case SourceModifier.Complement: + throw new NotImplementedException(); + case SourceModifier.X2: + return $"{value}_x2"; + case SourceModifier.X2AndNegate: + return $"-{value}_x2"; + case SourceModifier.DivideByZ: + return $"{value}_dz"; + case SourceModifier.DivideByW: + return $"{value}_dw"; + case SourceModifier.Abs: + return $"{value}_abs"; + case SourceModifier.AbsAndNegate: + return $"-{value}_abs"; + case SourceModifier.Not: + throw new NotImplementedException(); + default: + throw new NotImplementedException(); + } + } } } diff --git a/DirectXShaderModel/D3D10Instruction.cs b/DirectXShaderModel/D3D10Instruction.cs new file mode 100644 index 0000000..37b2107 --- /dev/null +++ b/DirectXShaderModel/D3D10Instruction.cs @@ -0,0 +1,137 @@ +using System; + +namespace HlslDecompiler.DirectXShaderModel +{ + public class D3D10Instruction : Instruction + { + public D3D10Opcode Opcode { get; } + public D3D10ParamCollection ParamTokens { get; } + + public D3D10Instruction(D3D10Opcode opcode, uint[] paramTokens) + { + Opcode = opcode; + ParamTokens = new D3D10ParamCollection(paramTokens); + } + + public override bool HasDestination + { + get + { + switch (Opcode) + { + case D3D10Opcode.Add: + case D3D10Opcode.DclInputPS: + case D3D10Opcode.DclOutput: + case D3D10Opcode.DclTemps: + case D3D10Opcode.Dp2: + case D3D10Opcode.GE: + case D3D10Opcode.Mad: + case D3D10Opcode.Mov: + case D3D10Opcode.MovC: + case D3D10Opcode.Mul: + return true; + default: + return false; + } + } + } + + public override bool IsTextureOperation + { + get + { + switch (Opcode) + { + default: + return false; + } + } + } + + public override int GetDestinationParamIndex() + { + throw new NotImplementedException(); + } + + public override int GetDestinationWriteMask() + { + throw new NotImplementedException(); + } + + public override int GetDestinationMaskedLength() + { + return 4; + } + + public override int GetSourceSwizzle(int srcIndex) + { + throw new NotImplementedException(); + } + + public override string GetSourceSwizzleName(int srcIndex) + { + throw new NotImplementedException(); + } + + public override string GetDeclSemantic() + { + switch (GetParamOperandType(0)) + { + case OperandType.Output: + return "sem"; + //return GetDeclUsage().ToString().ToUpper(); + default: + throw new NotImplementedException(); + } + } + + public override float GetParamSingle(int index) + { + throw new NotImplementedException(); + } + + public override float GetParamInt(int index) + { + throw new NotImplementedException(); + } + + private Span GetParamSpan(int index) + { + int paramCount = 0; + for (int i = 0; i < ParamTokens.Count; i++) + { + uint param = ParamTokens.Tokens[i]; + int numComponents = (int)(param & 3); + numComponents.ToString(); + } + return new Span(ParamTokens.Tokens, 0, 1); + } + + public override RegisterKey GetParamRegisterKey(int index) + { + return new RegisterKey( + GetParamOperandType(index)); + } + + public OperandType GetParamOperandType(int index) + { + uint p = ParamTokens.Tokens[index]; + return (OperandType)((p >> 12) & 0xFF); + } + + public override string GetParamRegisterName(int index) + { + throw new NotImplementedException(); + } + + public override int GetParamRegisterNumber(int index) + { + throw new NotImplementedException(); + } + + public override string ToString() + { + return Opcode.ToString(); + } + } +} diff --git a/DirectXShaderModel/D3D10Opcode.cs b/DirectXShaderModel/D3D10Opcode.cs new file mode 100644 index 0000000..2bfaa21 --- /dev/null +++ b/DirectXShaderModel/D3D10Opcode.cs @@ -0,0 +1,114 @@ +namespace HlslDecompiler.DirectXShaderModel +{ + // D3D10_SB_OPCODE_TYPE + public enum D3D10Opcode + { + Add, + And, + Break, + BreakC, + Call, + CallC, + Case, + Continue, + ContinueC, + Cut, + Default, + DerivRtx, + DerivRty, + Discard, + Div, + Dp2, + Dp3, + Dp4, + Else, + Emit, + EmitThenCut, + EndIf, + EndLoop, + EndSwitch, + Eq, + Exp, + Frc, + Ftoi, + Ftou, + GE, + IAdd, + If, + Ieq, + Ige, + Ilt, + IMad, + IMax, + IMin, + IMul, + Ine, + INeg, + ISHL, + ISHR, + ITOF, + Label, + LD, + LDMS, + Log, + Loop, + LT, + Mad, + Min, + Max, + CustomData, + Mov, + MovC, + Mul, + Ne, + Nop, + Not, + Or, + ResInfo, + Ret, + RetC, + RoundNe, + RoundNi, + RoundPi, + RoundZ, + Rsq, + Sample, + SampleC, + SampleCLZ, + SampleL, + SampleD, + SampleB, + Sqrt, + Swtich, + SinCos, + Udiv, + ULT, + UGE, + UMul, + Umad, + UMax, + UMin, + UShr, + UTof, + Xor, + DclResource, + DclConstantBuffer, + DclSampler, + DclIndexRange, + DxlGSOutputPrimitiveTopology, + DclGSMaxOutputVertexCount, + DclInput, + DclInputSgv, + DclInputSiv, + DclInputPS, + DclInputPSSgv, + DclInputPSSiv, + DclOutput, + DclOutputSgv, + DclOutputSiv, + DclTemps, + DclIndexableTemp, + DclGlobalFlags, + Reserved0 + } +} diff --git a/DirectXShaderModel/D3D10ParamCollection.cs b/DirectXShaderModel/D3D10ParamCollection.cs new file mode 100644 index 0000000..1ecf48f --- /dev/null +++ b/DirectXShaderModel/D3D10ParamCollection.cs @@ -0,0 +1,13 @@ +namespace HlslDecompiler.DirectXShaderModel +{ + public class D3D10ParamCollection + { + public uint[] Tokens { get; } + public virtual int Count => Tokens.Length; + + public D3D10ParamCollection(uint[] paramTokens) + { + Tokens = paramTokens; + } + } +} diff --git a/DirectXShaderModel/D3D9Instruction.cs b/DirectXShaderModel/D3D9Instruction.cs new file mode 100644 index 0000000..ab7cfd3 --- /dev/null +++ b/DirectXShaderModel/D3D9Instruction.cs @@ -0,0 +1,439 @@ +using System; + +namespace HlslDecompiler.DirectXShaderModel +{ + public class D3D9Instruction : Instruction + { + public Opcode Opcode { get; } + public D3D9ParamCollection Params { get; } + + public D3D9Instruction(Opcode opcode, uint[] paramTokens) + { + Opcode = opcode; + switch (opcode) + { + case Opcode.Comment: + case Opcode.Def: + case Opcode.DefB: + case Opcode.DefI: + Params = new D3D9ParamCollection(paramTokens); + break; + default: + Params = new ParamRelativeCollection(paramTokens); + break; + } + } + + public override bool HasDestination + { + get + { + switch (Opcode) + { + case Opcode.Abs: + case Opcode.Add: + case Opcode.Bem: + case Opcode.Cmp: + case Opcode.Cnd: + case Opcode.Crs: + case Opcode.Dcl: + case Opcode.Def: + case Opcode.DefB: + case Opcode.DefI: + case Opcode.DP2Add: + case Opcode.Dp3: + case Opcode.Dp4: + case Opcode.Dst: + case Opcode.DSX: + case Opcode.DSY: + case Opcode.Exp: + case Opcode.ExpP: + case Opcode.Frc: + case Opcode.Lit: + case Opcode.Log: + case Opcode.LogP: + case Opcode.Lrp: + case Opcode.M3x2: + case Opcode.M3x3: + case Opcode.M3x4: + case Opcode.M4x3: + case Opcode.M4x4: + case Opcode.Mad: + case Opcode.Max: + case Opcode.Min: + case Opcode.Mov: + case Opcode.MovA: + case Opcode.Mul: + case Opcode.Nrm: + case Opcode.Pow: + case Opcode.Rcp: + case Opcode.Rsq: + case Opcode.SetP: + case Opcode.Sge: + case Opcode.Sgn: + case Opcode.SinCos: + case Opcode.Slt: + case Opcode.Sub: + case Opcode.Tex: + case Opcode.TexBem: + case Opcode.TexBeml: + case Opcode.TexCoord: + case Opcode.TexDepth: + case Opcode.TexDP3: + case Opcode.TexDP3Tex: + case Opcode.TexKill: + case Opcode.TexLDD: + case Opcode.TexLDL: + case Opcode.TexM3x2Depth: + case Opcode.TeXM3x2Pad: + case Opcode.TexM3x2Tex: + case Opcode.TexM3x3: + case Opcode.TexM3x3Diff: + case Opcode.TeXM3x3Pad: + case Opcode.TexM3x3Spec: + case Opcode.TexM3x3Tex: + case Opcode.TexM3x3VSpec: + case Opcode.TexReg2AR: + case Opcode.TexReg2GB: + case Opcode.TexReg2RGB: + return true; + default: + return false; + } + } + } + + public override bool IsTextureOperation + { + get + { + switch (Opcode) + { + case Opcode.Tex: + case Opcode.TexBem: + case Opcode.TexBeml: + case Opcode.TexCoord: + case Opcode.TexDepth: + case Opcode.TexDP3: + case Opcode.TexDP3Tex: + case Opcode.TexKill: + case Opcode.TexLDD: + case Opcode.TexLDL: + case Opcode.TexM3x2Depth: + case Opcode.TeXM3x2Pad: + case Opcode.TexM3x2Tex: + case Opcode.TexM3x3: + case Opcode.TexM3x3Diff: + case Opcode.TeXM3x3Pad: + case Opcode.TexM3x3Spec: + case Opcode.TexM3x3Tex: + case Opcode.TexM3x3VSpec: + case Opcode.TexReg2AR: + case Opcode.TexReg2GB: + case Opcode.TexReg2RGB: + return true; + default: + return false; + } + } + } + + public override string GetDeclSemantic() + { + switch (GetParamRegisterType(1)) + { + case RegisterType.Input: + case RegisterType.Output: + string name; + switch (GetDeclUsage()) + { + case DeclUsage.Binormal: + case DeclUsage.BlendIndices: + case DeclUsage.BlendWeight: + case DeclUsage.Color: + case DeclUsage.Depth: + case DeclUsage.Fog: + case DeclUsage.Normal: + case DeclUsage.Position: + case DeclUsage.PositionT: + case DeclUsage.PSize: + case DeclUsage.Sample: + case DeclUsage.Tangent: + case DeclUsage.TessFactor: + case DeclUsage.TexCoord: + name = GetDeclUsage().ToString().ToUpper(); + break; + default: + throw new NotImplementedException(); + } + if (GetDeclIndex() != 0) + { + name += GetDeclIndex().ToString(); + } + return name; + case RegisterType.Sampler: + switch (GetDeclSamplerTextureType()) + { + case SamplerTextureType.TwoD: + return "2d"; + case SamplerTextureType.Cube: + return "cube"; + case SamplerTextureType.Volume: + return "volume"; + default: + throw new NotImplementedException(); + } + case RegisterType.MiscType: + if (GetParamRegisterNumber(1) == 0) + { + return "vFace"; + } + if (GetParamRegisterNumber(1) == 1) + { + return "vPos"; + } + throw new NotImplementedException(); + default: + throw new NotImplementedException(); + } + } + + // For output, input and texture declarations + private DeclUsage GetDeclUsage() + { + return (DeclUsage)(Params[0] & 0x1F); + } + + // For output, input and texture declarations + private int GetDeclIndex() + { + return (int)(Params[0] >> 16) & 0x0F; + } + + // For sampler declarations + private SamplerTextureType GetDeclSamplerTextureType() + { + return (SamplerTextureType)((Params[0] >> 27) & 0xF); + } + + public override int GetDestinationParamIndex() + { + if (Opcode == Opcode.Dcl) return 1; + + return 0; + } + + public override int GetDestinationWriteMask() + { + int destIndex = GetDestinationParamIndex(); + return (int)((Params[destIndex] >> 16) & 0xF); + } + + public SourceModifier GetSourceModifier(int srcIndex) + { + return (SourceModifier)((Params[srcIndex] >> 24) & 0xF); + } + + public override int GetSourceSwizzle(int srcIndex) + { + return (int)((Params[srcIndex] >> 16) & 0xFF); + } + + public override string GetSourceSwizzleName(int srcIndex) + { + int destinationMask; + switch (Opcode) + { + case Opcode.Dp3: + destinationMask = 7; + break; + case Opcode.Dp4: + case Opcode.IfC: + destinationMask = 15; + break; + default: + destinationMask = GetDestinationWriteMask(); + break; + } + + byte[] swizzle = GetSourceSwizzleComponents(srcIndex); + + string swizzleName = ""; + for (int i = 0; i < 4; i++) + { + if ((destinationMask & (1 << i)) != 0) + { + switch (swizzle[i]) + { + case 0: + swizzleName += "x"; + break; + case 1: + swizzleName += "y"; + break; + case 2: + swizzleName += "z"; + break; + case 3: + swizzleName += "w"; + break; + } + } + } + switch (swizzleName) + { + case "xyzw": + return ""; + case "xxxx": + return ".x"; + case "yyyy": + return ".y"; + case "zzzz": + return ".z"; + case "wwww": + return ".w"; + default: + return "." + swizzleName; + } + } + + public RegisterType GetParamRegisterType(int index) + { + uint p = Params[index]; + return (RegisterType)(((p >> 28) & 0x7) | ((p >> 8) & 0x18)); + } + + public override float GetParamSingle(int index) + { + return BitConverter.ToSingle(GetParamBytes(index), 0); + } + + public override float GetParamInt(int index) + { + return BitConverter.ToInt32(GetParamBytes(index), 0); + } + + private byte[] GetParamBytes(int index) + { + return BitConverter.GetBytes(Params[index]); + } + + public override RegisterKey GetParamRegisterKey(int index) + { + return new RegisterKey( + GetParamRegisterType(index), + GetParamRegisterNumber(index)); + } + + public RegisterType GetRelativeParamRegisterType(int index) + { + uint p = Params.GetRelativeToken(index); + return (RegisterType)(((p >> 28) & 0x7) | ((p >> 8) & 0x18)); + } + + public override string GetParamRegisterName(int index) + { + var registerType = GetParamRegisterType(index); + int registerNumber = GetParamRegisterNumber(index); + + string registerTypeName; + switch (registerType) + { + case RegisterType.Addr: + registerTypeName = "a"; + break; + case RegisterType.Const: + registerTypeName = "c"; + break; + case RegisterType.Const2: + registerTypeName = "c"; + registerNumber += 2048; + break; + case RegisterType.Const3: + registerTypeName = "c"; + registerNumber += 4096; + break; + case RegisterType.Const4: + registerTypeName = "c"; + registerNumber += 6144; + break; + case RegisterType.ConstBool: + registerTypeName = "b"; + break; + case RegisterType.ConstInt: + registerTypeName = "i"; + break; + case RegisterType.Input: + registerTypeName = "v"; + break; + case RegisterType.Output: + registerTypeName = "o"; + break; + case RegisterType.RastOut: + registerTypeName = "rast"; + break; + case RegisterType.Temp: + registerTypeName = "r"; + break; + case RegisterType.Sampler: + registerTypeName = "s"; + break; + case RegisterType.ColorOut: + registerTypeName = "oC"; + break; + case RegisterType.DepthOut: + registerTypeName = "oDepth"; + break; + case RegisterType.MiscType: + if (registerNumber == 0) + { + return "vFace"; + } + else if (registerNumber == 1) + { + return "vPos"; + } + else + { + throw new NotImplementedException(); + } + case RegisterType.Loop: + return "aL"; + default: + throw new NotImplementedException(); + } + + string relativeAddressing = string.Empty; + if (Params.HasRelativeAddressing(index)) + { + RegisterType relativeType = GetRelativeParamRegisterType(index); + switch (relativeType) + { + case RegisterType.Loop: + relativeAddressing = "[aL]"; + break; + default: + throw new NotSupportedException(relativeType.ToString()); + } + } + + return $"{registerTypeName}{registerNumber}{relativeAddressing}"; + } + + public override int GetParamRegisterNumber(int index) + { + return (int)(Params[index] & 0x7FF); + } + + public ResultModifier GetDestinationResultModifier() + { + int destIndex = GetDestinationParamIndex(); + return (ResultModifier)((Params[destIndex] >> 20) & 0xF); + } + + public override string ToString() + { + return Opcode.ToString(); + } + } +} diff --git a/DirectXShaderModel/ParamCollection.cs b/DirectXShaderModel/D3D9ParamCollection.cs similarity index 80% rename from DirectXShaderModel/ParamCollection.cs rename to DirectXShaderModel/D3D9ParamCollection.cs index 9f283a1..b3b180f 100644 --- a/DirectXShaderModel/ParamCollection.cs +++ b/DirectXShaderModel/D3D9ParamCollection.cs @@ -2,12 +2,12 @@ namespace HlslDecompiler.DirectXShaderModel { - public class ParamCollection + public class D3D9ParamCollection { public uint[] Tokens { get; } public virtual int Count => Tokens.Length; - public ParamCollection(uint[] paramTokens) + public D3D9ParamCollection(uint[] paramTokens) { Tokens = paramTokens; } diff --git a/DirectXShaderModel/DeclUsage.cs b/DirectXShaderModel/DeclUsage.cs index c8397fa..c0b9407 100644 --- a/DirectXShaderModel/DeclUsage.cs +++ b/DirectXShaderModel/DeclUsage.cs @@ -1,6 +1,6 @@ namespace HlslDecompiler.DirectXShaderModel { - // D3DDECLUSAGE + // https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3ddeclusage public enum DeclUsage { Position, diff --git a/DirectXShaderModel/Declaration.cs b/DirectXShaderModel/Declaration.cs index 9f38726..dac4ce6 100644 --- a/DirectXShaderModel/Declaration.cs +++ b/DirectXShaderModel/Declaration.cs @@ -44,7 +44,14 @@ public class RegisterDeclaration public RegisterDeclaration(Instruction declInstruction) { - RegisterKey = declInstruction.GetParamRegisterKey(1); + if (declInstruction is D3D10Instruction d3D10Instruction) + { + RegisterKey = new RegisterKey(d3D10Instruction.GetParamOperandType(0)); + } + else + { + RegisterKey = declInstruction.GetParamRegisterKey(1); + } Semantic = declInstruction.GetDeclSemantic(); _maskedLength = declInstruction.GetDestinationMaskedLength(); } diff --git a/DirectXShaderModel/Instruction.cs b/DirectXShaderModel/Instruction.cs index d21593f..00d0dc9 100644 --- a/DirectXShaderModel/Instruction.cs +++ b/DirectXShaderModel/Instruction.cs @@ -13,291 +13,28 @@ enum IfComparison LE } - public class Instruction + public abstract class Instruction { - public Opcode Opcode { get; } - public ParamCollection Params { get; } - public int Modifier { get; set; } public bool Predicated { get; set; } - public bool HasDestination - { - get - { - switch (Opcode) - { - case Opcode.Abs: - case Opcode.Add: - case Opcode.Bem: - case Opcode.Cmp: - case Opcode.Cnd: - case Opcode.Crs: - case Opcode.Dcl: - case Opcode.Def: - case Opcode.DefB: - case Opcode.DefI: - case Opcode.DP2Add: - case Opcode.Dp3: - case Opcode.Dp4: - case Opcode.Dst: - case Opcode.DSX: - case Opcode.DSY: - case Opcode.Exp: - case Opcode.ExpP: - case Opcode.Frc: - case Opcode.Lit: - case Opcode.Log: - case Opcode.LogP: - case Opcode.Lrp: - case Opcode.M3x2: - case Opcode.M3x3: - case Opcode.M3x4: - case Opcode.M4x3: - case Opcode.M4x4: - case Opcode.Mad: - case Opcode.Max: - case Opcode.Min: - case Opcode.Mov: - case Opcode.MovA: - case Opcode.Mul: - case Opcode.Nrm: - case Opcode.Pow: - case Opcode.Rcp: - case Opcode.Rsq: - case Opcode.SetP: - case Opcode.Sge: - case Opcode.Sgn: - case Opcode.SinCos: - case Opcode.Slt: - case Opcode.Sub: - case Opcode.Tex: - case Opcode.TexBem: - case Opcode.TexBeml: - case Opcode.TexCoord: - case Opcode.TexDepth: - case Opcode.TexDP3: - case Opcode.TexDP3Tex: - case Opcode.TexKill: - case Opcode.TexLDD: - case Opcode.TexLDL: - case Opcode.TexM3x2Depth: - case Opcode.TeXM3x2Pad: - case Opcode.TexM3x2Tex: - case Opcode.TexM3x3: - case Opcode.TexM3x3Diff: - case Opcode.TeXM3x3Pad: - case Opcode.TexM3x3Spec: - case Opcode.TexM3x3Tex: - case Opcode.TexM3x3VSpec: - case Opcode.TexReg2AR: - case Opcode.TexReg2GB: - case Opcode.TexReg2RGB: - return true; - default: - return false; - } - } - } + public abstract bool HasDestination { get; } - public bool IsTextureOperation - { - get - { - switch (Opcode) - { - case Opcode.Tex: - case Opcode.TexBem: - case Opcode.TexBeml: - case Opcode.TexCoord: - case Opcode.TexDepth: - case Opcode.TexDP3: - case Opcode.TexDP3Tex: - case Opcode.TexKill: - case Opcode.TexLDD: - case Opcode.TexLDL: - case Opcode.TexM3x2Depth: - case Opcode.TeXM3x2Pad: - case Opcode.TexM3x2Tex: - case Opcode.TexM3x3: - case Opcode.TexM3x3Diff: - case Opcode.TeXM3x3Pad: - case Opcode.TexM3x3Spec: - case Opcode.TexM3x3Tex: - case Opcode.TexM3x3VSpec: - case Opcode.TexReg2AR: - case Opcode.TexReg2GB: - case Opcode.TexReg2RGB: - return true; - default: - return false; - } - } - } - - public Instruction(Opcode opcode, uint[] paramTokens) - { - Opcode = opcode; - switch (opcode) - { - case Opcode.Comment: - case Opcode.Def: - case Opcode.DefB: - case Opcode.DefI: - Params = new ParamCollection(paramTokens); - break; - default: - Params = new ParamRelativeCollection(paramTokens); - break; - } - } + public abstract bool IsTextureOperation { get; } - byte[] GetParamBytes(int index) - { - return BitConverter.GetBytes(Params[index]); - } - - public float GetParamSingle(int index) - { - return BitConverter.ToSingle(GetParamBytes(index), 0); - } - - public float GetParamInt(int index) - { - return BitConverter.ToInt32(GetParamBytes(index), 0); - } - - public RegisterKey GetParamRegisterKey(int index) - { - return new RegisterKey( - GetParamRegisterType(index), - GetParamRegisterNumber(index)); - } - - public RegisterType GetParamRegisterType(int index) - { - uint p = Params[index]; - return (RegisterType)(((p >> 28) & 0x7) | ((p >> 8) & 0x18)); - } - - public RegisterType GetRelativeParamRegisterType(int index) - { - uint p = Params.GetRelativeToken(index); - return (RegisterType)(((p >> 28) & 0x7) | ((p >> 8) & 0x18)); - } - - public int GetParamRegisterNumber(int index) - { - return (int)(Params[index] & 0x7FF); - } - - public string GetParamRegisterName(int index) - { - var registerType = GetParamRegisterType(index); - int registerNumber = GetParamRegisterNumber(index); - - string registerTypeName; - switch (registerType) - { - case RegisterType.Addr: - registerTypeName = "a"; - break; - case RegisterType.Const: - registerTypeName = "c"; - break; - case RegisterType.Const2: - registerTypeName = "c"; - registerNumber += 2048; - break; - case RegisterType.Const3: - registerTypeName = "c"; - registerNumber += 4096; - break; - case RegisterType.Const4: - registerTypeName = "c"; - registerNumber += 6144; - break; - case RegisterType.ConstBool: - registerTypeName = "b"; - break; - case RegisterType.ConstInt: - registerTypeName = "i"; - break; - case RegisterType.Input: - registerTypeName = "v"; - break; - case RegisterType.Output: - registerTypeName = "o"; - break; - case RegisterType.RastOut: - registerTypeName = "rast"; - break; - case RegisterType.Temp: - registerTypeName = "r"; - break; - case RegisterType.Sampler: - registerTypeName = "s"; - break; - case RegisterType.ColorOut: - registerTypeName = "oC"; - break; - case RegisterType.DepthOut: - registerTypeName = "oDepth"; - break; - case RegisterType.MiscType: - if (registerNumber == 0) - { - return "vFace"; - } - else if (registerNumber == 1) - { - return "vPos"; - } - else - { - throw new NotImplementedException(); - } - case RegisterType.Loop: - return "aL"; - default: - throw new NotImplementedException(); - } - - string relativeAddressing = string.Empty; - if (Params.HasRelativeAddressing(index)) - { - RegisterType relativeType = GetRelativeParamRegisterType(index); - switch (relativeType) - { - case RegisterType.Loop: - relativeAddressing = "[aL]"; - break; - default: - throw new NotSupportedException(relativeType.ToString()); - } - } + public abstract float GetParamSingle(int index); + + public abstract float GetParamInt(int index); - return $"{registerTypeName}{registerNumber}{relativeAddressing}"; - } + public abstract RegisterKey GetParamRegisterKey(int index); - public int GetDestinationParamIndex() - { - if (Opcode == Opcode.Dcl) return 1; + public abstract int GetParamRegisterNumber(int index); - return 0; - } + public abstract string GetParamRegisterName(int index); - public ResultModifier GetDestinationResultModifier() - { - int destIndex = GetDestinationParamIndex(); - return (ResultModifier)((Params[destIndex] >> 20) & 0xF); - } + public abstract int GetDestinationParamIndex(); - public int GetDestinationWriteMask() - { - int destIndex = GetDestinationParamIndex(); - return (int)((Params[destIndex] >> 16) & 0xF); - } + public abstract int GetDestinationWriteMask(); public string GetDestinationWriteMaskName(int destinationLength, bool hlsl) { @@ -326,7 +63,7 @@ public string GetDestinationWriteMaskName(int destinationLength, bool hlsl) // Length of ".xy" = 2 // Length of ".yw" = 4 (xyzw) - public int GetDestinationMaskedLength() + public virtual int GetDestinationMaskedLength() { int writeMask = GetDestinationWriteMask(); for (int i = 3; i >= 0; i--) @@ -354,10 +91,7 @@ public int GetDestinationMaskLength() return length; } - public int GetSourceSwizzle(int srcIndex) - { - return (int)((Params[srcIndex] >> 16) & 0xFF); - } + public abstract int GetSourceSwizzle(int srcIndex); public byte[] GetSourceSwizzleComponents(int srcIndex) { @@ -370,150 +104,8 @@ public byte[] GetSourceSwizzleComponents(int srcIndex) return swizzleArray; } - public string GetSourceSwizzleName(int srcIndex) - { - int destinationMask; - switch (Opcode) - { - case Opcode.Dp3: - destinationMask = 7; - break; - case Opcode.Dp4: - case Opcode.IfC: - destinationMask = 15; - break; - default: - destinationMask = GetDestinationWriteMask(); - break; - } - - byte[] swizzle = GetSourceSwizzleComponents(srcIndex); + public abstract string GetSourceSwizzleName(int srcIndex); - string swizzleName = ""; - for (int i = 0; i < 4; i++) - { - if ((destinationMask & (1 << i)) != 0) - { - switch (swizzle[i]) - { - case 0: - swizzleName += "x"; - break; - case 1: - swizzleName += "y"; - break; - case 2: - swizzleName += "z"; - break; - case 3: - swizzleName += "w"; - break; - } - } - } - switch (swizzleName) - { - case "xyzw": - return ""; - case "xxxx": - return ".x"; - case "yyyy": - return ".y"; - case "zzzz": - return ".z"; - case "wwww": - return ".w"; - default: - return "." + swizzleName; - } - } - - public SourceModifier GetSourceModifier(int srcIndex) - { - return (SourceModifier)((Params[srcIndex] >> 24) & 0xF); - } - - // For output, input and texture declarations - public DeclUsage GetDeclUsage() - { - return (DeclUsage)(Params[0] & 0x1F); - } - - // For output, input and texture declarations - public int GetDeclIndex() - { - return (int)(Params[0] >> 16) & 0x0F; - } - - // For sampler declarations - public SamplerTextureType GetDeclSamplerTextureType() - { - return (SamplerTextureType)((Params[0] >> 27) & 0xF); - } - - public string GetDeclSemantic() - { - switch (GetParamRegisterType(1)) - { - case RegisterType.Input: - case RegisterType.Output: - string name; - switch (GetDeclUsage()) - { - case DeclUsage.Binormal: - case DeclUsage.BlendIndices: - case DeclUsage.BlendWeight: - case DeclUsage.Color: - case DeclUsage.Depth: - case DeclUsage.Fog: - case DeclUsage.Normal: - case DeclUsage.Position: - case DeclUsage.PositionT: - case DeclUsage.PSize: - case DeclUsage.Sample: - case DeclUsage.Tangent: - case DeclUsage.TessFactor: - case DeclUsage.TexCoord: - name = GetDeclUsage().ToString().ToUpper(); - break; - default: - throw new NotImplementedException(); - } - if (GetDeclIndex() != 0) - { - name += GetDeclIndex().ToString(); - } - return name; - case RegisterType.Sampler: - switch (GetDeclSamplerTextureType()) - { - case SamplerTextureType.TwoD: - return "2d"; - case SamplerTextureType.Cube: - return "cube"; - case SamplerTextureType.Volume: - return "volume"; - default: - throw new NotImplementedException(); - } - case RegisterType.MiscType: - if (GetParamRegisterNumber(1) == 0) - { - return "vFace"; - } - if (GetParamRegisterNumber(1) == 1) - { - return "vPos"; - } - throw new NotImplementedException(); - default: - throw new NotImplementedException(); - } - } - - public override string ToString() - { - return Opcode.ToString(); - } + public abstract string GetDeclSemantic(); } } diff --git a/DirectXShaderModel/InstructionVerifier.cs b/DirectXShaderModel/InstructionVerifier.cs index 0383b0d..ca636cf 100644 --- a/DirectXShaderModel/InstructionVerifier.cs +++ b/DirectXShaderModel/InstructionVerifier.cs @@ -3,7 +3,7 @@ public class InstructionVerifier { [System.Diagnostics.Conditional("DEBUG")] - public static void Verify(Instruction instruction) + public static void Verify(D3D9Instruction instruction) { //Assert(currentInstruction.Modifier == 0); Assert(!instruction.Predicated); @@ -66,5 +66,11 @@ private static void Assert(bool condition) { System.Diagnostics.Debug.Assert(condition); } + + [System.Diagnostics.Conditional("DEBUG")] + public static void Verify(D3D10Instruction instruction) + { + // TODO + } } } diff --git a/DirectXShaderModel/OperandType.cs b/DirectXShaderModel/OperandType.cs new file mode 100644 index 0000000..31cb3c5 --- /dev/null +++ b/DirectXShaderModel/OperandType.cs @@ -0,0 +1,9 @@ +namespace HlslDecompiler.DirectXShaderModel +{ + public enum OperandType + { + Temp, + Input, + Output + } +} diff --git a/DirectXShaderModel/ParamRelativeCollection.cs b/DirectXShaderModel/ParamRelativeCollection.cs index 9264d8d..e9a1b05 100644 --- a/DirectXShaderModel/ParamRelativeCollection.cs +++ b/DirectXShaderModel/ParamRelativeCollection.cs @@ -1,6 +1,6 @@ namespace HlslDecompiler.DirectXShaderModel { - public class ParamRelativeCollection : ParamCollection + public class ParamRelativeCollection : D3D9ParamCollection { public override int Count { diff --git a/DirectXShaderModel/Reader/DxbcReader.cs b/DirectXShaderModel/Reader/DxbcReader.cs new file mode 100644 index 0000000..f55f76d --- /dev/null +++ b/DirectXShaderModel/Reader/DxbcReader.cs @@ -0,0 +1,82 @@ +using HlslDecompiler.Util; +using System.IO; +using System.Text; + +namespace HlslDecompiler.DirectXShaderModel +{ + public class DxbcReader : BinaryReader + { + public DxbcReader(Stream input, bool leaveOpen = false) + : base(input, new UTF8Encoding(false, true), leaveOpen) + { + } + + virtual public ShaderModel ReadShader() + { + int dxbc = ReadInt32(); + System.Diagnostics.Debug.Assert(dxbc == FourCC.Make("DXBC")); + + ReadBytes(16); // checksum + ReadInt32(); // 1 + + ReadInt32(); // totalSize + + int chunkCount = ReadInt32(); + int[] chunkOffsets = new int[chunkCount]; + for (int i = 0; i < chunkCount; i++) + { + chunkOffsets[i] = ReadInt32(); + } + + ShaderModel shader = null; + foreach (int chunkOffset in chunkOffsets) + { + BaseStream.Position = chunkOffset; + string chunkType = FourCC.Decode(ReadInt32()); + if (chunkType == "RDEF") + { + ReadBytes(20); + byte majorVersion = ReadByte(); + byte minorVersion = ReadByte(); + ShaderType shaderType = (ShaderType)ReadUInt16(); + shader = new ShaderModel(minorVersion, majorVersion, shaderType); + } + else if (chunkType == "OSGN") + { + + } + else if (chunkType == "SHDR") + { + ReadBytes(8); + int chunkSize = ReadInt32() * 4; + long chunkEnd = BaseStream.Position + chunkSize - 8; + while (BaseStream.Position < chunkEnd) + { + D3D10Instruction instruction = ReadInstruction(); + InstructionVerifier.Verify(instruction); + shader.Instructions.Add(instruction); + } + } + } + + return shader; + } + + private D3D10Instruction ReadInstruction() + { + uint instructionToken = ReadUInt32(); + D3D10Opcode opcode = (D3D10Opcode)(instructionToken & 0x3FF); + + int paramCount = (int)((instructionToken >> 24) & 0xFF) - 1; + bool isExtended = (instructionToken & 0x80000000) != 0; + + uint[] paramTokens = new uint[paramCount]; + for (int i = 0; i < paramCount; i++) + { + paramTokens[i] = ReadUInt32(); + } + var instruction = new D3D10Instruction(opcode, paramTokens); + return instruction; + } + } +} diff --git a/DirectXShaderModel/Reader/FormatDetector.cs b/DirectXShaderModel/Reader/FormatDetector.cs index a2959c7..334a957 100644 --- a/DirectXShaderModel/Reader/FormatDetector.cs +++ b/DirectXShaderModel/Reader/FormatDetector.cs @@ -7,7 +7,8 @@ namespace HlslDecompiler enum ShaderFileFormat { Unknown, - ShaderModel, + ShaderModel3, + Dxbc, Rgxa } @@ -31,7 +32,7 @@ public static ShaderFileFormat Detect(Stream stream) signature = reader.ReadUInt32(); if (signature == 0xFFFE0300 || signature == 0xFFFF0300) { - format = ShaderFileFormat.ShaderModel; + format = ShaderFileFormat.ShaderModel3; } } } diff --git a/DirectXShaderModel/Reader/ShaderReader.cs b/DirectXShaderModel/Reader/ShaderReader.cs index 42f8371..21a1cc8 100644 --- a/DirectXShaderModel/Reader/ShaderReader.cs +++ b/DirectXShaderModel/Reader/ShaderReader.cs @@ -21,7 +21,7 @@ virtual public ShaderModel ReadShader() while (true) { - Instruction instruction = ReadInstruction(); + D3D9Instruction instruction = ReadInstruction(); InstructionVerifier.Verify(instruction); shader.Instructions.Add(instruction); if (instruction.Opcode == Opcode.End) break; @@ -30,7 +30,7 @@ virtual public ShaderModel ReadShader() return shader; } - private Instruction ReadInstruction() + private D3D9Instruction ReadInstruction() { uint instructionToken = ReadUInt32(); Opcode opcode = (Opcode)(instructionToken & 0xffff); @@ -50,7 +50,7 @@ private Instruction ReadInstruction() { paramTokens[i] = ReadUInt32(); } - var instruction = new Instruction(opcode, paramTokens); + var instruction = new D3D9Instruction(opcode, paramTokens); if (opcode != Opcode.Comment) { diff --git a/DirectXShaderModel/RegisterKey.cs b/DirectXShaderModel/RegisterKey.cs index b2e65c7..e5c6779 100644 --- a/DirectXShaderModel/RegisterKey.cs +++ b/DirectXShaderModel/RegisterKey.cs @@ -8,8 +8,14 @@ public RegisterKey(RegisterType registerType, int registerNumber) Number = registerNumber; } + public RegisterKey(OperandType operandType) + { + OperandType = operandType; + } + public int Number { get; } public RegisterType Type { get; } + public OperandType OperandType { get; } public override bool Equals(object obj) diff --git a/DirectXShaderModel/RegisterType.cs b/DirectXShaderModel/RegisterType.cs index 0975de2..9ecf345 100644 --- a/DirectXShaderModel/RegisterType.cs +++ b/DirectXShaderModel/RegisterType.cs @@ -1,6 +1,6 @@ namespace HlslDecompiler.DirectXShaderModel { - // https://msdn.microsoft.com/en-us/library/windows/hardware/ff569707%28v=vs.85%29.aspx + // https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/d3d9types/ne-d3d9types-_d3dshader_param_register_type public enum RegisterType { Temp, diff --git a/DirectXShaderModel/ResultModifier.cs b/DirectXShaderModel/ResultModifier.cs index 5cacbdf..94e4a06 100644 --- a/DirectXShaderModel/ResultModifier.cs +++ b/DirectXShaderModel/ResultModifier.cs @@ -1,6 +1,6 @@ namespace HlslDecompiler.DirectXShaderModel { - // https://msdn.microsoft.com/en-us/library/windows/hardware/ff552738%28v=vs.85%29.aspx + // https://docs.microsoft.com/en-us/windows-hardware/drivers/display/destination-parameter-token public enum ResultModifier { None, diff --git a/DirectXShaderModel/ShaderModel.cs b/DirectXShaderModel/ShaderModel.cs index 50f0b43..e791a55 100644 --- a/DirectXShaderModel/ShaderModel.cs +++ b/DirectXShaderModel/ShaderModel.cs @@ -92,7 +92,9 @@ public IList ParseConstantTable() private byte[] GetConstantTableData() { int ctabToken = FourCC.Make("CTAB"); - var ctabComment = Instructions.FirstOrDefault(x => x.Opcode == Opcode.Comment && x.Params[0] == ctabToken); + var ctabComment = Instructions + .OfType() + .FirstOrDefault(x => x.Opcode == Opcode.Comment && x.Params[0] == ctabToken); if (ctabComment == null) { return null; @@ -151,7 +153,7 @@ public void ToFile(string filename) writer.Write((byte)MajorVersion); writer.Write((ushort)Type); - foreach (Instruction i in Instructions) + foreach (D3D9Instruction i in Instructions) { uint instruction = (uint)i.Opcode | diff --git a/DirectXShaderModel/SourceModifier.cs b/DirectXShaderModel/SourceModifier.cs index 463474c..790f74d 100644 --- a/DirectXShaderModel/SourceModifier.cs +++ b/DirectXShaderModel/SourceModifier.cs @@ -1,6 +1,6 @@ namespace HlslDecompiler.DirectXShaderModel { - // https://msdn.microsoft.com/en-us/library/windows/hardware/ff569716%28v=vs.85%29.aspx + // https://docs.microsoft.com/en-us/windows-hardware/drivers/display/source-parameter-token?redirectedfrom=MSDN public enum SourceModifier { None, diff --git a/Hlsl/Compiler/RegisterState.cs b/Hlsl/Compiler/RegisterState.cs index 805491f..2d16e52 100644 --- a/Hlsl/Compiler/RegisterState.cs +++ b/Hlsl/Compiler/RegisterState.cs @@ -39,7 +39,7 @@ public string GetDestinationName(Instruction instruction) return string.Format("{0}{1}", registerName, writeMaskName); } - public string GetSourceName(Instruction instruction, int srcIndex) + public string GetSourceName(D3D9Instruction instruction, int srcIndex) { string sourceRegisterName; @@ -116,7 +116,7 @@ public string GetSourceName(Instruction instruction, int srcIndex) private string GetRelativeAddressingName(Instruction instruction, int srcIndex) { - if (instruction.Params.HasRelativeAddressing(srcIndex)) + if (instruction is D3D9Instruction d3D9Instruction && d3D9Instruction.Params.HasRelativeAddressing(srcIndex)) { return "[i]"; } @@ -265,100 +265,190 @@ private void Load(ShaderModel shader) } } - foreach (var instruction in shader.Instructions) + if (shader.MajorVersion <= 3) { - if (!instruction.HasDestination) + foreach (D3D9Instruction instruction in shader.Instructions) { - if (instruction.Opcode == Opcode.Loop) + if (!instruction.HasDestination) { - RegisterKey registerKey = new RegisterKey(RegisterType.Loop, 0); - if (!_registerDeclarations.TryGetValue(registerKey, out _)) + if (instruction.Opcode == Opcode.Loop) { - var registerDeclaration = new RegisterDeclaration(registerKey); - _registerDeclarations.Add(registerKey, registerDeclaration); + RegisterKey registerKey = new RegisterKey(RegisterType.Loop, 0); + if (!_registerDeclarations.TryGetValue(registerKey, out _)) + { + var registerDeclaration = new RegisterDeclaration(registerKey); + _registerDeclarations.Add(registerKey, registerDeclaration); + } } + continue; } - continue; - } - if (instruction.Opcode == Opcode.Dcl) - { - var registerDeclaration = new RegisterDeclaration(instruction); - RegisterKey registerKey = registerDeclaration.RegisterKey; + if (instruction.Opcode == Opcode.Dcl) + { + var registerDeclaration = new RegisterDeclaration(instruction); + RegisterKey registerKey = registerDeclaration.RegisterKey; - _registerDeclarations.Add(registerKey, registerDeclaration); + _registerDeclarations.Add(registerKey, registerDeclaration); - switch (registerKey.Type) + switch (registerKey.Type) + { + case RegisterType.Input: + case RegisterType.MiscType: + MethodInputRegisters.Add(registerKey, registerDeclaration); + break; + case RegisterType.Output: + case RegisterType.ColorOut: + MethodOutputRegisters.Add(registerKey, registerDeclaration); + break; + } + switch (registerKey.OperandType) + { + case OperandType.Output: + MethodOutputRegisters.Add(registerKey, registerDeclaration); + break; + } + } + else if (instruction.Opcode == Opcode.Def) { - case RegisterType.Input: - case RegisterType.MiscType: - MethodInputRegisters.Add(registerKey, registerDeclaration); - break; - case RegisterType.Output: - case RegisterType.ColorOut: - MethodOutputRegisters.Add(registerKey, registerDeclaration); - break; + var constant = new ConstantRegister( + instruction.GetParamRegisterNumber(0), + instruction.GetParamSingle(1), + instruction.GetParamSingle(2), + instruction.GetParamSingle(3), + instruction.GetParamSingle(4)); + _constantDefinitions.Add(constant); + } + else if (instruction.Opcode == Opcode.DefI) + { + var constantInt = new ConstantIntRegister(instruction.GetParamRegisterNumber(0), + instruction.Params[1], + instruction.Params[2], + instruction.Params[3], + instruction.Params[4]); + _constantIntDefinitions.Add(constantInt); + } + else + { + int destIndex = instruction.GetDestinationParamIndex(); + RegisterType registerType = instruction.GetParamRegisterType(destIndex); + // Find assignments to color outputs, since pixel shader outputs are not pre-declared + if (registerType == RegisterType.ColorOut) + { + if (shader.Type == ShaderType.Pixel) + { + int registerNumber = instruction.GetParamRegisterNumber(destIndex); + var registerKey = new RegisterKey(registerType, registerNumber); + if (MethodOutputRegisters.ContainsKey(registerKey) == false) + { + var reg = new RegisterDeclaration(registerKey); + MethodOutputRegisters[registerKey] = reg; + + if (!_registerDeclarations.TryGetValue(registerKey, out _)) + { + var registerDeclaration = new RegisterDeclaration(registerKey); + _registerDeclarations.Add(registerKey, registerDeclaration); + } + } + } + } + // Find assignments to temporary registers, since they are not pre-declared + else if (registerType == RegisterType.Temp) + { + int registerNumber = instruction.GetParamRegisterNumber(destIndex); + RegisterKey registerKey = new RegisterKey(registerType, registerNumber); + if (!_registerDeclarations.TryGetValue(registerKey, out _)) + { + var registerDeclaration = new RegisterDeclaration(registerKey); + _registerDeclarations.Add(registerKey, registerDeclaration); + } + } } } - else if (instruction.Opcode == Opcode.Def) - { - var constant = new ConstantRegister( - instruction.GetParamRegisterNumber(0), - instruction.GetParamSingle(1), - instruction.GetParamSingle(2), - instruction.GetParamSingle(3), - instruction.GetParamSingle(4)); - _constantDefinitions.Add(constant); - } - else if (instruction.Opcode == Opcode.DefI) - { - var constantInt = new ConstantIntRegister(instruction.GetParamRegisterNumber(0), - instruction.Params[1], - instruction.Params[2], - instruction.Params[3], - instruction.Params[4]); - _constantIntDefinitions.Add(constantInt); - } - else + } + else + { + foreach (D3D10Instruction instruction in shader.Instructions) { - int destIndex = instruction.GetDestinationParamIndex(); - RegisterType registerType = instruction.GetParamRegisterType(destIndex); - // Find assignments to color outputs, since pixel shader outputs are not pre-declared - if (registerType == RegisterType.ColorOut) + if (!instruction.HasDestination) { - if (shader.Type == ShaderType.Pixel) + if (instruction.Opcode == D3D10Opcode.Loop) { - int registerNumber = instruction.GetParamRegisterNumber(destIndex); - var registerKey = new RegisterKey(registerType, registerNumber); - if (MethodOutputRegisters.ContainsKey(registerKey) == false) + RegisterKey registerKey = new RegisterKey(RegisterType.Loop, 0); + if (!_registerDeclarations.TryGetValue(registerKey, out _)) { - var reg = new RegisterDeclaration(registerKey); - MethodOutputRegisters[registerKey] = reg; + var registerDeclaration = new RegisterDeclaration(registerKey); + _registerDeclarations.Add(registerKey, registerDeclaration); + } + } + continue; + } + + if (instruction.Opcode == D3D10Opcode.DclOutput) + { + var registerDeclaration = new RegisterDeclaration(instruction); + RegisterKey registerKey = registerDeclaration.RegisterKey; + + _registerDeclarations.Add(registerKey, registerDeclaration); - if (!_registerDeclarations.TryGetValue(registerKey, out _)) + switch (registerKey.Type) + { + case RegisterType.Input: + case RegisterType.MiscType: + MethodInputRegisters.Add(registerKey, registerDeclaration); + break; + case RegisterType.Output: + case RegisterType.ColorOut: + MethodOutputRegisters.Add(registerKey, registerDeclaration); + break; + } + switch (registerKey.OperandType) + { + case OperandType.Output: + MethodOutputRegisters.Add(registerKey, registerDeclaration); + break; + } + } + else + { + int destIndex = instruction.GetDestinationParamIndex(); + OperandType operandType = instruction.GetParamOperandType(destIndex); + // Find assignments to color outputs, since pixel shader outputs are not pre-declared + if (operandType == OperandType.Output) + { + if (shader.Type == ShaderType.Pixel) + { + int registerNumber = instruction.GetParamRegisterNumber(destIndex); + var registerKey = new RegisterKey(operandType); + if (MethodOutputRegisters.ContainsKey(registerKey) == false) { - var registerDeclaration = new RegisterDeclaration(registerKey); - _registerDeclarations.Add(registerKey, registerDeclaration); + var reg = new RegisterDeclaration(registerKey); + MethodOutputRegisters[registerKey] = reg; + + if (!_registerDeclarations.TryGetValue(registerKey, out _)) + { + var registerDeclaration = new RegisterDeclaration(registerKey); + _registerDeclarations.Add(registerKey, registerDeclaration); + } } } } - } - // Find assignments to temporary registers, since they are not pre-declared - else if (registerType == RegisterType.Temp) - { - int registerNumber = instruction.GetParamRegisterNumber(destIndex); - RegisterKey registerKey = new RegisterKey(registerType, registerNumber); - if (!_registerDeclarations.TryGetValue(registerKey, out _)) + // Find assignments to temporary registers, since they are not pre-declared + else if (operandType == OperandType.Temp) { - var registerDeclaration = new RegisterDeclaration(registerKey); - _registerDeclarations.Add(registerKey, registerDeclaration); + int registerNumber = instruction.GetParamRegisterNumber(destIndex); + RegisterKey registerKey = new RegisterKey(operandType); + if (!_registerDeclarations.TryGetValue(registerKey, out _)) + { + var registerDeclaration = new RegisterDeclaration(registerKey); + _registerDeclarations.Add(registerKey, registerDeclaration); + } } } } } } - private string GetSourceConstantName(Instruction instruction, int srcIndex) + private string GetSourceConstantName(D3D9Instruction instruction, int srcIndex) { var registerType = instruction.GetParamRegisterType(srcIndex); int registerNumber = instruction.GetParamRegisterNumber(srcIndex); @@ -465,7 +555,8 @@ private string GetSourceConstantName(Instruction instruction, int srcIndex) } else { - if (instruction.Opcode == Opcode.If || instruction.Opcode == Opcode.IfC) + if (instruction is D3D9Instruction d3D9Instruction + && (d3D9Instruction.Opcode == Opcode.If || d3D9Instruction.Opcode == Opcode.IfC)) { // TODO } diff --git a/Hlsl/HlslAstWriter.cs b/Hlsl/HlslAstWriter.cs index 1f06a47..408b101 100644 --- a/Hlsl/HlslAstWriter.cs +++ b/Hlsl/HlslAstWriter.cs @@ -1,7 +1,5 @@ using HlslDecompiler.DirectXShaderModel; using HlslDecompiler.Hlsl; -using System; -using System.Collections.Generic; using System.Linq; namespace HlslDecompiler diff --git a/Hlsl/HlslSimpleWriter.cs b/Hlsl/HlslSimpleWriter.cs index 5fc376b..0a773db 100644 --- a/Hlsl/HlslSimpleWriter.cs +++ b/Hlsl/HlslSimpleWriter.cs @@ -23,7 +23,10 @@ protected override void WriteMethodBody() WriteTemporaryVariableDeclarations(); foreach (Instruction instruction in _shader.Instructions) { - WriteInstruction(instruction); + if (instruction is D3D9Instruction d9Instruction) + { + WriteInstruction(d9Instruction); + } } WriteLine(); @@ -68,7 +71,7 @@ private Dictionary FindTemporaryRegisterAssignments() foreach (Instruction instruction in _shader.Instructions.Where(i => i.HasDestination)) { int destIndex = instruction.GetDestinationParamIndex(); - if (instruction.GetParamRegisterType(destIndex) == RegisterType.Temp) + if (instruction is D3D9Instruction d3D9Instruction && d3D9Instruction.GetParamRegisterType(destIndex) == RegisterType.Temp) { int writeMask = instruction.GetDestinationWriteMask(); @@ -86,7 +89,7 @@ private Dictionary FindTemporaryRegisterAssignments() return tempRegisters; } - private void WriteInstruction(Instruction instruction) + private void WriteInstruction(D3D9Instruction instruction) { switch (instruction.Opcode) { diff --git a/Hlsl/HlslWriter.cs b/Hlsl/HlslWriter.cs index d833537..6c63566 100644 --- a/Hlsl/HlslWriter.cs +++ b/Hlsl/HlslWriter.cs @@ -47,7 +47,11 @@ protected string GetDestinationName(Instruction instruction) protected string GetSourceName(Instruction instruction, int srcIndex) { - return _registers.GetSourceName(instruction, srcIndex); + if (instruction is D3D10Instruction) + { + throw new NotImplementedException(); + } + return _registers.GetSourceName(instruction as D3D9Instruction, srcIndex); } private static string GetConstantTypeName(ConstantDeclaration declaration) diff --git a/Hlsl/InstructionParser.cs b/Hlsl/InstructionParser.cs index fa5ed97..c506934 100644 --- a/Hlsl/InstructionParser.cs +++ b/Hlsl/InstructionParser.cs @@ -23,31 +23,49 @@ public HlslAst Parse(ShaderModel shader) while (instructionPointer < shader.Instructions.Count) { var instruction = shader.Instructions[instructionPointer]; - if (instruction.HasDestination) + if (instruction is D3D10Instruction d3D10Instruction) { - ParseAssignmentInstruction(instruction); - } - else - { - switch (instruction.Opcode) + switch (d3D10Instruction.Opcode) { - case Opcode.If: - case Opcode.IfC: - case Opcode.Else: - case Opcode.Loop: - case Opcode.Rep: - case Opcode.End: - case Opcode.Endif: - case Opcode.EndLoop: - case Opcode.EndRep: - ParseControlInstruction(instruction); - break; - case Opcode.Comment: + case D3D10Opcode.Discard: + case D3D10Opcode.Ret: break; default: throw new NotImplementedException(); } } + else if (instruction is D3D9Instruction d3D9Instruction) + { + if (d3D9Instruction.HasDestination) + { + ParseAssignmentInstruction(d3D9Instruction); + } + else + { + switch (d3D9Instruction.Opcode) + { + case Opcode.If: + case Opcode.IfC: + case Opcode.Else: + case Opcode.Loop: + case Opcode.Rep: + case Opcode.End: + case Opcode.Endif: + case Opcode.EndLoop: + case Opcode.EndRep: + ParseControlInstruction(instruction); + break; + case Opcode.Comment: + break; + default: + throw new NotImplementedException(); + } + } + } + else + { + throw new NotImplementedException(); + } instructionPointer++; } @@ -125,7 +143,7 @@ private void LoadConstantOutputs(ShaderModel shader) } } - private void ParseAssignmentInstruction(Instruction instruction) + private void ParseAssignmentInstruction(D3D9Instruction instruction) { var newOutputs = new Dictionary(); @@ -168,7 +186,7 @@ private static IEnumerable GetDestinationKeys(Instruction } } - private HlslTreeNode CreateInstructionTree(Instruction instruction, RegisterComponentKey destinationKey) + private HlslTreeNode CreateInstructionTree(D3D9Instruction instruction, RegisterComponentKey destinationKey) { int componentIndex = destinationKey.ComponentIndex; @@ -311,7 +329,19 @@ private HlslTreeNode CreateDotProduct2AddNode(Instruction instruction) private HlslTreeNode CreateDotProductNode(Instruction instruction) { var addends = new List(); - int numComponents = instruction.Opcode == Opcode.Dp3 ? 3 : 4; + int numComponents; + if (instruction is D3D9Instruction d3d9instruction) + { + numComponents = d3d9instruction.Opcode == Opcode.Dp3 ? 3 : 4; + } + else if (instruction is D3D10Instruction d3d10instruction) + { + numComponents = d3d10instruction.Opcode == D3D10Opcode.Dp3 ? 3 : 4; + } + else + { + throw new NotImplementedException(); + } for (int component = 0; component < numComponents; component++) { IList componentInput = GetInputs(instruction, component); @@ -336,22 +366,30 @@ private HlslTreeNode CreateNormalizeOutputNode(Instruction instruction, int outp private HlslTreeNode[] GetInputs(Instruction instruction, int componentIndex) { - int numInputs = GetNumInputs(instruction.Opcode); - var inputs = new HlslTreeNode[numInputs]; - for (int i = 0; i < numInputs; i++) + if (instruction is D3D9Instruction d3D9Instruction) { - int inputParameterIndex = i; - if (instruction.Opcode != Opcode.TexKill) + int numInputs = GetNumInputs(d3D9Instruction.Opcode); + var inputs = new HlslTreeNode[numInputs]; + for (int i = 0; i < numInputs; i++) { - inputParameterIndex++; + int inputParameterIndex = i; + if (d3D9Instruction.Opcode != Opcode.TexKill) + { + inputParameterIndex++; + } + RegisterComponentKey inputKey = GetParamRegisterComponentKey(instruction, inputParameterIndex, componentIndex); + HlslTreeNode input = _activeOutputs[inputKey]; + if (instruction is D3D9Instruction d3D9Instruction2) + { + SourceModifier modifier = d3D9Instruction2.GetSourceModifier(inputParameterIndex); + input = ApplyModifier(input, modifier); + } + inputs[i] = input; } - RegisterComponentKey inputKey = GetParamRegisterComponentKey(instruction, inputParameterIndex, componentIndex); - HlslTreeNode input = _activeOutputs[inputKey]; - SourceModifier modifier = instruction.GetSourceModifier(inputParameterIndex); - input = ApplyModifier(input, modifier); - inputs[i] = input; + return inputs; } - return inputs; + throw new NotImplementedException(); + } private HlslTreeNode[] GetInputComponents(Instruction instruction, int inputParameterIndex, int numComponents) @@ -361,8 +399,11 @@ private HlslTreeNode[] GetInputComponents(Instruction instruction, int inputPara { RegisterComponentKey inputKey = GetParamRegisterComponentKey(instruction, inputParameterIndex, i); HlslTreeNode input = _activeOutputs[inputKey]; - var modifier = instruction.GetSourceModifier(inputParameterIndex); - input = ApplyModifier(input, modifier); + if (instruction is D3D9Instruction d9Instruction) + { + var modifier = d9Instruction.GetSourceModifier(inputParameterIndex); + input = ApplyModifier(input, modifier); + } components[i] = input; } return components; diff --git a/HlslDecompiler.Tests/CompileShaders.ps1 b/HlslDecompiler.Tests/CompileShaders.ps1 index 1e75d69..087b032 100644 --- a/HlslDecompiler.Tests/CompileShaders.ps1 +++ b/HlslDecompiler.Tests/CompileShaders.ps1 @@ -30,20 +30,19 @@ function RunProgram($program, $arguments) { } function CompileShader($basename, $profile, $fxc) { - Write-Host "Compiling $basename..." + Write-Host "Compiling $profile\$basename..." if ($generateAssemblyListing) { - $assemblyListingArg = " /Fc ShaderAssembly\$basename.asm" + $assemblyListingArg = " /Fc ShaderAssembly\$profile\$basename.asm" } else { $assemblyListingArg = "" } - $arguments = "/T $profile ShaderSources/$basename.fx /Fo CompiledShaders/$basename.fxc$assemblyListingArg" + $arguments = "/T $profile ShaderSources\$profile\$basename.fx /Fo CompiledShaders/$profile/$basename.fxc$assemblyListingArg" RunProgram $fxc $arguments } -function CompileByType($shaderType, $fxc) { - $profile = "$($shaderType)_3_0" - ForEach ($shaderSource in Get-ChildItem "ShaderSources\$($shaderType)_*.fx") { - CompileShader $shaderSource.Basename $profile $fxc +function CompileByProfile($profile, $fxc) { + ForEach ($shaderSource in Get-ChildItem "ShaderSources\$($profile)\*.fx") { + CompileShader "$($shaderSource.Basename)" $profile $fxc } } @@ -55,8 +54,10 @@ function CompileAll { } Write-Host "Using $fxc" - CompileByType "ps" $fxc - CompileByType "vs" $fxc + CompileByProfile "ps_3_0" $fxc + CompileByProfile "ps_4_0" $fxc + CompileByProfile "vs_3_0" $fxc + CompileByProfile "vs_4_0" $fxc } CompileAll diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_absolute_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/absolute_multiply.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_absolute_multiply.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/absolute_multiply.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_clip.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/clip.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_clip.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/clip.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_conditional.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/conditional.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_conditional.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/conditional.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_constant.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/constant.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_constant.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/constant.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_constant_struct.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/constant_struct.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_constant_struct.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/constant_struct.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_dot_product2_add.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/dot_product2_add.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_dot_product2_add.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/dot_product2_add.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_float4_constant.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/float4_constant.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_float4_constant.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/float4_constant.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_float4_construct.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/float4_construct.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_float4_construct.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/float4_construct.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_float4_construct2.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/float4_construct2.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_float4_construct2.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/float4_construct2.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_multiply_subtract.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/multiply_subtract.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_multiply_subtract.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/multiply_subtract.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_negate_absolute.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/negate_absolute.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_negate_absolute.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/negate_absolute.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_tex2d.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/tex2d.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_tex2d.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/tex2d.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_tex2d_swizzle.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/tex2d_swizzle.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_tex2d_swizzle.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/tex2d_swizzle.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_tex2d_two_samplers.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/tex2d_two_samplers.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_tex2d_two_samplers.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/tex2d_two_samplers.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_texcoord.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/texcoord.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_texcoord.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/texcoord.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_texcoord_modifier.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/texcoord_modifier.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_texcoord_modifier.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/texcoord_modifier.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_texcoord_swizzle.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_3_0/texcoord_swizzle.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/ps_texcoord_swizzle.fxc rename to HlslDecompiler.Tests/CompiledShaders/ps_3_0/texcoord_swizzle.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/absolute_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/absolute_multiply.fxc new file mode 100644 index 0000000..2ec630a Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/absolute_multiply.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/clip.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/clip.fxc new file mode 100644 index 0000000..734c7cc Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/clip.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/conditional.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/conditional.fxc new file mode 100644 index 0000000..a9347b2 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/conditional.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/constant.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/constant.fxc new file mode 100644 index 0000000..d8d24af Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/constant.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/constant_struct.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/constant_struct.fxc new file mode 100644 index 0000000..3a22d7a Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/constant_struct.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/dot_product2_add.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/dot_product2_add.fxc new file mode 100644 index 0000000..dabf575 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/dot_product2_add.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/float4_constant.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/float4_constant.fxc new file mode 100644 index 0000000..bc4d945 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/float4_constant.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/float4_construct.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/float4_construct.fxc new file mode 100644 index 0000000..a31884a Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/float4_construct.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/float4_construct2.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/float4_construct2.fxc new file mode 100644 index 0000000..9bef07a Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/float4_construct2.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/multiply_negate.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/multiply_negate.fxc new file mode 100644 index 0000000..9246dbc Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/multiply_negate.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/multiply_subtract.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/multiply_subtract.fxc new file mode 100644 index 0000000..7860c9b Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/multiply_subtract.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/negate_absolute.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/negate_absolute.fxc new file mode 100644 index 0000000..76b2447 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/negate_absolute.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/sample_2d.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/sample_2d.fxc new file mode 100644 index 0000000..d656a96 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/sample_2d.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/sample_2d_swizzle.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/sample_2d_swizzle.fxc new file mode 100644 index 0000000..aa7d14c Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/sample_2d_swizzle.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/sample_2d_two_samplers.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/sample_2d_two_samplers.fxc new file mode 100644 index 0000000..ca1b162 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/sample_2d_two_samplers.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/texcoord.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/texcoord.fxc new file mode 100644 index 0000000..c8a0b84 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/texcoord.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/texcoord_modifier.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/texcoord_modifier.fxc new file mode 100644 index 0000000..8af257a Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/texcoord_modifier.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/ps_4_0/texcoord_swizzle.fxc b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/texcoord_swizzle.fxc new file mode 100644 index 0000000..fc9af31 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/ps_4_0/texcoord_swizzle.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_3_0/constant.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/constant.fxc new file mode 100644 index 0000000..7d2cd4a Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/constant.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_3_0/constant_struct.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/constant_struct.fxc new file mode 100644 index 0000000..416a9ca Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/constant_struct.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_3_0/dot_product.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/dot_product.fxc new file mode 100644 index 0000000..4b3262b Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/dot_product.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_length.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/length.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/vs_length.fxc rename to HlslDecompiler.Tests/CompiledShaders/vs_3_0/length.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_3_0/matrix22_vector2_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/matrix22_vector2_multiply.fxc new file mode 100644 index 0000000..6741a7a Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/matrix22_vector2_multiply.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_matrix23_vector2_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/matrix23_vector2_multiply.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/vs_matrix23_vector2_multiply.fxc rename to HlslDecompiler.Tests/CompiledShaders/vs_3_0/matrix23_vector2_multiply.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_3_0/matrix33_vector3_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/matrix33_vector3_multiply.fxc new file mode 100644 index 0000000..a39b14d Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/matrix33_vector3_multiply.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_3_0/matrix44_vector4_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/matrix44_vector4_multiply.fxc new file mode 100644 index 0000000..0eca726 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/matrix44_vector4_multiply.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_3_0/normalize.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/normalize.fxc new file mode 100644 index 0000000..85d6a5a Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/normalize.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_submatrix43_vector3_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/submatrix43_vector3_multiply.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/vs_submatrix43_vector3_multiply.fxc rename to HlslDecompiler.Tests/CompiledShaders/vs_3_0/submatrix43_vector3_multiply.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_vector2_matrix22_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/vector2_matrix22_multiply.fxc similarity index 54% rename from HlslDecompiler.Tests/CompiledShaders/vs_vector2_matrix22_multiply.fxc rename to HlslDecompiler.Tests/CompiledShaders/vs_3_0/vector2_matrix22_multiply.fxc index a0e4014..4635699 100644 Binary files a/HlslDecompiler.Tests/CompiledShaders/vs_vector2_matrix22_multiply.fxc and b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/vector2_matrix22_multiply.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_vector2_matrix32_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/vector2_matrix32_multiply.fxc similarity index 100% rename from HlslDecompiler.Tests/CompiledShaders/vs_vector2_matrix32_multiply.fxc rename to HlslDecompiler.Tests/CompiledShaders/vs_3_0/vector2_matrix32_multiply.fxc diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_3_0/vector3_matrix33_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/vector3_matrix33_multiply.fxc new file mode 100644 index 0000000..3cc2482 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/vector3_matrix33_multiply.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_3_0/vector4_matrix44_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/vector4_matrix44_multiply.fxc new file mode 100644 index 0000000..f500307 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_3_0/vector4_matrix44_multiply.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_4_0/constant.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/constant.fxc new file mode 100644 index 0000000..617499a Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/constant.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_4_0/constant_struct.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/constant_struct.fxc new file mode 100644 index 0000000..dfc03de Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/constant_struct.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_4_0/dot_product.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/dot_product.fxc new file mode 100644 index 0000000..230c59a Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/dot_product.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_4_0/length.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/length.fxc new file mode 100644 index 0000000..2154b5d Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/length.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_4_0/matrix22_vector2_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/matrix22_vector2_multiply.fxc new file mode 100644 index 0000000..febc3f2 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/matrix22_vector2_multiply.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_4_0/matrix23_vector2_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/matrix23_vector2_multiply.fxc new file mode 100644 index 0000000..0091216 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/matrix23_vector2_multiply.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_4_0/matrix33_vector3_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/matrix33_vector3_multiply.fxc new file mode 100644 index 0000000..b2030c1 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/matrix33_vector3_multiply.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_4_0/matrix44_vector4_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/matrix44_vector4_multiply.fxc new file mode 100644 index 0000000..cd32bf3 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/matrix44_vector4_multiply.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_4_0/normalize.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/normalize.fxc new file mode 100644 index 0000000..9807305 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/normalize.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_4_0/submatrix43_vector3_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/submatrix43_vector3_multiply.fxc new file mode 100644 index 0000000..91ae177 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/submatrix43_vector3_multiply.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_4_0/vector2_matrix22_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/vector2_matrix22_multiply.fxc new file mode 100644 index 0000000..97a9a6d Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/vector2_matrix22_multiply.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_4_0/vector2_matrix32_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/vector2_matrix32_multiply.fxc new file mode 100644 index 0000000..ac6f228 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/vector2_matrix32_multiply.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_4_0/vector3_matrix33_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/vector3_matrix33_multiply.fxc new file mode 100644 index 0000000..9d13716 Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/vector3_matrix33_multiply.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_4_0/vector4_matrix44_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/vector4_matrix44_multiply.fxc new file mode 100644 index 0000000..227182e Binary files /dev/null and b/HlslDecompiler.Tests/CompiledShaders/vs_4_0/vector4_matrix44_multiply.fxc differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_constant.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_constant.fxc deleted file mode 100644 index e4f8e90..0000000 Binary files a/HlslDecompiler.Tests/CompiledShaders/vs_constant.fxc and /dev/null differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_constant_struct.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_constant_struct.fxc deleted file mode 100644 index 69f526d..0000000 Binary files a/HlslDecompiler.Tests/CompiledShaders/vs_constant_struct.fxc and /dev/null differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_dot_product.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_dot_product.fxc deleted file mode 100644 index 4a5a90b..0000000 Binary files a/HlslDecompiler.Tests/CompiledShaders/vs_dot_product.fxc and /dev/null differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_matrix22_vector2_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_matrix22_vector2_multiply.fxc deleted file mode 100644 index 805e3dd..0000000 Binary files a/HlslDecompiler.Tests/CompiledShaders/vs_matrix22_vector2_multiply.fxc and /dev/null differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_matrix33_vector3_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_matrix33_vector3_multiply.fxc deleted file mode 100644 index 23a8e87..0000000 Binary files a/HlslDecompiler.Tests/CompiledShaders/vs_matrix33_vector3_multiply.fxc and /dev/null differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_matrix44_vector4_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_matrix44_vector4_multiply.fxc deleted file mode 100644 index d1a3c61..0000000 Binary files a/HlslDecompiler.Tests/CompiledShaders/vs_matrix44_vector4_multiply.fxc and /dev/null differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_normalize.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_normalize.fxc deleted file mode 100644 index 1aae71f..0000000 Binary files a/HlslDecompiler.Tests/CompiledShaders/vs_normalize.fxc and /dev/null differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_vector3_matrix33_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_vector3_matrix33_multiply.fxc deleted file mode 100644 index d3819fd..0000000 Binary files a/HlslDecompiler.Tests/CompiledShaders/vs_vector3_matrix33_multiply.fxc and /dev/null differ diff --git a/HlslDecompiler.Tests/CompiledShaders/vs_vector4_matrix44_multiply.fxc b/HlslDecompiler.Tests/CompiledShaders/vs_vector4_matrix44_multiply.fxc deleted file mode 100644 index ec310c6..0000000 Binary files a/HlslDecompiler.Tests/CompiledShaders/vs_vector4_matrix44_multiply.fxc and /dev/null differ diff --git a/HlslDecompiler.Tests/DecompileDxbcTests.cs b/HlslDecompiler.Tests/DecompileDxbcTests.cs new file mode 100644 index 0000000..a93423b --- /dev/null +++ b/HlslDecompiler.Tests/DecompileDxbcTests.cs @@ -0,0 +1,78 @@ +using HlslDecompiler.DirectXShaderModel; +using NUnit.Framework; +using System.IO; + +namespace HlslDecompiler.Tests +{ + [TestFixture] + public class DecompileDxbcTests + { + [TestCase("ps_4_0", "conditional")] + [TestCase("ps_4_0", "constant")] + [TestCase("ps_4_0", "constant_struct")] + [TestCase("ps_4_0", "dot_product2_add")] + [TestCase("ps_4_0", "texcoord")] + [TestCase("ps_4_0", "texcoord_modifier")] + [TestCase("ps_4_0", "texcoord_swizzle")] + [TestCase("ps_4_0", "float4_construct")] + [TestCase("ps_4_0", "float4_construct2")] + [TestCase("ps_4_0", "float4_constant")] + [TestCase("ps_4_0", "multiply_subtract")] + [TestCase("ps_4_0", "absolute_multiply")] + [TestCase("ps_4_0", "negate_absolute")] + [TestCase("ps_4_0", "sample_2d")] + [TestCase("ps_4_0", "sample_2d_swizzle")] + [TestCase("ps_4_0", "sample_2d_two_samplers")] + [TestCase("ps_4_0", "clip")] + [TestCase("vs_4_0", "constant")] + [TestCase("vs_4_0", "constant_struct")] + [TestCase("vs_4_0", "dot_product")] + [TestCase("vs_4_0", "length")] + [TestCase("vs_4_0", "matrix22_vector2_multiply")] + [TestCase("vs_4_0", "matrix23_vector2_multiply")] + [TestCase("vs_4_0", "matrix33_vector3_multiply")] + [TestCase("vs_4_0", "matrix44_vector4_multiply")] + [TestCase("vs_4_0", "normalize")] + [TestCase("vs_4_0", "submatrix43_vector3_multiply")] + [TestCase("vs_4_0", "vector2_matrix22_multiply")] + [TestCase("vs_4_0", "vector2_matrix32_multiply")] + [TestCase("vs_4_0", "vector3_matrix33_multiply")] + [TestCase("vs_4_0", "vector4_matrix44_multiply")] + public void DecompileTest(string profile, string baseFilename) + { + string compiledShaderFilename = $"CompiledShaders{Path.DirectorySeparatorChar}{profile}{Path.DirectorySeparatorChar}{baseFilename}.fxc"; + string asmExpectedFilename = $"ShaderAssembly{Path.DirectorySeparatorChar}{profile}{Path.DirectorySeparatorChar}{baseFilename}.asm"; + string hlslExpectedFilename = $"ShaderSources{Path.DirectorySeparatorChar}{profile}{Path.DirectorySeparatorChar}{baseFilename}.fx"; + string asmOutputFilename = $"{profile}{Path.DirectorySeparatorChar}{baseFilename}.asm"; + string hlslOutputFilename = $"{profile}{Path.DirectorySeparatorChar}{baseFilename}.fx"; + + ShaderModel shader; + + var inputStream = File.Open(Path.GetFullPath(compiledShaderFilename), FileMode.Open, FileAccess.Read); + using (var input = new DxbcReader(inputStream, true)) + { + shader = input.ReadShader(); + } + + var asmWriter = new AsmWriter(shader); + MakeFolder(asmOutputFilename); + asmWriter.Write(asmOutputFilename); + + var hlslWriter = new HlslAstWriter(shader); + MakeFolder(hlslOutputFilename); + hlslWriter.Write(hlslOutputFilename); + + FileAssert.AreEqual(asmExpectedFilename, asmOutputFilename, "Assembly not equal"); + FileAssert.AreEqual(hlslExpectedFilename, hlslOutputFilename, "HLSL not equal"); + } + + private static void MakeFolder(string hlslOutputFilename) + { + string directory = Path.GetDirectoryName(hlslOutputFilename); + if (!Directory.Exists(directory)) + { + Directory.CreateDirectory(directory); + } + } + } +} diff --git a/HlslDecompiler.Tests/DecompileTests.cs b/HlslDecompiler.Tests/DecompileTests.cs index f55ee86..d3ea3d7 100644 --- a/HlslDecompiler.Tests/DecompileTests.cs +++ b/HlslDecompiler.Tests/DecompileTests.cs @@ -7,48 +7,48 @@ namespace HlslDecompiler.Tests [TestFixture] public class DecompileTests { - [TestCase("ps_conditional")] - [TestCase("ps_constant")] - [TestCase("ps_constant_struct")] - [TestCase("ps_dot_product2_add")] - [TestCase("ps_texcoord")] - [TestCase("ps_texcoord_modifier")] - [TestCase("ps_texcoord_swizzle")] - [TestCase("ps_float4_construct")] - [TestCase("ps_float4_construct2")] - [TestCase("ps_float4_constant")] - [TestCase("ps_multiply_subtract")] - [TestCase("ps_absolute_multiply")] - [TestCase("ps_negate_absolute")] - [TestCase("ps_tex2d")] - [TestCase("ps_tex2d_swizzle")] - [TestCase("ps_tex2d_two_samplers")] - [TestCase("ps_clip")] - [TestCase("vs_constant")] - [TestCase("vs_constant_struct")] - [TestCase("vs_dot_product")] - [TestCase("vs_length")] - [TestCase("vs_matrix22_vector2_multiply")] - [TestCase("vs_matrix23_vector2_multiply")] - [TestCase("vs_matrix33_vector3_multiply")] - [TestCase("vs_matrix44_vector4_multiply")] - [TestCase("vs_normalize")] - [TestCase("vs_submatrix43_vector3_multiply")] - [TestCase("vs_vector2_matrix22_multiply")] - [TestCase("vs_vector2_matrix32_multiply")] - [TestCase("vs_vector3_matrix33_multiply")] - [TestCase("vs_vector4_matrix44_multiply")] - public void DecompileTest(string baseFilename) + [TestCase("ps_3_0", "conditional")] + [TestCase("ps_3_0", "constant")] + [TestCase("ps_3_0", "constant_struct")] + [TestCase("ps_3_0", "dot_product2_add")] + [TestCase("ps_3_0", "texcoord")] + [TestCase("ps_3_0", "texcoord_modifier")] + [TestCase("ps_3_0", "texcoord_swizzle")] + [TestCase("ps_3_0", "float4_construct")] + [TestCase("ps_3_0", "float4_construct2")] + [TestCase("ps_3_0", "float4_constant")] + [TestCase("ps_3_0", "multiply_subtract")] + [TestCase("ps_3_0", "absolute_multiply")] + [TestCase("ps_3_0", "negate_absolute")] + [TestCase("ps_3_0", "tex2d")] + [TestCase("ps_3_0", "tex2d_swizzle")] + [TestCase("ps_3_0", "tex2d_two_samplers")] + [TestCase("ps_3_0", "clip")] + [TestCase("vs_3_0", "constant")] + [TestCase("vs_3_0", "constant_struct")] + [TestCase("vs_3_0", "dot_product")] + [TestCase("vs_3_0", "length")] + [TestCase("vs_3_0", "matrix22_vector2_multiply")] + [TestCase("vs_3_0", "matrix23_vector2_multiply")] + [TestCase("vs_3_0", "matrix33_vector3_multiply")] + [TestCase("vs_3_0", "matrix44_vector4_multiply")] + [TestCase("vs_3_0", "normalize")] + [TestCase("vs_3_0", "submatrix43_vector3_multiply")] + [TestCase("vs_3_0", "vector2_matrix22_multiply")] + [TestCase("vs_3_0", "vector2_matrix32_multiply")] + [TestCase("vs_3_0", "vector3_matrix33_multiply")] + [TestCase("vs_3_0", "vector4_matrix44_multiply")] + public void DecompileShaderTest(string profile, string baseFilename) { - string compiledShaderFilename = $"CompiledShaders{Path.DirectorySeparatorChar}{baseFilename}.fxc"; - string asmExpectedFilename = $"ShaderAssembly{Path.DirectorySeparatorChar}{baseFilename}.asm"; - string hlslExpectedFilename = $"ShaderSources{Path.DirectorySeparatorChar}{baseFilename}.fx"; + string compiledShaderFilename = $"CompiledShaders{Path.DirectorySeparatorChar}{profile}{Path.DirectorySeparatorChar}{baseFilename}.fxc"; + string asmExpectedFilename = $"ShaderAssembly{Path.DirectorySeparatorChar}{profile}{Path.DirectorySeparatorChar}{baseFilename}.asm"; + string hlslExpectedFilename = $"ShaderSources{Path.DirectorySeparatorChar}{profile}{Path.DirectorySeparatorChar}{baseFilename}.fx"; string asmOutputFilename = $"{baseFilename}.asm"; string hlslOutputFilename = $"{baseFilename}.fx"; ShaderModel shader; - var inputStream = File.Open(compiledShaderFilename, FileMode.Open, FileAccess.Read); + var inputStream = File.Open(Path.GetFullPath(compiledShaderFilename), FileMode.Open, FileAccess.Read); using (var input = new ShaderReader(inputStream, true)) { shader = input.ReadShader(); diff --git a/HlslDecompiler.Tests/HlslDecompiler.Tests.csproj b/HlslDecompiler.Tests/HlslDecompiler.Tests.csproj index cdcc904..e88b471 100644 --- a/HlslDecompiler.Tests/HlslDecompiler.Tests.csproj +++ b/HlslDecompiler.Tests/HlslDecompiler.Tests.csproj @@ -1,7 +1,7 @@ - + - netcoreapp3.1 + net6.0 false @@ -17,288 +17,556 @@ - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + + + + + diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_absolute_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/absolute_multiply.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_absolute_multiply.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/absolute_multiply.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_clip.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/clip.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_clip.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/clip.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_conditional.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/conditional.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_conditional.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/conditional.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_constant.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/constant.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_constant.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/constant.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_constant_struct.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/constant_struct.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_constant_struct.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/constant_struct.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_dot_product2_add.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/dot_product2_add.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_dot_product2_add.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/dot_product2_add.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_float4_constant.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/float4_constant.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_float4_constant.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/float4_constant.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_float4_construct.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/float4_construct.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_float4_construct.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/float4_construct.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_float4_construct2.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/float4_construct2.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_float4_construct2.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/float4_construct2.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_multiply_subtract.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/multiply_subtract.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_multiply_subtract.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/multiply_subtract.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_negate_absolute.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/negate_absolute.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_negate_absolute.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/negate_absolute.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_tex2d.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/tex2d.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_tex2d.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/tex2d.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_tex2d_swizzle.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/tex2d_swizzle.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_tex2d_swizzle.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/tex2d_swizzle.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_tex2d_two_samplers.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/tex2d_two_samplers.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_tex2d_two_samplers.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/tex2d_two_samplers.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_texcoord.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/texcoord.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_texcoord.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/texcoord.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_texcoord_modifier.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/texcoord_modifier.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_texcoord_modifier.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/texcoord_modifier.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_texcoord_swizzle.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_3_0/texcoord_swizzle.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/ps_texcoord_swizzle.asm rename to HlslDecompiler.Tests/ShaderAssembly/ps_3_0/texcoord_swizzle.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/absolute_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/absolute_multiply.asm new file mode 100644 index 0000000..c7cbfba --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/absolute_multiply.asm @@ -0,0 +1,28 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// TEXCOORD 0 xyzw 0 NONE float x w +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v0.xw +dcl_output o0.xyzw +dcl_temps 1 +mul r0.x, v0.x, l(3.000000) +mov o0.w, |r0.x| +mad o0.xy, v0.xwxx, l(3.000000, 3.000000, 0.000000, 0.000000), l(-1.000000, -1.000000, 0.000000, 0.000000) +mov o0.z, l(8.000000) +ret +// Approximately 5 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/clip.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/clip.asm new file mode 100644 index 0000000..6f8d20d --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/clip.asm @@ -0,0 +1,25 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// TEXCOORD 0 xyzw 0 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v0.xyzw +dcl_output o0.xyzw +discard_nz l(-1) +mov o0.xyzw, v0.xyzw +ret +// Approximately 3 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/conditional.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/conditional.asm new file mode 100644 index 0000000..7515de6 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/conditional.asm @@ -0,0 +1,29 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// TEXCOORD 0 xyzw 0 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v0.xyzw +dcl_output o0.xyzw +dcl_temps 1 +ge r0.x, v0.x, l(0.000000) +mul r0.y, v0.y, l(3.000000) +add r0.z, v0.z, v0.z +movc o0.xyz, r0.xxxx, r0.yyyy, r0.zzzz +mov o0.w, v0.w +ret +// Approximately 6 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/constant.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/constant.asm new file mode 100644 index 0000000..b43bb0f --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/constant.asm @@ -0,0 +1,22 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// no Input +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_output o0.xyzw +mov o0.xyzw, l(0,0,0,0) +ret +// Approximately 2 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/constant_struct.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/constant_struct.asm new file mode 100644 index 0000000..4ceeaea --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/constant_struct.asm @@ -0,0 +1,25 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// no Input +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// SV_Target 1 xyzw 1 TARGET float xyzw +// +ps_4_0 +dcl_output o0.xyzw +dcl_output o1.xyzw +mov o0.xyzw, l(0.300000,0.700000,0.010000,-50.009998) +mov o1.xyzw, l(-1234567.000000,50.009998,5.010000,0) +ret +// Approximately 3 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/dot_product2_add.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/dot_product2_add.asm new file mode 100644 index 0000000..06b2eac --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/dot_product2_add.asm @@ -0,0 +1,27 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// TEXCOORD 0 xyzw 0 NONE float yzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v0.yzw +dcl_output o0.xyzw +dcl_temps 1 +dp2 r0.x, v0.yzyy, v0.zwzz +add o0.x, r0.x, l(1.000000) +mov o0.yzw, l(0,2.000000,3.000000,4.000000) +ret +// Approximately 4 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/float4_constant.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/float4_constant.asm new file mode 100644 index 0000000..7ec40c8 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/float4_constant.asm @@ -0,0 +1,22 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// no Input +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_output o0.xyzw +mov o0.xyzw, l(1.500000,0,1.500000,2.750000) +ret +// Approximately 2 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/float4_construct.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/float4_construct.asm new file mode 100644 index 0000000..e5eafd2 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/float4_construct.asm @@ -0,0 +1,36 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// TEXCOORD 0 xyzw 0 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// SV_Target 1 xyzw 1 TARGET float xyzw +// SV_Target 2 xyzw 2 TARGET float xyzw +// SV_Target 3 xyzw 3 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v0.xyzw +dcl_output o0.xyzw +dcl_output o1.xyzw +dcl_output o2.xyzw +dcl_output o3.xyzw +mov o0.xyzw, v0.xyzw +mov o1.xyz, v0.xyzx +mov o1.w, l(0) +mov o2.xy, v0.xyxx +mov o2.zw, l(0,0,0,1.000000) +mov o3.x, v0.x +mov o3.yzw, l(0,0,1.000000,2.000000) +ret +// Approximately 8 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/float4_construct2.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/float4_construct2.asm new file mode 100644 index 0000000..5308121 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/float4_construct2.asm @@ -0,0 +1,40 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// TEXCOORD 0 xy 0 NONE float xy +// TEXCOORD 1 xyzw 1 NONE float zw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// SV_Target 1 xyzw 1 TARGET float xyzw +// SV_Target 2 xyzw 2 TARGET float xyzw +// SV_Target 3 xyzw 3 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v0.xy +dcl_input_ps linear v1.zw +dcl_output o0.xyzw +dcl_output o1.xyzw +dcl_output o2.xyzw +dcl_output o3.xyzw +dcl_temps 1 +mov r0.zw, v0.xxxy +mov r0.xy, l(0,1.000000,0,0) +mov o0.xyzw, r0.zxyw +mov o1.xyzw, r0.xyzw +mov o2.xyz, l(0,1.000000,2.000000,0) +mov o2.w, v0.x +mov o3.xy, v0.xyxx +mov o3.zw, v1.zzzw +ret +// Approximately 9 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/multiply_negate.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/multiply_negate.asm new file mode 100644 index 0000000..fed0eac --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/multiply_negate.asm @@ -0,0 +1,29 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// TEXCOORD 0 xyz 0 NONE float xyz +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v0.xyz +dcl_output o0.xyzw +dcl_temps 1 +mul r0.x, v0.x, v0.y +mul r0.x, r0.x, v0.z +mov o0.x, -|r0.x| +mov o0.y, r0.x +mov o0.zw, l(0,0,1.000000,2.000000) +ret +// Approximately 6 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/multiply_subtract.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/multiply_subtract.asm new file mode 100644 index 0000000..0a21512 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/multiply_subtract.asm @@ -0,0 +1,26 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// TEXCOORD 0 xyzw 0 NONE float xy w +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v0.xyw +dcl_output o0.xyzw +mov o0.w, |v0.w| +mov o0.x, l(3.000000) +mad o0.yz, v0.xxyx, l(0.000000, 2.000000, 2.000000, 0.000000), l(0.000000, -1.000000, -1.000000, 0.000000) +ret +// Approximately 4 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/negate_absolute.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/negate_absolute.asm new file mode 100644 index 0000000..6bf5893 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/negate_absolute.asm @@ -0,0 +1,26 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// TEXCOORD 0 xyz 0 NONE float x z +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v0.xz +dcl_output o0.xyzw +mov o0.x, -|v0.z| +mov o0.y, v0.x +mov o0.zw, l(0,0,1.000000,2.000000) +ret +// Approximately 4 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/sample_2d.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/sample_2d.asm new file mode 100644 index 0000000..170b840 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/sample_2d.asm @@ -0,0 +1,34 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// samplerState0 sampler NA NA 0 1 +// texture0 texture float4 2d 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// TEXCOORD 0 xy 0 NONE float xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v0.xy +dcl_output o0.xyzw +sample o0.xyzw, v0.xyxx, t0.xyzw, s0 +ret +// Approximately 2 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/sample_2d_swizzle.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/sample_2d_swizzle.asm new file mode 100644 index 0000000..e4d8296 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/sample_2d_swizzle.asm @@ -0,0 +1,37 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// samplerState0 sampler NA NA 0 1 +// texture0 texture float4 2d 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// TEXCOORD 0 xy 0 NONE float xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v0.xy +dcl_output o0.xyzw +dcl_temps 1 +add r0.xy, v0.yxyy, v0.yxyy +sample r0.xyzw, r0.xyxx, t0.xyzw, s0 +mov o0.xyzw, r0.wzyx +ret +// Approximately 4 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/sample_2d_two_samplers.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/sample_2d_two_samplers.asm new file mode 100644 index 0000000..c326994 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/sample_2d_two_samplers.asm @@ -0,0 +1,40 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// samplerState0 sampler NA NA 0 1 +// samplerState1 sampler NA NA 1 1 +// texture0 texture float4 2d 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// TEXCOORD 0 xy 0 NONE float xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_sampler s0, mode_default +dcl_sampler s1, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v0.xy +dcl_output o0.xyzw +dcl_temps 1 +sample r0.xyzw, v0.yxyy, t0.xyzw, s1 +mad r0.xy, r0.xyxx, l(2.000000, 2.000000, 0.000000, 0.000000), v0.yxyy +sample r0.xyzw, r0.xyxx, t0.xyzw, s0 +mov o0.xyzw, r0.wzyx +ret +// Approximately 5 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/texcoord.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/texcoord.asm new file mode 100644 index 0000000..3322e52 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/texcoord.asm @@ -0,0 +1,24 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// TEXCOORD 0 xyzw 0 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v0.xyzw +dcl_output o0.xyzw +mov o0.xyzw, v0.xyzw +ret +// Approximately 2 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/texcoord_modifier.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/texcoord_modifier.asm new file mode 100644 index 0000000..d98b763 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/texcoord_modifier.asm @@ -0,0 +1,26 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// TEXCOORD 0 xyzw 0 NONE float xy w +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v0.xyw +dcl_output o0.xyzw +mov o0.w, |v0.w| +mov o0.xy, -v0.yxyy +mov o0.z, l(2.000000) +ret +// Approximately 4 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/texcoord_swizzle.asm b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/texcoord_swizzle.asm new file mode 100644 index 0000000..c55d001 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/ps_4_0/texcoord_swizzle.asm @@ -0,0 +1,25 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// TEXCOORD 0 xyz 0 NONE float xyz +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v0.xyz +dcl_output o0.xyzw +mov o0.xyz, v0.yzxy +mov o0.w, l(3.000000) +ret +// Approximately 3 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_constant.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_3_0/constant.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/vs_constant.asm rename to HlslDecompiler.Tests/ShaderAssembly/vs_3_0/constant.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_constant_struct.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_3_0/constant_struct.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/vs_constant_struct.asm rename to HlslDecompiler.Tests/ShaderAssembly/vs_3_0/constant_struct.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_dot_product.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_3_0/dot_product.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/vs_dot_product.asm rename to HlslDecompiler.Tests/ShaderAssembly/vs_3_0/dot_product.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_length.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_3_0/length.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/vs_length.asm rename to HlslDecompiler.Tests/ShaderAssembly/vs_3_0/length.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_matrix22_vector2_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_3_0/matrix22_vector2_multiply.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/vs_matrix22_vector2_multiply.asm rename to HlslDecompiler.Tests/ShaderAssembly/vs_3_0/matrix22_vector2_multiply.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_matrix23_vector2_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_3_0/matrix23_vector2_multiply.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/vs_matrix23_vector2_multiply.asm rename to HlslDecompiler.Tests/ShaderAssembly/vs_3_0/matrix23_vector2_multiply.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_matrix33_vector3_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_3_0/matrix33_vector3_multiply.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/vs_matrix33_vector3_multiply.asm rename to HlslDecompiler.Tests/ShaderAssembly/vs_3_0/matrix33_vector3_multiply.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_matrix44_vector4_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_3_0/matrix44_vector4_multiply.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/vs_matrix44_vector4_multiply.asm rename to HlslDecompiler.Tests/ShaderAssembly/vs_3_0/matrix44_vector4_multiply.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_normalize.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_3_0/normalize.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/vs_normalize.asm rename to HlslDecompiler.Tests/ShaderAssembly/vs_3_0/normalize.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_submatrix43_vector3_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_3_0/submatrix43_vector3_multiply.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/vs_submatrix43_vector3_multiply.asm rename to HlslDecompiler.Tests/ShaderAssembly/vs_3_0/submatrix43_vector3_multiply.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_vector2_matrix22_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_3_0/vector2_matrix22_multiply.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/vs_vector2_matrix22_multiply.asm rename to HlslDecompiler.Tests/ShaderAssembly/vs_3_0/vector2_matrix22_multiply.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_vector2_matrix32_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_3_0/vector2_matrix32_multiply.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/vs_vector2_matrix32_multiply.asm rename to HlslDecompiler.Tests/ShaderAssembly/vs_3_0/vector2_matrix32_multiply.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_vector3_matrix33_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_3_0/vector3_matrix33_multiply.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/vs_vector3_matrix33_multiply.asm rename to HlslDecompiler.Tests/ShaderAssembly/vs_3_0/vector3_matrix33_multiply.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_vector4_matrix44_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_3_0/vector4_matrix44_multiply.asm similarity index 100% rename from HlslDecompiler.Tests/ShaderAssembly/vs_vector4_matrix44_multiply.asm rename to HlslDecompiler.Tests/ShaderAssembly/vs_3_0/vector4_matrix44_multiply.asm diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/constant.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/constant.asm new file mode 100644 index 0000000..782f329 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/constant.asm @@ -0,0 +1,22 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// no Input +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// +vs_4_0 +dcl_output o0.xyzw +mov o0.xyzw, l(0,0,0,0) +ret +// Approximately 2 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/constant_struct.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/constant_struct.asm new file mode 100644 index 0000000..b761327 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/constant_struct.asm @@ -0,0 +1,31 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// no Input +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// POSITION 1 xyzw 1 NONE float xyzw +// POSITION 2 xyz 2 NONE float xyz +// POSITION 3 xyz 3 NONE float xyz +// +vs_4_0 +dcl_output o0.xyzw +dcl_output o1.xyzw +dcl_output o2.xyz +dcl_output o3.xyz +mov o0.xyzw, l(0,0,0,0) +mov o1.xyzw, l(0,0,0,0) +mov o2.xyz, l(0,0,0,0) +mov o3.xyz, l(0,0,0,0) +ret +// Approximately 5 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/dot_product.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/dot_product.asm new file mode 100644 index 0000000..d79eca3 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/dot_product.asm @@ -0,0 +1,51 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// Buffer Definitions: +// +// cbuffer $Globals +// { +// +// float2 constant2; // Offset: 0 Size: 8 +// float3 constant3; // Offset: 16 Size: 12 +// float4 constant4; // Offset: 32 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// $Globals cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// TEXCOORD 0 xyzw 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[3], immediateIndexed +dcl_input v0.xyzw +dcl_input v1.xyz +dcl_input v2.xy +dcl_output o0.xyzw +dp4 o0.x, cb0[2].xyzw, v0.xyzw +dp3 o0.y, cb0[1].xyzx, v1.xyzx +dp2 o0.z, cb0[0].xyxx, v2.xyxx +mov o0.w, l(4.000000) +ret +// Approximately 5 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/length.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/length.asm new file mode 100644 index 0000000..1eee3c6 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/length.asm @@ -0,0 +1,39 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// POSITION 1 xyzw 1 NONE float xyz +// POSITION 2 xyzw 2 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// +vs_4_0 +dcl_input v0.xyzw +dcl_input v1.xyz +dcl_input v2.xyzw +dcl_output o0.xyzw +dcl_temps 1 +add r0.xyzw, v2.xyzw, l(2.000000, 2.000000, 2.000000, 2.000000) +dp4 r0.x, r0.xyzw, r0.xyzw +sqrt r0.x, r0.x +mul o0.w, r0.x, l(-5.000000) +dp2 r0.x, v2.xyxx, v2.xyxx +sqrt r0.x, r0.x +mov o0.z, -r0.x +dp4 r0.x, v0.xyzw, v0.xyzw +sqrt o0.x, r0.x +dp3 r0.x, v1.xyzx, v1.xyzx +sqrt o0.y, r0.x +ret +// Approximately 12 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/matrix22_vector2_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/matrix22_vector2_multiply.asm new file mode 100644 index 0000000..b47f17c --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/matrix22_vector2_multiply.asm @@ -0,0 +1,53 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// Buffer Definitions: +// +// cbuffer $Globals +// { +// +// float2x2 matrix_2x2; // Offset: 0 Size: 24 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// $Globals cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// POSITION 1 xy 1 NONE float xy +// POSITION 2 zw 1 NONE float zw +// +vs_4_0 +dcl_constantbuffer cb0[2], immediateIndexed +dcl_input v0.xy +dcl_output o0.xyzw +dcl_output o1.xy +dcl_output o1.zw +dcl_temps 1 +mul r0.xyzw, v0.yyxx, cb0[1].xyxy +mad o0.xyzw, cb0[0].xyxy, v0.xxyy, r0.xyzw +add r0.xy, v0.xyxx, v0.xyxx +mul r0.yz, r0.yyyy, cb0[1].xxyx +mad o1.zw, cb0[0].xxxy, r0.xxxx, r0.yyyz +mul r0.xy, |v0.xxxx|, cb0[1].xyxx +mad o1.xy, cb0[0].xyxx, |v0.yyyy|, r0.xyxx +ret +// Approximately 8 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/matrix23_vector2_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/matrix23_vector2_multiply.asm new file mode 100644 index 0000000..6815aaa --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/matrix23_vector2_multiply.asm @@ -0,0 +1,53 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// Buffer Definitions: +// +// cbuffer $Globals +// { +// +// float2x3 matrix_2x3; // Offset: 0 Size: 40 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// $Globals cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// POSITION 1 xy 1 NONE float xy +// POSITION 2 zw 1 NONE float zw +// +vs_4_0 +dcl_constantbuffer cb0[2], immediateIndexed +dcl_input v0.xy +dcl_output o0.xyzw +dcl_output o1.xy +dcl_output o1.zw +dcl_temps 1 +mul r0.xyzw, v0.yyxx, cb0[1].xyxy +mad o0.xyzw, cb0[0].xyxy, v0.xxyy, r0.xyzw +add r0.xy, v0.xyxx, v0.xyxx +mul r0.yz, r0.yyyy, cb0[1].xxyx +mad o1.zw, cb0[0].xxxy, r0.xxxx, r0.yyyz +mul r0.xy, |v0.xxxx|, cb0[1].xyxx +mad o1.xy, cb0[0].xyxx, |v0.yyyy|, r0.xyxx +ret +// Approximately 8 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/matrix33_vector3_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/matrix33_vector3_multiply.asm new file mode 100644 index 0000000..fdad22c --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/matrix33_vector3_multiply.asm @@ -0,0 +1,62 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// Buffer Definitions: +// +// cbuffer $Globals +// { +// +// float3x3 matrix_3x3; // Offset: 0 Size: 44 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// $Globals cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyz +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// POSITION 1 xyz 1 NONE float xyz +// POSITION 2 xyz 2 NONE float xyz +// POSITION 3 xyz 3 NONE float xyz +// +vs_4_0 +dcl_constantbuffer cb0[3], immediateIndexed +dcl_input v0.xyz +dcl_output o0.xyzw +dcl_output o1.xyz +dcl_output o2.xyz +dcl_output o3.xyz +dcl_temps 2 +mul r0.xyz, v0.yyyy, cb0[1].xyzx +mad r1.xyz, cb0[0].xyzx, v0.xxxx, r0.xyzx +mad o0.xyz, cb0[2].xyzx, v0.zzzz, r1.xyzx +mov o0.w, l(1.000000) +mul r1.xyz, v0.xxxx, cb0[1].xyzx +mad r1.xyz, cb0[0].xyzx, v0.yyyy, r1.xyzx +mad o1.xyz, cb0[2].xyzx, v0.zzzz, r1.xyzx +mul r1.xyz, |v0.xxxx|, cb0[1].xyzx +mad r1.xyz, cb0[0].xyzx, |v0.yyyy|, r1.xyzx +mad o2.xyz, cb0[2].xyzx, |v0.zzzz|, r1.xyzx +add r0.w, v0.x, v0.x +mad r0.xyz, cb0[0].xyzx, r0.wwww, r0.xyzx +mul r0.w, v0.z, l(3.000000) +mad o3.xyz, cb0[2].xyzx, r0.wwww, r0.xyzx +ret +// Approximately 15 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/matrix44_vector4_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/matrix44_vector4_multiply.asm new file mode 100644 index 0000000..79860bc --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/matrix44_vector4_multiply.asm @@ -0,0 +1,65 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// Buffer Definitions: +// +// cbuffer $Globals +// { +// +// float4x4 matrix_4x4; // Offset: 0 Size: 64 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// $Globals cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// POSITION 1 xyzw 1 NONE float xyzw +// POSITION 2 xyzw 2 NONE float xyzw +// POSITION 3 xyzw 3 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[4], immediateIndexed +dcl_input v0.xyzw +dcl_output o0.xyzw +dcl_output o1.xyzw +dcl_output o2.xyzw +dcl_output o3.xyzw +dcl_temps 2 +mul r0.xyzw, v0.yyyy, cb0[1].xyzw +mad r0.xyzw, cb0[0].xyzw, v0.xxxx, r0.xyzw +mad r0.xyzw, cb0[2].xyzw, v0.zzzz, r0.xyzw +mad o0.xyzw, cb0[3].xyzw, v0.wwww, r0.xyzw +mul r0.xyzw, v0.xxxx, cb0[1].xyzw +mad r0.xyzw, cb0[0].xyzw, v0.yyyy, r0.xyzw +mad r0.xyzw, cb0[2].xyzw, v0.zzzz, r0.xyzw +mad o1.xyzw, cb0[3].xyzw, v0.wwww, r0.xyzw +mul r0.xyzw, |v0.xxxx|, cb0[1].xyzw +mad r0.xyzw, cb0[0].xyzw, |v0.yyyy|, r0.xyzw +mad r0.xyzw, cb0[2].xyzw, |v0.zzzz|, r0.xyzw +mad o2.xyzw, cb0[3].xyzw, |v0.wwww|, r0.xyzw +mul r0.xyzw, v0.xyzw, l(5.000000, 2.000000, 3.000000, 4.000000) +mul r1.xyzw, r0.yyyy, cb0[1].xyzw +mad r1.xyzw, cb0[0].xyzw, r0.xxxx, r1.xyzw +mad r1.xyzw, cb0[2].xyzw, r0.zzzz, r1.xyzw +mad o3.xyzw, cb0[3].xyzw, r0.wwww, r1.xyzw +ret +// Approximately 18 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/normalize.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/normalize.asm new file mode 100644 index 0000000..e7b25a9 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/normalize.asm @@ -0,0 +1,28 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyz +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// +vs_4_0 +dcl_input v0.xyz +dcl_output o0.xyzw +dcl_temps 1 +dp3 r0.x, v0.xyzx, v0.xyzx +rsq r0.x, r0.x +mul o0.xyz, r0.xxxx, v0.yxzy +mov o0.w, l(1.000000) +ret +// Approximately 5 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/submatrix43_vector3_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/submatrix43_vector3_multiply.asm new file mode 100644 index 0000000..6b13593 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/submatrix43_vector3_multiply.asm @@ -0,0 +1,45 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// Buffer Definitions: +// +// cbuffer $Globals +// { +// +// float4x4 matrix_4x4; // Offset: 0 Size: 64 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// $Globals cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyz +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[3], immediateIndexed +dcl_input v0.xyz +dcl_output o0.xyzw +dcl_temps 1 +mul r0.xyzw, v0.yyyy, cb0[1].xyzw +mad r0.xyzw, cb0[0].xyzw, v0.xxxx, r0.xyzw +mad o0.xyzw, cb0[2].xyzw, v0.zzzz, r0.xyzw +ret +// Approximately 4 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/vector2_matrix22_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/vector2_matrix22_multiply.asm new file mode 100644 index 0000000..ffe3e6e --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/vector2_matrix22_multiply.asm @@ -0,0 +1,55 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// Buffer Definitions: +// +// cbuffer $Globals +// { +// +// float2x2 matrix_2x2; // Offset: 0 Size: 24 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// $Globals cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// POSITION 1 xy 1 NONE float xy +// POSITION 2 zw 1 NONE float zw +// +vs_4_0 +dcl_constantbuffer cb0[2], immediateIndexed +dcl_input v0.xy +dcl_output o0.xyzw +dcl_output o1.xy +dcl_output o1.zw +dcl_temps 1 +dp2 o0.x, v0.xyxx, cb0[0].xyxx +dp2 o0.y, v0.xyxx, cb0[1].xyxx +dp2 o0.z, v0.yxyy, cb0[0].xyxx +dp2 o0.w, v0.yxyy, cb0[1].xyxx +dp2 o1.x, |v0.yxyy|, cb0[0].xyxx +dp2 o1.y, |v0.yxyy|, cb0[1].xyxx +add r0.xy, v0.xyxx, v0.xyxx +dp2 o1.z, r0.xyxx, cb0[0].xyxx +dp2 o1.w, r0.xyxx, cb0[1].xyxx +ret +// Approximately 10 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/vector2_matrix32_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/vector2_matrix32_multiply.asm new file mode 100644 index 0000000..8e8f647 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/vector2_matrix32_multiply.asm @@ -0,0 +1,55 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// Buffer Definitions: +// +// cbuffer $Globals +// { +// +// float3x2 matrix_3x2; // Offset: 0 Size: 28 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// $Globals cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// POSITION 1 xy 1 NONE float xy +// POSITION 2 zw 1 NONE float zw +// +vs_4_0 +dcl_constantbuffer cb0[2], immediateIndexed +dcl_input v0.xy +dcl_output o0.xyzw +dcl_output o1.xy +dcl_output o1.zw +dcl_temps 1 +dp2 o0.x, v0.xyxx, cb0[0].xyxx +dp2 o0.y, v0.xyxx, cb0[1].xyxx +dp2 o0.z, v0.yxyy, cb0[0].xyxx +dp2 o0.w, v0.yxyy, cb0[1].xyxx +dp2 o1.x, |v0.yxyy|, cb0[0].xyxx +dp2 o1.y, |v0.yxyy|, cb0[1].xyxx +add r0.xy, v0.xyxx, v0.xyxx +dp2 o1.z, r0.xyxx, cb0[0].xyxx +dp2 o1.w, r0.xyxx, cb0[1].xyxx +ret +// Approximately 10 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/vector3_matrix33_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/vector3_matrix33_multiply.asm new file mode 100644 index 0000000..7c165a4 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/vector3_matrix33_multiply.asm @@ -0,0 +1,62 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// Buffer Definitions: +// +// cbuffer $Globals +// { +// +// float3x3 matrix_3x3; // Offset: 0 Size: 44 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// $Globals cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyz +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// POSITION 1 xyz 1 NONE float xyz +// POSITION 2 xyz 2 NONE float xyz +// POSITION 3 xyz 3 NONE float xyz +// +vs_4_0 +dcl_constantbuffer cb0[3], immediateIndexed +dcl_input v0.xyz +dcl_output o0.xyzw +dcl_output o1.xyz +dcl_output o2.xyz +dcl_output o3.xyz +dcl_temps 1 +dp3 o0.x, v0.xyzx, cb0[0].xyzx +dp3 o0.y, v0.xyzx, cb0[1].xyzx +dp3 o0.z, v0.xyzx, cb0[2].xyzx +mov o0.w, l(1.000000) +dp3 o1.x, v0.yxzy, cb0[0].xyzx +dp3 o1.y, v0.yxzy, cb0[1].xyzx +dp3 o1.z, v0.yxzy, cb0[2].xyzx +dp3 o2.x, |v0.yxzy|, cb0[0].xyzx +dp3 o2.y, |v0.yxzy|, cb0[1].xyzx +dp3 o2.z, |v0.yxzy|, cb0[2].xyzx +mul r0.xyz, v0.yxzy, l(1.000000, 2.000000, 3.000000, 0.000000) +dp3 o3.x, r0.xyzx, cb0[0].xyzx +dp3 o3.y, r0.xyzx, cb0[1].xyzx +dp3 o3.z, r0.xyzx, cb0[2].xyzx +ret +// Approximately 15 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/vector4_matrix44_multiply.asm b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/vector4_matrix44_multiply.asm new file mode 100644 index 0000000..969ecc5 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderAssembly/vs_4_0/vector4_matrix44_multiply.asm @@ -0,0 +1,65 @@ +// +// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 +// +// +// Buffer Definitions: +// +// cbuffer $Globals +// { +// +// float4x4 matrix_4x4; // Offset: 0 Size: 64 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// $Globals cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// POSITION 1 xyzw 1 NONE float xyzw +// POSITION 2 xyzw 2 NONE float xyzw +// POSITION 3 xyzw 3 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[4], immediateIndexed +dcl_input v0.xyzw +dcl_output o0.xyzw +dcl_output o1.xyzw +dcl_output o2.xyzw +dcl_output o3.xyzw +dcl_temps 1 +dp4 o0.x, v0.xyzw, cb0[0].xyzw +dp4 o0.y, v0.xyzw, cb0[1].xyzw +dp4 o0.z, v0.xyzw, cb0[2].xyzw +dp4 o0.w, v0.xyzw, cb0[3].xyzw +dp4 o1.x, v0.yxzw, cb0[0].xyzw +dp4 o1.y, v0.yxzw, cb0[1].xyzw +dp4 o1.z, v0.yxzw, cb0[2].xyzw +dp4 o1.w, v0.yxzw, cb0[3].xyzw +dp4 o2.x, |v0.yxzw|, cb0[0].xyzw +dp4 o2.y, |v0.yxzw|, cb0[1].xyzw +dp4 o2.z, |v0.yxzw|, cb0[2].xyzw +dp4 o2.w, |v0.yxzw|, cb0[3].xyzw +mul r0.xyzw, v0.xyzw, l(5.000000, 2.000000, 3.000000, 4.000000) +dp4 o3.x, r0.xyzw, cb0[0].xyzw +dp4 o3.y, r0.xyzw, cb0[1].xyzw +dp4 o3.z, r0.xyzw, cb0[2].xyzw +dp4 o3.w, r0.xyzw, cb0[3].xyzw +ret +// Approximately 18 instruction slots used diff --git a/HlslDecompiler.Tests/ShaderSources/ps_absolute_multiply.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/absolute_multiply.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_absolute_multiply.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/absolute_multiply.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_clip.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/clip.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_clip.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/clip.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_conditional.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/conditional.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_conditional.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/conditional.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_constant.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/constant.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_constant.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/constant.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_constant_struct.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/constant_struct.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_constant_struct.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/constant_struct.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_dot_product2_add.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/dot_product2_add.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_dot_product2_add.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/dot_product2_add.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_float4_constant.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/float4_constant.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_float4_constant.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/float4_constant.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_float4_construct.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/float4_construct.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_float4_construct.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/float4_construct.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_float4_construct2.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/float4_construct2.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_float4_construct2.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/float4_construct2.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_multiply_negate.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/multiply_negate.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_multiply_negate.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/multiply_negate.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_multiply_subtract.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/multiply_subtract.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_multiply_subtract.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/multiply_subtract.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_negate_absolute.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/negate_absolute.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_negate_absolute.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/negate_absolute.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_tex2d.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/tex2d.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_tex2d.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/tex2d.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_tex2d_swizzle.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/tex2d_swizzle.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_tex2d_swizzle.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/tex2d_swizzle.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_tex2d_two_samplers.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/tex2d_two_samplers.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_tex2d_two_samplers.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/tex2d_two_samplers.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_texcoord.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/texcoord.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_texcoord.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/texcoord.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_texcoord_modifier.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/texcoord_modifier.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_texcoord_modifier.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/texcoord_modifier.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_texcoord_swizzle.fx b/HlslDecompiler.Tests/ShaderSources/ps_3_0/texcoord_swizzle.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/ps_texcoord_swizzle.fx rename to HlslDecompiler.Tests/ShaderSources/ps_3_0/texcoord_swizzle.fx diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/absolute_multiply.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/absolute_multiply.fx new file mode 100644 index 0000000..7084ad7 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/absolute_multiply.fx @@ -0,0 +1,4 @@ +float4 main(float4 texcoord : TEXCOORD) : SV_Target +{ + return float4(3 * texcoord.xw - 1, 8, abs(3 * texcoord.x)); +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/clip.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/clip.fx new file mode 100644 index 0000000..9334166 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/clip.fx @@ -0,0 +1,5 @@ +float4 main(float4 texcoord : TEXCOORD) : SV_Target +{ + clip(-1); + return texcoord; +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/conditional.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/conditional.fx new file mode 100644 index 0000000..5f01339 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/conditional.fx @@ -0,0 +1,4 @@ +float4 main(float4 texcoord : TEXCOORD) : SV_Target +{ + return float4(texcoord.x >= 0 ? 3 * texcoord.yyy : 2 * texcoord.zzz, texcoord.w); +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/constant.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/constant.fx new file mode 100644 index 0000000..58def22 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/constant.fx @@ -0,0 +1,4 @@ +float4 main() : SV_Target +{ + return 0; +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/constant_struct.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/constant_struct.fx new file mode 100644 index 0000000..f11e003 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/constant_struct.fx @@ -0,0 +1,15 @@ +struct PS_OUT +{ + float4 color : SV_Target; + float4 color1 : SV_Target1; +}; + +PS_OUT main() +{ + PS_OUT o; + + o.color = float4(0.300000012, 0.699999988, 0.00999999978, -50.0099983); + o.color1 = float4(-1234567, 50.0099983, 5.01000023, 0); + + return o; +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/dot_product2_add.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/dot_product2_add.fx new file mode 100644 index 0000000..bed4e96 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/dot_product2_add.fx @@ -0,0 +1,4 @@ +float4 main(float4 texcoord : TEXCOORD) : SV_Target +{ + return float4(dot(texcoord.yz, texcoord.zw) + 1, 2, 3, 4); +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/float4_constant.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/float4_constant.fx new file mode 100644 index 0000000..b976f8f --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/float4_constant.fx @@ -0,0 +1,4 @@ +float4 main() : SV_Target +{ + return float4(1.5, 0, 1.5, 2.75); +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/float4_construct.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/float4_construct.fx new file mode 100644 index 0000000..6cbb811 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/float4_construct.fx @@ -0,0 +1,19 @@ +struct PS_OUT +{ + float4 color : SV_Target; + float4 color1 : SV_Target1; + float4 color2 : SV_Target2; + float4 color3 : SV_Target3; +}; + +PS_OUT main(float4 texcoord : TEXCOORD) +{ + PS_OUT o; + + o.color = texcoord; + o.color1 = float4(texcoord.xyz, 0); + o.color2 = float4(texcoord.xy, 0, 1); + o.color3 = float4(texcoord.x, 0, 1, 2); + + return o; +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/float4_construct2.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/float4_construct2.fx new file mode 100644 index 0000000..2f6452e --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/float4_construct2.fx @@ -0,0 +1,25 @@ +struct PS_IN +{ + float2 texcoord : TEXCOORD; + float4 texcoord1 : TEXCOORD1; +}; + +struct PS_OUT +{ + float4 color : SV_Target; + float4 color1 : SV_Target1; + float4 color2 : SV_Target2; + float4 color3 : SV_Target3; +}; + +PS_OUT main(PS_IN i) +{ + PS_OUT o; + + o.color = float4(i.texcoord.x, 0, 1, i.texcoord.y); + o.color1 = float4(0, 1, i.texcoord); + o.color2 = float4(0, 1, 2, i.texcoord.x); + o.color3 = float4(i.texcoord, i.texcoord1.zw); + + return o; +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/multiply_negate.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/multiply_negate.fx new file mode 100644 index 0000000..3bcb7ac --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/multiply_negate.fx @@ -0,0 +1,4 @@ +float4 main(float3 texcoord : TEXCOORD) : SV_Target +{ + return float4(-abs(texcoord.y * texcoord.x * texcoord.z), texcoord.y * texcoord.x * texcoord.z, 1, 2); +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/multiply_subtract.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/multiply_subtract.fx new file mode 100644 index 0000000..baf00a8 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/multiply_subtract.fx @@ -0,0 +1,4 @@ +float4 main(float4 texcoord : TEXCOORD) : SV_Target +{ + return float4(3, 2 * texcoord.xy - 1, abs(texcoord.w)); +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/negate_absolute.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/negate_absolute.fx new file mode 100644 index 0000000..6e18e74 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/negate_absolute.fx @@ -0,0 +1,4 @@ +float4 main(float3 texcoord : TEXCOORD) : SV_Target +{ + return float4(-abs(texcoord.z), texcoord.x, 1, 2); +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/sample_2d.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/sample_2d.fx new file mode 100644 index 0000000..c244bc0 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/sample_2d.fx @@ -0,0 +1,7 @@ +Texture2D texture0; +SamplerState samplerState0; + +float4 main(float2 texcoord : TEXCOORD) : SV_Target +{ + return texture0.Sample(samplerState0, texcoord); +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/sample_2d_swizzle.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/sample_2d_swizzle.fx new file mode 100644 index 0000000..d37c7ff --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/sample_2d_swizzle.fx @@ -0,0 +1,7 @@ +Texture2D texture0; +SamplerState samplerState0; + +float4 main(float2 texcoord : TEXCOORD) : SV_Target +{ + return texture0.Sample(samplerState0, 2 * texcoord.yx).wzyx; +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/sample_2d_two_samplers.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/sample_2d_two_samplers.fx new file mode 100644 index 0000000..403af5a --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/sample_2d_two_samplers.fx @@ -0,0 +1,8 @@ +Texture2D texture0; +SamplerState samplerState0; +SamplerState samplerState1; + +float4 main(float2 texcoord : TEXCOORD) : SV_Target +{ + return texture0.Sample(samplerState0, 2 * texture0.Sample(samplerState1, texcoord.yx).xy + texcoord.yx).wzyx; +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/texcoord.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/texcoord.fx new file mode 100644 index 0000000..42b01e7 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/texcoord.fx @@ -0,0 +1,4 @@ +float4 main(float4 texcoord : TEXCOORD) : SV_Target +{ + return texcoord; +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/texcoord_modifier.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/texcoord_modifier.fx new file mode 100644 index 0000000..3599772 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/texcoord_modifier.fx @@ -0,0 +1,4 @@ +float4 main(float4 texcoord : TEXCOORD) : SV_Target +{ + return float4(-texcoord.yx, 2, abs(texcoord.w)); +} diff --git a/HlslDecompiler.Tests/ShaderSources/ps_4_0/texcoord_swizzle.fx b/HlslDecompiler.Tests/ShaderSources/ps_4_0/texcoord_swizzle.fx new file mode 100644 index 0000000..4dbc2aa --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/ps_4_0/texcoord_swizzle.fx @@ -0,0 +1,4 @@ +float4 main(float3 texcoord : TEXCOORD) : SV_Target +{ + return float4(texcoord.yzx, 3); +} diff --git a/HlslDecompiler.Tests/ShaderSources/vs_constant.fx b/HlslDecompiler.Tests/ShaderSources/vs_3_0/constant.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/vs_constant.fx rename to HlslDecompiler.Tests/ShaderSources/vs_3_0/constant.fx diff --git a/HlslDecompiler.Tests/ShaderSources/vs_constant_struct.fx b/HlslDecompiler.Tests/ShaderSources/vs_3_0/constant_struct.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/vs_constant_struct.fx rename to HlslDecompiler.Tests/ShaderSources/vs_3_0/constant_struct.fx diff --git a/HlslDecompiler.Tests/ShaderSources/vs_dot_product.fx b/HlslDecompiler.Tests/ShaderSources/vs_3_0/dot_product.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/vs_dot_product.fx rename to HlslDecompiler.Tests/ShaderSources/vs_3_0/dot_product.fx diff --git a/HlslDecompiler.Tests/ShaderSources/vs_length.fx b/HlslDecompiler.Tests/ShaderSources/vs_3_0/length.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/vs_length.fx rename to HlslDecompiler.Tests/ShaderSources/vs_3_0/length.fx diff --git a/HlslDecompiler.Tests/ShaderSources/vs_matrix22_vector2_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_3_0/matrix22_vector2_multiply.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/vs_matrix22_vector2_multiply.fx rename to HlslDecompiler.Tests/ShaderSources/vs_3_0/matrix22_vector2_multiply.fx diff --git a/HlslDecompiler.Tests/ShaderSources/vs_matrix23_vector2_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_3_0/matrix23_vector2_multiply.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/vs_matrix23_vector2_multiply.fx rename to HlslDecompiler.Tests/ShaderSources/vs_3_0/matrix23_vector2_multiply.fx diff --git a/HlslDecompiler.Tests/ShaderSources/vs_matrix33_vector3_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_3_0/matrix33_vector3_multiply.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/vs_matrix33_vector3_multiply.fx rename to HlslDecompiler.Tests/ShaderSources/vs_3_0/matrix33_vector3_multiply.fx diff --git a/HlslDecompiler.Tests/ShaderSources/vs_matrix44_vector4_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_3_0/matrix44_vector4_multiply.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/vs_matrix44_vector4_multiply.fx rename to HlslDecompiler.Tests/ShaderSources/vs_3_0/matrix44_vector4_multiply.fx diff --git a/HlslDecompiler.Tests/ShaderSources/vs_normalize.fx b/HlslDecompiler.Tests/ShaderSources/vs_3_0/normalize.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/vs_normalize.fx rename to HlslDecompiler.Tests/ShaderSources/vs_3_0/normalize.fx diff --git a/HlslDecompiler.Tests/ShaderSources/vs_submatrix43_vector3_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_3_0/submatrix43_vector3_multiply.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/vs_submatrix43_vector3_multiply.fx rename to HlslDecompiler.Tests/ShaderSources/vs_3_0/submatrix43_vector3_multiply.fx diff --git a/HlslDecompiler.Tests/ShaderSources/vs_vector2_matrix22_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_3_0/vector2_matrix22_multiply.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/vs_vector2_matrix22_multiply.fx rename to HlslDecompiler.Tests/ShaderSources/vs_3_0/vector2_matrix22_multiply.fx diff --git a/HlslDecompiler.Tests/ShaderSources/vs_vector2_matrix32_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_3_0/vector2_matrix32_multiply.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/vs_vector2_matrix32_multiply.fx rename to HlslDecompiler.Tests/ShaderSources/vs_3_0/vector2_matrix32_multiply.fx diff --git a/HlslDecompiler.Tests/ShaderSources/vs_vector3_matrix33_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_3_0/vector3_matrix33_multiply.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/vs_vector3_matrix33_multiply.fx rename to HlslDecompiler.Tests/ShaderSources/vs_3_0/vector3_matrix33_multiply.fx diff --git a/HlslDecompiler.Tests/ShaderSources/vs_vector4_matrix44_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_3_0/vector4_matrix44_multiply.fx similarity index 100% rename from HlslDecompiler.Tests/ShaderSources/vs_vector4_matrix44_multiply.fx rename to HlslDecompiler.Tests/ShaderSources/vs_3_0/vector4_matrix44_multiply.fx diff --git a/HlslDecompiler.Tests/ShaderSources/vs_4_0/constant.fx b/HlslDecompiler.Tests/ShaderSources/vs_4_0/constant.fx new file mode 100644 index 0000000..a05a4a9 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/vs_4_0/constant.fx @@ -0,0 +1,4 @@ +float4 main() : POSITION +{ + return 0; +} diff --git a/HlslDecompiler.Tests/ShaderSources/vs_4_0/constant_struct.fx b/HlslDecompiler.Tests/ShaderSources/vs_4_0/constant_struct.fx new file mode 100644 index 0000000..5a4508c --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/vs_4_0/constant_struct.fx @@ -0,0 +1,19 @@ +struct VS_OUT +{ + float4 position : POSITION; + float4 position1 : POSITION1; + float3 position2 : POSITION2; + float3 position3 : POSITION3; +}; + +VS_OUT main() +{ + VS_OUT o; + + o.position = 0; + o.position1 = 0; + o.position2 = 0; + o.position3 = 0; + + return o; +} diff --git a/HlslDecompiler.Tests/ShaderSources/vs_4_0/dot_product.fx b/HlslDecompiler.Tests/ShaderSources/vs_4_0/dot_product.fx new file mode 100644 index 0000000..1147eea --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/vs_4_0/dot_product.fx @@ -0,0 +1,15 @@ +float2 constant2; +float3 constant3; +float4 constant4; + +struct VS_IN +{ + float4 position : POSITION; + float4 texcoord : TEXCOORD; + float4 texcoord1 : TEXCOORD1; +}; + +float4 main(VS_IN i) : POSITION +{ + return float4(dot(constant4, i.position), dot(constant3, i.texcoord.xyz), dot(constant2, i.texcoord1.xy), 4); +} diff --git a/HlslDecompiler.Tests/ShaderSources/vs_4_0/length.fx b/HlslDecompiler.Tests/ShaderSources/vs_4_0/length.fx new file mode 100644 index 0000000..2ca11fa --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/vs_4_0/length.fx @@ -0,0 +1,11 @@ +struct VS_IN +{ + float4 position : POSITION; + float4 position1 : POSITION1; + float4 position2 : POSITION2; +}; + +float4 main(VS_IN i) : POSITION +{ + return float4(length(i.position), length(i.position1.xyz), -length(i.position2.xy), -5 * length(2 + i.position2)); +} diff --git a/HlslDecompiler.Tests/ShaderSources/vs_4_0/matrix22_vector2_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_4_0/matrix22_vector2_multiply.fx new file mode 100644 index 0000000..246b486 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/vs_4_0/matrix22_vector2_multiply.fx @@ -0,0 +1,19 @@ +float2x2 matrix_2x2; + +struct VS_OUT +{ + float4 position : POSITION; + float2 position1 : POSITION1; + float2 position2 : POSITION2; +}; + +VS_OUT main(float4 position : POSITION) +{ + VS_OUT o; + + o.position = float4(mul(matrix_2x2, position.xy), mul(matrix_2x2, position.yx)); + o.position1 = mul(matrix_2x2, abs(position.yx)); + o.position2 = mul(matrix_2x2, 2 * position.xy); + + return o; +} diff --git a/HlslDecompiler.Tests/ShaderSources/vs_4_0/matrix23_vector2_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_4_0/matrix23_vector2_multiply.fx new file mode 100644 index 0000000..84ec1b2 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/vs_4_0/matrix23_vector2_multiply.fx @@ -0,0 +1,19 @@ +float2x3 matrix_2x3; + +struct VS_OUT +{ + float4 position : POSITION; + float2 position1 : POSITION1; + float2 position2 : POSITION2; +}; + +VS_OUT main(float4 position : POSITION) +{ + VS_OUT o; + + o.position = float4(mul(matrix_2x3, position.xy), mul(matrix_2x3, position.yx)); + o.position1 = mul(matrix_2x3, abs(position.yx)); + o.position2 = mul(matrix_2x3, 2 * position.xy); + + return o; +} diff --git a/HlslDecompiler.Tests/ShaderSources/vs_4_0/matrix33_vector3_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_4_0/matrix33_vector3_multiply.fx new file mode 100644 index 0000000..3971732 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/vs_4_0/matrix33_vector3_multiply.fx @@ -0,0 +1,21 @@ +float3x3 matrix_3x3; + +struct VS_OUT +{ + float4 position : POSITION; + float3 position1 : POSITION1; + float3 position2 : POSITION2; + float3 position3 : POSITION3; +}; + +VS_OUT main(float4 position : POSITION) +{ + VS_OUT o; + + o.position = float4(mul(matrix_3x3, position.xyz), 1); + o.position1 = mul(matrix_3x3, position.yxz); + o.position2 = mul(matrix_3x3, abs(position.yxz)); + o.position3 = mul(matrix_3x3, float3(2 * position.x, position.y, 3 * position.z)); + + return o; +} diff --git a/HlslDecompiler.Tests/ShaderSources/vs_4_0/matrix44_vector4_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_4_0/matrix44_vector4_multiply.fx new file mode 100644 index 0000000..2aa60f9 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/vs_4_0/matrix44_vector4_multiply.fx @@ -0,0 +1,21 @@ +float4x4 matrix_4x4; + +struct VS_OUT +{ + float4 position : POSITION; + float4 position1 : POSITION1; + float4 position2 : POSITION2; + float4 position3 : POSITION3; +}; + +VS_OUT main(float4 position : POSITION) +{ + VS_OUT o; + + o.position = mul(matrix_4x4, position); + o.position1 = mul(matrix_4x4, position.yxzw); + o.position2 = mul(matrix_4x4, abs(position.yxzw)); + o.position3 = mul(matrix_4x4, float4(5, 2, 3, 4) * position); + + return o; +} diff --git a/HlslDecompiler.Tests/ShaderSources/vs_4_0/normalize.fx b/HlslDecompiler.Tests/ShaderSources/vs_4_0/normalize.fx new file mode 100644 index 0000000..2940213 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/vs_4_0/normalize.fx @@ -0,0 +1,4 @@ +float4 main(float4 position : POSITION) : POSITION +{ + return float4(normalize(position.yxz), 1); +} diff --git a/HlslDecompiler.Tests/ShaderSources/vs_4_0/submatrix43_vector3_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_4_0/submatrix43_vector3_multiply.fx new file mode 100644 index 0000000..e05e1db --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/vs_4_0/submatrix43_vector3_multiply.fx @@ -0,0 +1,6 @@ +float4x4 matrix_4x4; + +float4 main(float4 position : POSITION) : POSITION +{ + return mul((float4x3)matrix_4x4, position.xyz); +} diff --git a/HlslDecompiler.Tests/ShaderSources/vs_4_0/vector2_matrix22_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_4_0/vector2_matrix22_multiply.fx new file mode 100644 index 0000000..4845d4c --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/vs_4_0/vector2_matrix22_multiply.fx @@ -0,0 +1,19 @@ +float2x2 matrix_2x2; + +struct VS_OUT +{ + float4 position : POSITION; + float2 position1 : POSITION1; + float2 position2 : POSITION2; +}; + +VS_OUT main(float4 position : POSITION) +{ + VS_OUT o; + + o.position = float4(mul(position.xy, matrix_2x2), mul(position.yx, matrix_2x2)); + o.position1 = mul(abs(position.yx), matrix_2x2); + o.position2 = mul(2 * position.xy, matrix_2x2); + + return o; +} diff --git a/HlslDecompiler.Tests/ShaderSources/vs_4_0/vector2_matrix32_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_4_0/vector2_matrix32_multiply.fx new file mode 100644 index 0000000..5daa918 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/vs_4_0/vector2_matrix32_multiply.fx @@ -0,0 +1,19 @@ +float3x2 matrix_3x2; + +struct VS_OUT +{ + float4 position : POSITION; + float2 position1 : POSITION1; + float2 position2 : POSITION2; +}; + +VS_OUT main(float4 position : POSITION) +{ + VS_OUT o; + + o.position = float4(mul(position.xy, matrix_3x2), mul(position.yx, matrix_3x2)); + o.position1 = mul(abs(position.yx), matrix_3x2); + o.position2 = mul(2 * position.xy, matrix_3x2); + + return o; +} diff --git a/HlslDecompiler.Tests/ShaderSources/vs_4_0/vector3_matrix33_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_4_0/vector3_matrix33_multiply.fx new file mode 100644 index 0000000..9c14e6d --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/vs_4_0/vector3_matrix33_multiply.fx @@ -0,0 +1,21 @@ +float3x3 matrix_3x3; + +struct VS_OUT +{ + float4 position : POSITION; + float3 position1 : POSITION1; + float3 position2 : POSITION2; + float3 position3 : POSITION3; +}; + +VS_OUT main(float4 position : POSITION) +{ + VS_OUT o; + + o.position = float4(mul(position.xyz, matrix_3x3), 1); + o.position1 = mul(position.yxz, matrix_3x3); + o.position2 = mul(abs(position.yxz), matrix_3x3); + o.position3 = mul(float3(position.y, float2(2, 3) * position.xz), matrix_3x3); + + return o; +} diff --git a/HlslDecompiler.Tests/ShaderSources/vs_4_0/vector4_matrix44_multiply.fx b/HlslDecompiler.Tests/ShaderSources/vs_4_0/vector4_matrix44_multiply.fx new file mode 100644 index 0000000..d8e93b4 --- /dev/null +++ b/HlslDecompiler.Tests/ShaderSources/vs_4_0/vector4_matrix44_multiply.fx @@ -0,0 +1,21 @@ +float4x4 matrix_4x4; + +struct VS_OUT +{ + float4 position : POSITION; + float4 position1 : POSITION1; + float4 position2 : POSITION2; + float4 position3 : POSITION3; +}; + +VS_OUT main(float4 position : POSITION) +{ + VS_OUT o; + + o.position = mul(position, matrix_4x4); + o.position1 = mul(position.yxzw, matrix_4x4); + o.position2 = mul(abs(position.yxzw), matrix_4x4); + o.position3 = mul(float4(5, 2, 3, 4) * position, matrix_4x4); + + return o; +} diff --git a/HlslDecompiler.csproj b/HlslDecompiler.csproj index 35c3966..4e343bd 100644 --- a/HlslDecompiler.csproj +++ b/HlslDecompiler.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net6.0 diff --git a/Program.cs b/Program.cs index e06aacc..7cdc52f 100644 --- a/Program.cs +++ b/Program.cs @@ -23,7 +23,7 @@ static void Main(string[] args) var format = FormatDetector.Detect(inputStream); switch (format) { - case ShaderFileFormat.ShaderModel: + case ShaderFileFormat.ShaderModel3: ReadShaderModel(baseFilename, inputStream, options.DoAstAnalysis); break; case ShaderFileFormat.Rgxa: diff --git a/Util/FourCC.cs b/Util/FourCC.cs index eec1895..c0be0e5 100644 --- a/Util/FourCC.cs +++ b/Util/FourCC.cs @@ -1,4 +1,5 @@ using System; +using System.Text; namespace HlslDecompiler.Util { @@ -12,5 +13,15 @@ public static int Make(string id) } return (id[3]) + (id[2] << 8) + (id[1] << 16) + (id[0] << 24); } + + public static String Decode(int code) + { + byte[] bytes = BitConverter.GetBytes(code); + if (!BitConverter.IsLittleEndian) + { + Array.Reverse(bytes); + } + return Encoding.ASCII.GetString(bytes); + } } }