- Fixed a small issue in variable parsing with Textures

- Removed the sharpdx references from the Metro shader generator
- Added a basic path searching to the metro shader generator to find the correct path to the fxc tool
This commit is contained in:
SND\AstrorEnales_cp 2012-08-17 14:25:59 +00:00
parent 2f635020a8
commit 96d6ad095e
11 changed files with 180 additions and 161 deletions

View File

@ -1,10 +1,4 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#endregion
using System;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
@ -12,22 +6,23 @@ using System.Text;
namespace ANX.Framework.Content.Pipeline.Graphics
{
public sealed class GeometryContentCollection : ChildCollection<MeshContent, GeometryContent>
{
protected GeometryContentCollection(MeshContent parent)
: base(parent)
{
throw new NotImplementedException();
}
public sealed class GeometryContentCollection
: ChildCollection<MeshContent, GeometryContent>
{
protected GeometryContentCollection(MeshContent parent)
: base(parent)
{
throw new NotImplementedException();
}
protected override MeshContent GetParent(GeometryContent child)
{
throw new NotImplementedException();
}
protected override MeshContent GetParent(GeometryContent child)
{
return child.Parent;
}
protected override void SetParent(GeometryContent child, MeshContent parent)
{
throw new NotImplementedException();
}
}
protected override void SetParent(GeometryContent child, MeshContent parent)
{
child.Parent = parent;
}
}
}

View File

@ -1,27 +1,30 @@
#region Using Statements
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
#endregion
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.Content.Pipeline.Graphics
{
public sealed class IndexCollection : Collection<int>
{
public IndexCollection()
{
}
public sealed class IndexCollection : Collection<int>
{
public IndexCollection()
{
}
public void AddRange(IEnumerable<int> indices)
{
throw new NotImplementedException();
}
}
public void AddRange(IEnumerable<int> indices)
{
if (indices == null)
{
throw new ArgumentNullException("indices");
}
foreach (int index in indices)
{
Items.Add(index);
}
}
}
}

View File

@ -1,5 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<AppDesignerFolder>Properties</AppDesignerFolder>
<OutputType>Library</OutputType>
<FileAlignment>512</FileAlignment>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</ProjectGuid>
<RootNamespace>ANX.Framework</RootNamespace>
<AssemblyName>ANX.Framework</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
@ -19,18 +31,6 @@
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<AppDesignerFolder>Properties</AppDesignerFolder>
<OutputType>Library</OutputType>
<FileAlignment>512</FileAlignment>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</ProjectGuid>
<RootNamespace>ANX.Framework</RootNamespace>
<AssemblyName>ANX.Framework</AssemblyName>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>

View File

@ -1,5 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<AppDesignerFolder>Properties</AppDesignerFolder>
<OutputType>Library</OutputType>
<FileAlignment>512</FileAlignment>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</ProjectGuid>
<RootNamespace>ANX.Framework</RootNamespace>
<AssemblyName>ANX.Framework</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
@ -19,18 +31,6 @@
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<AppDesignerFolder>Properties</AppDesignerFolder>
<OutputType>Library</OutputType>
<FileAlignment>512</FileAlignment>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</ProjectGuid>
<RootNamespace>ANX.Framework</RootNamespace>
<AssemblyName>ANX.Framework</AssemblyName>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>

View File

@ -1,5 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<AppDesignerFolder>Properties</AppDesignerFolder>
<OutputType>Library</OutputType>
<FileAlignment>512</FileAlignment>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</ProjectGuid>
<RootNamespace>ANX.Framework</RootNamespace>
<AssemblyName>ANX.Framework</AssemblyName>
<ProjectTypeGuids>{69878862-DA7D-4DC6-B0A1-50D8FAB4242F};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
@ -19,19 +32,6 @@
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<AppDesignerFolder>Properties</AppDesignerFolder>
<OutputType>Library</OutputType>
<FileAlignment>512</FileAlignment>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</ProjectGuid>
<RootNamespace>ANX.Framework</RootNamespace>
<AssemblyName>ANX.Framework</AssemblyName>
<ProjectTypeGuids>{69878862-DA7D-4DC6-B0A1-50D8FAB4242F};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>

View File

@ -1,5 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<AppDesignerFolder>Properties</AppDesignerFolder>
<OutputType>Library</OutputType>
<FileAlignment>512</FileAlignment>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</ProjectGuid>
<RootNamespace>ANX.Framework</RootNamespace>
<AssemblyName>ANX.Framework</AssemblyName>
<ProjectTypeGuids>{BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<DefaultLanguage>en-US</DefaultLanguage>
<PackageCertificateKeyFile>Test_TemporaryKey.pfx</PackageCertificateKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
@ -19,21 +34,6 @@
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<AppDesignerFolder>Properties</AppDesignerFolder>
<OutputType>Library</OutputType>
<FileAlignment>512</FileAlignment>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</ProjectGuid>
<RootNamespace>ANX.Framework</RootNamespace>
<AssemblyName>ANX.Framework</AssemblyName>
<ProjectTypeGuids>{BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<DefaultLanguage>en-US</DefaultLanguage>
<PackageCertificateKeyFile>Test_TemporaryKey.pfx</PackageCertificateKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>

View File

@ -31,19 +31,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="SharpDX, Version=2.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\SharpDX\Bin\Standard-net20\SharpDX.dll</HintPath>
</Reference>
<Reference Include="SharpDX.D3DCompiler">
<HintPath>..\..\lib\SharpDX\Bin\Win8Desktop-net20\SharpDX.D3DCompiler.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="MetroCodeGenerator.cs" />
<Compile Include="CompiledPass.cs" />
<Compile Include="IncludeHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>

View File

@ -1,41 +0,0 @@
using System;
using System.IO;
using SharpDX.D3DCompiler;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace DX11MetroShaderGenerator
{
internal class IncludeHandler : Include
{
private string directory;
public IncludeHandler(string directory)
{
this.directory = directory;
}
public void Close(Stream stream)
{
stream.Close();
}
public Stream Open(IncludeType type, string fileName, Stream parentStream)
{
return File.OpenRead(Path.Combine(directory, fileName));
}
public IDisposable Shadow
{
get;
set;
}
public void Dispose()
{
throw new NotImplementedException();
}
}
}

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using HLSLParser;
using SharpDX.D3DCompiler;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
@ -108,16 +107,8 @@ namespace DX11MetroShaderGenerator
{
int indexOfOpenParenthesis = entryPoint.IndexOf('(');
entryPoint = entryPoint.Substring(0, indexOfOpenParenthesis);
/*ShaderBytecode byteCode = ShaderBytecode.Compile(resultSourceCode,
entryPoint, profile, ShaderFlags.None, EffectFlags.None,
null, new IncludeHandler(""));
byte[] result = new byte[byteCode.BufferSize];
byteCode.Data.Read(result, 0, result.Length);
return result;*/
return Execute(resultSourceCode, profile, entryPoint);
return ExecuteCompiler(resultSourceCode, profile, entryPoint);
}
#endregion
@ -188,31 +179,35 @@ namespace DX11MetroShaderGenerator
}
#endregion
private byte[] Execute(string source, string profile, string entryPoint)
#region ExecuteCompiler
private byte[] ExecuteCompiler(string source, string profile, string entryPoint)
{
string tempSourcePath = Path.GetTempFileName() + ".fx";
string tempDestPath = Path.GetTempFileName() + "_" + profile + ".fxo";
File.WriteAllText(tempSourcePath, source);
Process process = new Process();
process.StartInfo.FileName = @"C:\Program Files (x86)\Windows Kits\8.0\bin\x86\fxc.exe";
process.StartInfo.Arguments = "/E" + entryPoint + " /T" + profile + "_level_9_1 \"" +
tempSourcePath + "\" /Fo" + tempDestPath;
process.StartInfo.FileName = GetCompilerFilepath();
process.StartInfo.Arguments = "/E" + entryPoint + " /T" + profile +
"_level_9_1 \"" + tempSourcePath + "\" /Fo" + tempDestPath;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
string output = "";
DataReceivedEventHandler handler = delegate(object sender, DataReceivedEventArgs e)
DataReceivedEventHandler logHandler =
delegate(object sender, DataReceivedEventArgs e)
{
if (String.IsNullOrEmpty(e.Data) == false)
{
output += e.Data + "\n";
}
};
process.OutputDataReceived += handler;
process.ErrorDataReceived += handler;
process.OutputDataReceived += logHandler;
process.ErrorDataReceived += logHandler;
process.Start();
process.BeginErrorReadLine();
@ -232,5 +227,67 @@ namespace DX11MetroShaderGenerator
return new byte[0];
}
#endregion
#region GetCompilerFilepath
private string GetCompilerFilepath()
{
string fxcToolPath = "";
string subDir = Environment.Is64BitOperatingSystem ? "x64" : "x86";
string sdkPath = Environment.GetEnvironmentVariable("DXSDK_DIR");
if (String.IsNullOrEmpty(sdkPath) == false)
{
fxcToolPath = Path.Combine(sdkPath, subDir);
}
else
{
fxcToolPath = GetExistingPathFrom(new string[]
{
// Win8 paths
@"C:\Program Files (x86)\Windows Kits\8.0\bin\" + subDir + "\\",
@"C:\Program Files\Windows Kits\8.0\bin\" + subDir + "\\",
// Win7 paths
@"C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Utilities\bin\" +
subDir + "\\",
@"C:\Program Files\Microsoft DirectX SDK (June 2010)\Utilities\bin\" +
subDir + "\\",
});
if (String.IsNullOrEmpty(fxcToolPath))
{
throw new Exception(
"Unable to find the DirectX SDK! Make sure to install it.");
}
}
fxcToolPath = Path.Combine(fxcToolPath, "fxc.exe");
if (File.Exists(fxcToolPath) == false)
{
throw new Exception(
"Unable to compile shaders, cause the fxc.exe doesn't exist!");
}
return fxcToolPath;
}
#endregion
#region GetExistingPathFrom
private string GetExistingPathFrom(string[] possiblePaths)
{
foreach (string path in possiblePaths)
{
if (Directory.Exists(path))
{
return path;
}
}
return null;
}
#endregion
}
}

View File

@ -151,6 +151,7 @@ namespace HLSLParser
int nextSpaceIndex = FindInitialTypeEndSpace(currentText);
string variableType = currentText.Substring(0, nextSpaceIndex);
variableType = variableType.Replace(" ", "");
walker.Seek(nextSpaceIndex + 1);
variableType = ResolveMatrixAndArraySyntax(variableType);
@ -167,6 +168,18 @@ namespace HLSLParser
{
searchScope = text.IndexOf('>');
}
else if (text.StartsWith("Texture") ||
text.StartsWith("texture"))
{
string textureGeneric = text;
textureGeneric = textureGeneric.Substring(textureGeneric.IndexOf(' '));
textureGeneric = textureGeneric.Trim();
if (textureGeneric.StartsWith("<"))
{
searchScope = text.IndexOf('>');
}
}
return text.IndexOf(' ', searchScope);
}
#endregion

View File

@ -114,14 +114,14 @@ Texture2D<float4> Texture : register(t0);";
[Test]
public static void TestParseIfVariableWithGenericTexture2D()
{
string variableSource = "Texture2D<float4> Texture : register(t0);";
string variableSource = "Texture2D <float4> Texture : register(t0);";
var text = new ParseTextWalker(variableSource);
var result = Variable.TryParse(text);
Assert.NotNull(result);
Assert.AreEqual("Texture2D<float4>", result.Type);
Assert.AreEqual("Texture", result.Name);
Assert.AreEqual("register(t0)", result.Register);
Assert.AreEqual(variableSource, result.ToString());
Assert.AreEqual("Texture2D<float4> Texture : register(t0);", result.ToString());
}
#endregion