- Fixed a small bug in the hlsl parser

- Further work on the shader generation
- Started working on shader loading in the RenderSystem
This commit is contained in:
SND\AstrorEnales_cp 2012-08-16 16:44:35 +00:00
parent 44b03c5be6
commit 1662fbeef1
15 changed files with 449 additions and 243 deletions

View File

@ -65,18 +65,35 @@
<Compile Include="Graphics\Dxt3BitmapContent.cs" />
<Compile Include="Graphics\Dxt5BitmapContent.cs" />
<Compile Include="Graphics\EffectMaterialContent.cs" />
<Compile Include="Graphics\EnvironmentMapMaterialContent.cs" />
<Compile Include="Graphics\FontDescription.cs" />
<Compile Include="Graphics\FontDescriptionStyle.cs" />
<Compile Include="Graphics\GeometryContent.cs" />
<Compile Include="Graphics\GeometryContentCollection.cs" />
<Compile Include="Graphics\IndexCollection.cs" />
<Compile Include="Graphics\IndirectPositionCollection.cs" />
<Compile Include="Graphics\MaterialContent.cs" />
<Compile Include="Graphics\MeshBuilder.cs" />
<Compile Include="Graphics\MeshContent.cs" />
<Compile Include="Graphics\MeshHelper.cs" />
<Compile Include="Graphics\MipmapChain.cs" />
<Compile Include="Graphics\MipmapChainCollection.cs" />
<Compile Include="Graphics\NodeContent.cs" />
<Compile Include="Graphics\NodeContentCollection.cs" />
<Compile Include="Graphics\PixelBitmapContent.cs" />
<Compile Include="Graphics\PositionCollection.cs" />
<Compile Include="Graphics\TextureContent.cs" />
<Compile Include="Graphics\TextureReferenceDictionary.cs" />
<Compile Include="Graphics\VertexChannel.cs" />
<Compile Include="Graphics\VertexChannelCollection.cs" />
<Compile Include="Graphics\VertexContent.cs" />
<Compile Include="IContentImporter.cs" />
<Compile Include="IContentProcessor.cs" />
<Compile Include="NamedValueDictionary.cs" />
<Compile Include="OpaqueDataDictionary.cs" />
<Compile Include="Processors\CompiledEffectContent.cs" />
<Compile Include="Processors\VertexBufferContent.cs" />
<Compile Include="Processors\VertexDeclarationContent.cs" />
<Compile Include="Serialization\Compiler\BuiltInTypeWriter.cs" />
<Compile Include="Serialization\Compiler\ContentCompiler.cs" />
<Compile Include="Serialization\Compiler\ContentTypeWriter.cs" />

View File

@ -65,18 +65,35 @@
<Compile Include="Graphics\Dxt3BitmapContent.cs" />
<Compile Include="Graphics\Dxt5BitmapContent.cs" />
<Compile Include="Graphics\EffectMaterialContent.cs" />
<Compile Include="Graphics\EnvironmentMapMaterialContent.cs" />
<Compile Include="Graphics\FontDescription.cs" />
<Compile Include="Graphics\FontDescriptionStyle.cs" />
<Compile Include="Graphics\GeometryContent.cs" />
<Compile Include="Graphics\GeometryContentCollection.cs" />
<Compile Include="Graphics\IndexCollection.cs" />
<Compile Include="Graphics\IndirectPositionCollection.cs" />
<Compile Include="Graphics\MaterialContent.cs" />
<Compile Include="Graphics\MeshBuilder.cs" />
<Compile Include="Graphics\MeshContent.cs" />
<Compile Include="Graphics\MeshHelper.cs" />
<Compile Include="Graphics\MipmapChain.cs" />
<Compile Include="Graphics\MipmapChainCollection.cs" />
<Compile Include="Graphics\NodeContent.cs" />
<Compile Include="Graphics\NodeContentCollection.cs" />
<Compile Include="Graphics\PixelBitmapContent.cs" />
<Compile Include="Graphics\PositionCollection.cs" />
<Compile Include="Graphics\TextureContent.cs" />
<Compile Include="Graphics\TextureReferenceDictionary.cs" />
<Compile Include="Graphics\VertexChannel.cs" />
<Compile Include="Graphics\VertexChannelCollection.cs" />
<Compile Include="Graphics\VertexContent.cs" />
<Compile Include="IContentImporter.cs" />
<Compile Include="IContentProcessor.cs" />
<Compile Include="NamedValueDictionary.cs" />
<Compile Include="OpaqueDataDictionary.cs" />
<Compile Include="Processors\CompiledEffectContent.cs" />
<Compile Include="Processors\VertexBufferContent.cs" />
<Compile Include="Processors\VertexDeclarationContent.cs" />
<Compile Include="Serialization\Compiler\BuiltInTypeWriter.cs" />
<Compile Include="Serialization\Compiler\ContentCompiler.cs" />
<Compile Include="Serialization\Compiler\ContentTypeWriter.cs" />

View File

@ -67,18 +67,35 @@
<Compile Include="Graphics\Dxt3BitmapContent.cs" />
<Compile Include="Graphics\Dxt5BitmapContent.cs" />
<Compile Include="Graphics\EffectMaterialContent.cs" />
<Compile Include="Graphics\EnvironmentMapMaterialContent.cs" />
<Compile Include="Graphics\FontDescription.cs" />
<Compile Include="Graphics\FontDescriptionStyle.cs" />
<Compile Include="Graphics\GeometryContent.cs" />
<Compile Include="Graphics\GeometryContentCollection.cs" />
<Compile Include="Graphics\IndexCollection.cs" />
<Compile Include="Graphics\IndirectPositionCollection.cs" />
<Compile Include="Graphics\MaterialContent.cs" />
<Compile Include="Graphics\MeshBuilder.cs" />
<Compile Include="Graphics\MeshContent.cs" />
<Compile Include="Graphics\MeshHelper.cs" />
<Compile Include="Graphics\MipmapChain.cs" />
<Compile Include="Graphics\MipmapChainCollection.cs" />
<Compile Include="Graphics\NodeContent.cs" />
<Compile Include="Graphics\NodeContentCollection.cs" />
<Compile Include="Graphics\PixelBitmapContent.cs" />
<Compile Include="Graphics\PositionCollection.cs" />
<Compile Include="Graphics\TextureContent.cs" />
<Compile Include="Graphics\TextureReferenceDictionary.cs" />
<Compile Include="Graphics\VertexChannel.cs" />
<Compile Include="Graphics\VertexChannelCollection.cs" />
<Compile Include="Graphics\VertexContent.cs" />
<Compile Include="IContentImporter.cs" />
<Compile Include="IContentProcessor.cs" />
<Compile Include="NamedValueDictionary.cs" />
<Compile Include="OpaqueDataDictionary.cs" />
<Compile Include="Processors\CompiledEffectContent.cs" />
<Compile Include="Processors\VertexBufferContent.cs" />
<Compile Include="Processors\VertexDeclarationContent.cs" />
<Compile Include="Serialization\Compiler\BuiltInTypeWriter.cs" />
<Compile Include="Serialization\Compiler\ContentCompiler.cs" />
<Compile Include="Serialization\Compiler\ContentTypeWriter.cs" />

View File

@ -11,19 +11,20 @@ namespace ANX.RenderSystem.Windows.Metro
{
public class EffectParameter_Metro : INativeEffectParameter
{
//private EffectVariable nativeEffectVariable;
private ExtendedShaderParameter nativeParameter;
//public EffectVariable NativeParameter
//{
// get
// {
// return this.nativeEffectVariable;
// }
// internal set
// {
// this.nativeEffectVariable = value;
// }
//}
public string Name
{
get
{
return nativeParameter.Name;
}
}
public EffectParameter_Metro(ExtendedShaderParameter setNativeParameter)
{
nativeParameter = setNativeParameter;
}
public void SetValue(bool value)
{
@ -166,15 +167,6 @@ namespace ANX.RenderSystem.Windows.Metro
throw new NotImplementedException();
}
public string Name
{
get
{
//return nativeEffectVariable.Description.Name;
throw new NotImplementedException();
}
}
#region INativeEffectParameter Member

View File

@ -1,5 +1,7 @@
using System;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA;
using Dx11 = SharpDX.Direct3D11;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
@ -9,27 +11,64 @@ namespace ANX.RenderSystem.Windows.Metro
{
public class EffectPass_Metro : INativeEffectPass
{
//private EffectPass nativePass;
//public EffectPass NativePass
//{
// get
// {
// return this.nativePass;
// }
// internal set
// {
// this.nativePass = value;
// }
//}
#region Private
private ExtendedShaderPass nativePass;
private Effect parentEffect;
private Dx11.VertexShader vertexShader;
private Dx11.PixelShader pixelShader;
#endregion
#region Public
public string Name
{
get;
private set;
}
public EffectPass Pass
{
get;
private set;
}
public Dx11.VertexShader VertexShader
{
get
{
//return nativePass.Description.Name;
throw new NotImplementedException();
if (vertexShader == null)
{
vertexShader = new Dx11.VertexShader(
NativeDxDevice.Current.NativeDevice, nativePass.VertexCode);
}
return vertexShader;
}
}
public Dx11.PixelShader PixelShader
{
get
{
if (pixelShader == null)
{
pixelShader = new Dx11.PixelShader(
NativeDxDevice.Current.NativeDevice, nativePass.PixelCode);
}
return pixelShader;
}
}
#endregion
#region Constructor
public EffectPass_Metro(Effect setParentEffect, ExtendedShaderPass setNativePass)
{
Name = setNativePass.Name;
nativePass = setNativePass;
parentEffect = setParentEffect;
Pass = new EffectPass(parentEffect);
}
#endregion
}
}

View File

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA;
@ -11,59 +10,50 @@ namespace ANX.RenderSystem.Windows.Metro
{
public class EffectTechnique_Metro : INativeEffectTechnique
{
//private EffectTechnique nativeTechnique;
private ANX.Framework.Graphics.Effect parentEffect;
//internal EffectTechnique_DX10(ANX.Framework.Graphics.Effect parentEffect)
//{
// if (parentEffect == null)
// {
// throw new ArgumentNullException("parentEffect");
// }
// this.parentEffect = parentEffect;
//}
//public EffectTechnique NativeTechnique
//{
// get
// {
// return this.nativeTechnique;
// }
// internal set
// {
// this.nativeTechnique = value;
// }
//}
#region Private
private Effect parentEffect;
private List<EffectPass_Metro> passes;
#endregion
#region Public
public string Name
{
get
{
//return nativeTechnique.Description.Name;
throw new NotImplementedException();
}
get;
private set;
}
public IEnumerable<EffectPass> Passes
{
get
{
//TODO: implement
System.Diagnostics.Debugger.Break();
return null;
//for (int i = 0; i < nativeTechnique.Description.PassCount; i++)
//{
// EffectPass_DX10 passDx10 = new EffectPass_DX10();
// passDx10.NativePass = nativeTechnique.GetPassByIndex(i);
// Graphics.EffectPass pass = new Graphics.EffectPass(this.parentEffect);
// yield return pass;
//}
foreach (EffectPass_Metro pass in passes)
{
yield return pass.Pass;
}
}
}
#endregion
#region Constructor
public EffectTechnique_Metro(string setName, Effect setParentEffect,
ExtendedShaderPass[] nativePasses)
{
Name = setName;
parentEffect = setParentEffect;
ParsePasses(nativePasses);
}
#endregion
#region ParsePasses
private void ParsePasses(ExtendedShaderPass[] nativePasses)
{
passes = new List<EffectPass_Metro>();
foreach (ExtendedShaderPass pass in nativePasses)
{
passes.Add(new EffectPass_Metro(parentEffect, pass));
}
}
#endregion
}
}

View File

@ -15,6 +15,11 @@ namespace ANX.RenderSystem.Windows.Metro
{
#region Private
private Effect managedEffect;
private List<EffectTechnique> techniques;
private List<EffectParameter> parameters;
private ExtendedShader shader;
#endregion
#region Public
@ -34,16 +39,12 @@ namespace ANX.RenderSystem.Windows.Metro
{
get
{
throw new NotImplementedException();
//for (int i = 0; i < nativeEffect.Description.TechniqueCount; i++)
//{
// EffectTechnique_DX10 teqDx10 = new EffectTechnique_DX10(this.managedEffect);
// teqDx10.NativeTechnique = nativeEffect.GetTechniqueByIndex(i);
if (techniques == null)
{
ParseTechniques();
}
// Graphics.EffectTechnique teq = new Graphics.EffectTechnique(this.managedEffect, teqDx10);
// yield return teq;
//}
return techniques;
}
}
@ -51,22 +52,12 @@ namespace ANX.RenderSystem.Windows.Metro
{
get
{
//TODO: implement
System.Diagnostics.Debugger.Break();
if (parameters == null)
{
ParseParameters();
}
return null;
//for (int i = 0; i < nativeEffect.Description.GlobalVariableCount; i++)
//{
// EffectParameter_Metro parDx10 = new EffectParameter_Metro();
// parDx10.NativeParameter = nativeEffect.GetVariableByIndex(i);
// Graphics.EffectParameter par = new Graphics.EffectParameter();
// par.NativeParameter = parDx10;
// yield return par;
//}
return parameters;
}
}
#endregion
@ -77,29 +68,47 @@ namespace ANX.RenderSystem.Windows.Metro
{
this.managedEffect = managedEffect;
byte[] vertexData = SeekIfPossibleAndReadBytes(vertexShaderByteCode);
throw new NotImplementedException();
/*byte[] vertexData = SeekIfPossibleAndReadBytes(vertexShaderByteCode);
NativeVertexShader = new Dx11.VertexShader((Dx11.Device)device.NativeDevice, vertexData);
byte[] pixelData = SeekIfPossibleAndReadBytes(pixelShaderByteCode);
NativePixelShader = new Dx11.PixelShader((Dx11.Device)device.NativeDevice, pixelData);
NativePixelShader = new Dx11.PixelShader((Dx11.Device)device.NativeDevice, pixelData);*/
}
public Effect_Metro(GraphicsDevice device, Effect managedEffect, Stream effectByteCode)
{
this.managedEffect = managedEffect;
if (effectByteCode.CanSeek)
{
effectByteCode.Seek(0, SeekOrigin.Begin);
}
// TODO
/*
byte[] vertexData = SeekIfPossibleAndReadBytes(vertexShaderByteCode);
vertexShader = new Dx11.VertexShader((Dx11.Device)device.NativeDevice, vertexData);
shader = new ExtendedShader(effectByteCode);
}
#endregion
byte[] pixelData = SeekIfPossibleAndReadBytes(pixelShaderByteCode);
pixelShader = new Dx11.PixelShader((Dx11.Device)device.NativeDevice, pixelData);
*/
#region ParseTechniques
private void ParseTechniques()
{
techniques = new List<EffectTechnique>();
foreach (string key in shader.Techniques.Keys)
{
var nativeTechnique = new EffectTechnique_Metro(key, managedEffect, shader.Techniques[key]);
techniques.Add(new EffectTechnique(managedEffect, nativeTechnique));
}
}
#endregion
#region ParseParameters
private void ParseParameters()
{
parameters = new List<EffectParameter>();
foreach (ExtendedShaderParameter parameter in shader.Parameters)
{
EffectParameter newParam = new EffectParameter();
newParam.NativeParameter = new EffectParameter_Metro(parameter);
parameters.Add(newParam);
}
}
#endregion
@ -144,4 +153,79 @@ namespace ANX.RenderSystem.Windows.Metro
}
#endregion
}
public class ExtendedShader
{
public Dictionary<string, ExtendedShaderPass[]> Techniques;
public List<ExtendedShaderParameter> Parameters;
public ExtendedShader(Stream stream)
{
Techniques = new Dictionary<string, ExtendedShaderPass[]>();
Parameters = new List<ExtendedShaderParameter>();
BinaryReader reader = new BinaryReader(stream);
int numberOfVariables = reader.ReadInt32();
for (int index = 0; index < numberOfVariables; index++)
{
Parameters.Add(new ExtendedShaderParameter(reader));
}
int numberOfStructures = reader.ReadInt32();
for (int index = 0; index < numberOfStructures; index++)
{
string name = reader.ReadString();
int numberOfStructVariables = reader.ReadInt32();
for (int varIndex = 0; varIndex < numberOfStructVariables; varIndex++)
{
string varType = reader.ReadString();
string varName = reader.ReadString();
string varSemantic = reader.ReadString();
}
}
int numberOfTechniques = reader.ReadInt32();
for (int index = 0; index < numberOfTechniques; index++)
{
string name = reader.ReadString();
int numberOfPasses = reader.ReadInt32();
ExtendedShaderPass[] passes = new ExtendedShaderPass[numberOfPasses];
Techniques.Add(name, passes);
for (int passIndex = 0; passIndex < numberOfPasses; passIndex++)
{
passes[passIndex] = new ExtendedShaderPass(reader);
}
}
}
}
public class ExtendedShaderParameter
{
public string Type;
public string Name;
public ExtendedShaderParameter(BinaryReader reader)
{
Type = reader.ReadString();
Name = reader.ReadString();
}
}
public class ExtendedShaderPass
{
public string Name;
public byte[] VertexCode;
public byte[] PixelCode;
public ExtendedShaderPass(BinaryReader reader)
{
Name = reader.ReadString();
int vertexCodeLength = reader.ReadInt32();
VertexCode = reader.ReadBytes(vertexCodeLength);
int pixelCodeLength = reader.ReadInt32();
PixelCode = reader.ReadBytes(pixelCodeLength);
}
}
}

View File

@ -102,7 +102,6 @@ namespace ANX.RenderSystem.Windows.Metro
UpdateNativeSamplerState();
bound = true;
throw new NotImplementedException();
//device.PixelShader.SetSampler(index, this.nativeSamplerState);
}
#endregion
@ -129,8 +128,8 @@ namespace ANX.RenderSystem.Windows.Metro
nativeSamplerState = null;
}
nativeSamplerState = new Dx11.SamplerState(
NativeDxDevice.Current.NativeDevice, ref description);
//nativeSamplerState = new Dx11.SamplerState(
// NativeDxDevice.Current.NativeDevice, ref description);
isDirty = false;
}

View File

@ -26,112 +26,113 @@ namespace ANX.RenderSystem.Windows.Metro
097, 116, 003, 099, 111, 108, 005, 067, 079, 076, 079, 082, 005, 102, 108,
111, 097, 116, 003, 116, 101, 120, 009, 084, 069, 088, 067, 079, 079, 082,
068, 048, 001, 000, 000, 000, 015, 083, 112, 114, 105, 116, 101, 084, 101,
099, 104, 110, 105, 113, 117, 101, 001, 000, 000, 000, 128, 003, 000, 000,
068, 088, 066, 067, 093, 023, 212, 206, 149, 008, 160, 173, 236, 209, 184,
180, 025, 147, 008, 113, 001, 000, 000, 000, 128, 003, 000, 000, 005, 000,
000, 000, 052, 000, 000, 000, 008, 001, 000, 000, 120, 001, 000, 000, 236,
001, 000, 000, 004, 003, 000, 000, 082, 068, 069, 070, 204, 000, 000, 000,
001, 000, 000, 000, 072, 000, 000, 000, 001, 000, 000, 000, 028, 000, 000,
000, 000, 004, 254, 255, 000, 001, 000, 000, 152, 000, 000, 000, 060, 000,
099, 104, 110, 105, 113, 117, 101, 001, 000, 000, 000, 015, 083, 112, 114,
105, 116, 101, 067, 111, 108, 111, 114, 080, 097, 115, 115, 124, 003, 000,
000, 068, 088, 066, 067, 023, 003, 238, 120, 110, 149, 199, 207, 012, 120,
215, 169, 211, 034, 204, 247, 001, 000, 000, 000, 124, 003, 000, 000, 005,
000, 000, 000, 052, 000, 000, 000, 004, 001, 000, 000, 116, 001, 000, 000,
232, 001, 000, 000, 000, 003, 000, 000, 082, 068, 069, 070, 200, 000, 000,
000, 001, 000, 000, 000, 072, 000, 000, 000, 001, 000, 000, 000, 028, 000,
000, 000, 000, 004, 254, 255, 000, 001, 000, 000, 152, 000, 000, 000, 060,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000,
036, 071, 108, 111, 098, 097, 108, 115, 000, 171, 171, 171, 060, 000, 000,
000, 001, 000, 000, 000, 096, 000, 000, 000, 064, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 120, 000, 000, 000, 000, 000, 000, 000, 064,
000, 000, 000, 002, 000, 000, 000, 136, 000, 000, 000, 000, 000, 000, 000,
077, 097, 116, 114, 105, 120, 084, 114, 097, 110, 115, 102, 111, 114, 109,
000, 003, 000, 003, 000, 004, 000, 004, 000, 000, 000, 000, 000, 000, 000,
000, 000, 077, 105, 099, 114, 111, 115, 111, 102, 116, 032, 040, 082, 041,
032, 072, 076, 083, 076, 032, 083, 104, 097, 100, 101, 114, 032, 067, 111,
109, 112, 105, 108, 101, 114, 032, 057, 046, 050, 057, 046, 057, 053, 050,
046, 051, 049, 049, 049, 000, 171, 171, 171, 073, 083, 071, 078, 104, 000,
000, 000, 003, 000, 000, 000, 008, 000, 000, 000, 080, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 003, 000, 000, 000, 000, 000, 000, 000,
015, 015, 000, 000, 089, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 003, 000, 000, 000, 001, 000, 000, 000, 015, 015, 000, 000, 095, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 003, 000, 000, 000, 002,
000, 000, 000, 003, 003, 000, 000, 080, 079, 083, 073, 084, 073, 079, 078,
000, 067, 079, 076, 079, 082, 000, 084, 069, 088, 067, 079, 079, 082, 068,
000, 079, 083, 071, 078, 108, 000, 000, 000, 003, 000, 000, 000, 008, 000,
000, 000, 080, 000, 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 003,
000, 000, 000, 000, 000, 000, 000, 015, 000, 000, 000, 092, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 003, 000, 000, 000, 001, 000, 000,
000, 015, 000, 000, 000, 098, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 003, 000, 000, 000, 002, 000, 000, 000, 003, 012, 000, 000, 083,
086, 095, 080, 079, 083, 073, 084, 073, 079, 078, 000, 067, 079, 076, 079,
082, 000, 084, 069, 088, 067, 079, 079, 082, 068, 000, 171, 083, 072, 068,
082, 016, 001, 000, 000, 064, 000, 001, 000, 068, 000, 000, 000, 089, 000,
000, 004, 070, 142, 032, 000, 000, 000, 000, 000, 004, 000, 000, 000, 095,
000, 000, 003, 242, 016, 016, 000, 000, 000, 000, 000, 095, 000, 000, 003,
242, 016, 016, 000, 001, 000, 000, 000, 095, 000, 000, 003, 050, 016, 016,
000, 002, 000, 000, 000, 103, 000, 000, 004, 242, 032, 016, 000, 000, 000,
000, 000, 001, 000, 000, 000, 101, 000, 000, 003, 242, 032, 016, 000, 001,
000, 000, 000, 101, 000, 000, 003, 050, 032, 016, 000, 002, 000, 000, 000,
017, 000, 000, 008, 018, 032, 016, 000, 000, 000, 000, 000, 070, 030, 016,
000, 000, 000, 000, 000, 070, 142, 032, 000, 000, 000, 000, 000, 000, 000,
000, 000, 017, 000, 000, 008, 034, 032, 016, 000, 000, 000, 000, 000, 070,
030, 016, 000, 000, 000, 000, 000, 070, 142, 032, 000, 000, 000, 000, 000,
001, 000, 000, 000, 017, 000, 000, 008, 066, 032, 016, 000, 000, 000, 000,
000, 070, 030, 016, 000, 000, 000, 000, 000, 070, 142, 032, 000, 000, 000,
000, 000, 002, 000, 000, 000, 017, 000, 000, 008, 130, 032, 016, 000, 000,
000, 000, 000, 070, 030, 016, 000, 000, 000, 000, 000, 070, 142, 032, 000,
000, 000, 000, 000, 003, 000, 000, 000, 054, 000, 000, 005, 242, 032, 016,
000, 001, 000, 000, 000, 070, 030, 016, 000, 001, 000, 000, 000, 054, 000,
000, 005, 050, 032, 016, 000, 002, 000, 000, 000, 070, 016, 016, 000, 002,
000, 000, 000, 062, 000, 000, 001, 083, 084, 065, 084, 116, 000, 000, 000,
007, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 006, 000, 000,
000, 004, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001, 000,
000, 000, 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 000, 000, 000,
000, 036, 071, 108, 111, 098, 097, 108, 115, 000, 171, 171, 171, 060, 000,
000, 000, 001, 000, 000, 000, 096, 000, 000, 000, 064, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 120, 000, 000, 000, 000, 000, 000, 000,
064, 000, 000, 000, 002, 000, 000, 000, 136, 000, 000, 000, 000, 000, 000,
000, 077, 097, 116, 114, 105, 120, 084, 114, 097, 110, 115, 102, 111, 114,
109, 000, 003, 000, 003, 000, 004, 000, 004, 000, 000, 000, 000, 000, 000,
000, 000, 000, 077, 105, 099, 114, 111, 115, 111, 102, 116, 032, 040, 082,
041, 032, 072, 076, 083, 076, 032, 083, 104, 097, 100, 101, 114, 032, 067,
111, 109, 112, 105, 108, 101, 114, 032, 057, 046, 051, 048, 046, 056, 052,
048, 048, 046, 048, 000, 171, 073, 083, 071, 078, 104, 000, 000, 000, 003,
000, 000, 000, 008, 000, 000, 000, 080, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 003, 000, 000, 000, 000, 000, 000, 000, 015, 015, 000,
000, 089, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 003, 000,
000, 000, 001, 000, 000, 000, 015, 015, 000, 000, 095, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 003, 000, 000, 000, 002, 000, 000, 000,
003, 003, 000, 000, 080, 079, 083, 073, 084, 073, 079, 078, 000, 067, 079,
076, 079, 082, 000, 084, 069, 088, 067, 079, 079, 082, 068, 000, 079, 083,
071, 078, 108, 000, 000, 000, 003, 000, 000, 000, 008, 000, 000, 000, 080,
000, 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 003, 000, 000, 000,
000, 000, 000, 000, 015, 000, 000, 000, 092, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 003, 000, 000, 000, 001, 000, 000, 000, 015, 000,
000, 000, 098, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 003,
000, 000, 000, 002, 000, 000, 000, 003, 012, 000, 000, 083, 086, 095, 080,
079, 083, 073, 084, 073, 079, 078, 000, 067, 079, 076, 079, 082, 000, 084,
069, 088, 067, 079, 079, 082, 068, 000, 171, 083, 072, 068, 082, 016, 001,
000, 000, 064, 000, 001, 000, 068, 000, 000, 000, 089, 000, 000, 004, 070,
142, 032, 000, 000, 000, 000, 000, 004, 000, 000, 000, 095, 000, 000, 003,
242, 016, 016, 000, 000, 000, 000, 000, 095, 000, 000, 003, 242, 016, 016,
000, 001, 000, 000, 000, 095, 000, 000, 003, 050, 016, 016, 000, 002, 000,
000, 000, 103, 000, 000, 004, 242, 032, 016, 000, 000, 000, 000, 000, 001,
000, 000, 000, 101, 000, 000, 003, 242, 032, 016, 000, 001, 000, 000, 000,
101, 000, 000, 003, 050, 032, 016, 000, 002, 000, 000, 000, 017, 000, 000,
008, 018, 032, 016, 000, 000, 000, 000, 000, 070, 030, 016, 000, 000, 000,
000, 000, 070, 142, 032, 000, 000, 000, 000, 000, 000, 000, 000, 000, 017,
000, 000, 008, 034, 032, 016, 000, 000, 000, 000, 000, 070, 030, 016, 000,
000, 000, 000, 000, 070, 142, 032, 000, 000, 000, 000, 000, 001, 000, 000,
000, 017, 000, 000, 008, 066, 032, 016, 000, 000, 000, 000, 000, 070, 030,
016, 000, 000, 000, 000, 000, 070, 142, 032, 000, 000, 000, 000, 000, 002,
000, 000, 000, 017, 000, 000, 008, 130, 032, 016, 000, 000, 000, 000, 000,
070, 030, 016, 000, 000, 000, 000, 000, 070, 142, 032, 000, 000, 000, 000,
000, 003, 000, 000, 000, 054, 000, 000, 005, 242, 032, 016, 000, 001, 000,
000, 000, 070, 030, 016, 000, 001, 000, 000, 000, 054, 000, 000, 005, 050,
032, 016, 000, 002, 000, 000, 000, 070, 016, 016, 000, 002, 000, 000, 000,
062, 000, 000, 001, 083, 084, 065, 084, 116, 000, 000, 000, 007, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 006, 000, 000, 000, 004, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 002, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 160, 002, 000, 000,
068, 088, 066, 067, 029, 076, 118, 093, 197, 015, 041, 178, 119, 144, 245,
077, 096, 029, 105, 032, 001, 000, 000, 000, 160, 002, 000, 000, 005, 000,
000, 000, 052, 000, 000, 000, 224, 000, 000, 000, 084, 001, 000, 000, 136,
001, 000, 000, 036, 002, 000, 000, 082, 068, 069, 070, 164, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 002, 000, 000, 000, 028, 000, 000,
000, 000, 004, 255, 255, 000, 001, 000, 000, 115, 000, 000, 000, 092, 000,
000, 000, 003, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 001, 000, 000, 000,
107, 000, 000, 000, 002, 000, 000, 000, 005, 000, 000, 000, 004, 000, 000,
000, 255, 255, 255, 255, 000, 000, 000, 000, 001, 000, 000, 000, 013, 000,
000, 000, 084, 101, 120, 116, 117, 114, 101, 083, 097, 109, 112, 108, 101,
114, 000, 084, 101, 120, 116, 117, 114, 101, 000, 077, 105, 099, 114, 111,
115, 111, 102, 116, 032, 040, 082, 041, 032, 072, 076, 083, 076, 032, 083,
104, 097, 100, 101, 114, 032, 067, 111, 109, 112, 105, 108, 101, 114, 032,
057, 046, 050, 057, 046, 057, 053, 050, 046, 051, 049, 049, 049, 000, 073,
083, 071, 078, 108, 000, 000, 000, 003, 000, 000, 000, 008, 000, 000, 000,
080, 000, 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 003, 000, 000,
000, 000, 000, 000, 000, 015, 000, 000, 000, 092, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 003, 000, 000, 000, 001, 000, 000, 000, 015,
015, 000, 000, 098, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
003, 000, 000, 000, 002, 000, 000, 000, 003, 003, 000, 000, 083, 086, 095,
080, 079, 083, 073, 084, 073, 079, 078, 000, 067, 079, 076, 079, 082, 000,
084, 069, 088, 067, 079, 079, 082, 068, 000, 171, 079, 083, 071, 078, 044,
000, 000, 000, 001, 000, 000, 000, 008, 000, 000, 000, 032, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 003, 000, 000, 000, 000, 000, 000,
000, 015, 000, 000, 000, 083, 086, 095, 084, 097, 114, 103, 101, 116, 000,
171, 171, 083, 072, 068, 082, 148, 000, 000, 000, 064, 000, 000, 000, 037,
000, 000, 000, 090, 000, 000, 003, 000, 096, 016, 000, 000, 000, 000, 000,
088, 024, 000, 004, 000, 112, 016, 000, 000, 000, 000, 000, 085, 085, 000,
000, 098, 016, 000, 003, 242, 016, 016, 000, 001, 000, 000, 000, 098, 016,
000, 003, 050, 016, 016, 000, 002, 000, 000, 000, 101, 000, 000, 003, 242,
032, 016, 000, 000, 000, 000, 000, 104, 000, 000, 002, 001, 000, 000, 000,
069, 000, 000, 009, 242, 000, 016, 000, 000, 000, 000, 000, 070, 016, 016,
000, 002, 000, 000, 000, 070, 126, 016, 000, 000, 000, 000, 000, 000, 096,
016, 000, 000, 000, 000, 000, 056, 000, 000, 007, 242, 032, 016, 000, 000,
000, 000, 000, 070, 014, 016, 000, 000, 000, 000, 000, 070, 030, 016, 000,
001, 000, 000, 000, 062, 000, 000, 001, 083, 084, 065, 084, 116, 000, 000,
000, 003, 000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 003, 000,
000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 003, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 160, 002, 000, 000, 068, 088, 066,
067, 186, 056, 226, 083, 225, 174, 177, 036, 122, 188, 068, 240, 068, 118,
201, 132, 001, 000, 000, 000, 160, 002, 000, 000, 005, 000, 000, 000, 052,
000, 000, 000, 224, 000, 000, 000, 084, 001, 000, 000, 136, 001, 000, 000,
036, 002, 000, 000, 082, 068, 069, 070, 164, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 002, 000, 000, 000, 028, 000, 000, 000, 000, 004,
255, 255, 000, 001, 000, 000, 115, 000, 000, 000, 092, 000, 000, 000, 003,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000
000, 000, 000, 000, 001, 000, 000, 000, 001, 000, 000, 000, 107, 000, 000,
000, 002, 000, 000, 000, 005, 000, 000, 000, 004, 000, 000, 000, 255, 255,
255, 255, 000, 000, 000, 000, 001, 000, 000, 000, 013, 000, 000, 000, 084,
101, 120, 116, 117, 114, 101, 083, 097, 109, 112, 108, 101, 114, 000, 084,
101, 120, 116, 117, 114, 101, 000, 077, 105, 099, 114, 111, 115, 111, 102,
116, 032, 040, 082, 041, 032, 072, 076, 083, 076, 032, 083, 104, 097, 100,
101, 114, 032, 067, 111, 109, 112, 105, 108, 101, 114, 032, 057, 046, 051,
048, 046, 056, 052, 048, 048, 046, 048, 000, 171, 171, 073, 083, 071, 078,
108, 000, 000, 000, 003, 000, 000, 000, 008, 000, 000, 000, 080, 000, 000,
000, 000, 000, 000, 000, 001, 000, 000, 000, 003, 000, 000, 000, 000, 000,
000, 000, 015, 000, 000, 000, 092, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 003, 000, 000, 000, 001, 000, 000, 000, 015, 015, 000, 000,
098, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 003, 000, 000,
000, 002, 000, 000, 000, 003, 003, 000, 000, 083, 086, 095, 080, 079, 083,
073, 084, 073, 079, 078, 000, 067, 079, 076, 079, 082, 000, 084, 069, 088,
067, 079, 079, 082, 068, 000, 171, 079, 083, 071, 078, 044, 000, 000, 000,
001, 000, 000, 000, 008, 000, 000, 000, 032, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 003, 000, 000, 000, 000, 000, 000, 000, 015, 000,
000, 000, 083, 086, 095, 084, 097, 114, 103, 101, 116, 000, 171, 171, 083,
072, 068, 082, 148, 000, 000, 000, 064, 000, 000, 000, 037, 000, 000, 000,
090, 000, 000, 003, 000, 096, 016, 000, 000, 000, 000, 000, 088, 024, 000,
004, 000, 112, 016, 000, 000, 000, 000, 000, 085, 085, 000, 000, 098, 016,
000, 003, 242, 016, 016, 000, 001, 000, 000, 000, 098, 016, 000, 003, 050,
016, 016, 000, 002, 000, 000, 000, 101, 000, 000, 003, 242, 032, 016, 000,
000, 000, 000, 000, 104, 000, 000, 002, 001, 000, 000, 000, 069, 000, 000,
009, 242, 000, 016, 000, 000, 000, 000, 000, 070, 016, 016, 000, 002, 000,
000, 000, 070, 126, 016, 000, 000, 000, 000, 000, 000, 096, 016, 000, 000,
000, 000, 000, 056, 000, 000, 007, 242, 032, 016, 000, 000, 000, 000, 000,
070, 014, 016, 000, 000, 000, 000, 000, 070, 030, 016, 000, 001, 000, 000,
000, 062, 000, 000, 001, 083, 084, 065, 084, 116, 000, 000, 000, 003, 000,
000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 003, 000, 000, 000, 001,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 001, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000
};
#endregion //SpriteBatchShader

View File

@ -213,7 +213,8 @@ namespace ANX.RenderSystem.Windows.Metro
formatSize = (surfaceFormat == SurfaceFormat.Dxt1) ? 8 : 16;
int subresource = Dx11.Texture2D.CalculateSubResourceIndex(0, 0, 1);
SharpDX.DataBox rectangle = context.MapSubresource(this.nativeTexture, subresource, Dx11.MapMode.WriteDiscard, Dx11.MapFlags.None);
SharpDX.DataBox rectangle =
NativeDxDevice.Current.MapSubresource(nativeTexture, subresource);
SharpDX.DataStream ds = new SharpDX.DataStream(rectangle.DataPointer, Width * Height * 4 * 2, true, true);
int pitch = rectangle.RowPitch;
int col = 0;
@ -248,7 +249,7 @@ namespace ANX.RenderSystem.Windows.Metro
handle.Free();
context.UnmapSubresource(this.nativeTexture, subresource);
NativeDxDevice.Current.UnmapSubresource(nativeTexture, subresource);
}
}
else

View File

@ -8,6 +8,12 @@ namespace DX11MetroShaderGenerator
{
public class CompiledPass
{
public string Name
{
get;
private set;
}
public byte[] VertexShaderCode
{
get;
@ -20,8 +26,10 @@ namespace DX11MetroShaderGenerator
private set;
}
public CompiledPass(byte[] setVertexShaderCode, byte[] setPixelShaderCode)
public CompiledPass(string setName,
byte[] setVertexShaderCode, byte[] setPixelShaderCode)
{
Name = setName;
VertexShaderCode = setVertexShaderCode;
PixelShaderCode = setPixelShaderCode;
}

View File

@ -36,7 +36,7 @@
<HintPath>..\..\lib\SharpDX\Bin\Standard-net20\SharpDX.dll</HintPath>
</Reference>
<Reference Include="SharpDX.D3DCompiler">
<HintPath>..\..\lib\SharpDX\Bin\Standard-net20\SharpDX.D3DCompiler.dll</HintPath>
<HintPath>..\..\lib\SharpDX\Bin\Win8Desktop-net20\SharpDX.D3DCompiler.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using HLSLParser;
using SharpDX.D3DCompiler;
@ -98,7 +99,7 @@ namespace DX11MetroShaderGenerator
byte[] vertexCode = CompileShader(pass.VertexShaderProfile, pass.VertexShader);
byte[] pixelCode = CompileShader(pass.PixelShaderProfile, pass.PixelShader);
return new CompiledPass(vertexCode, pixelCode);
return new CompiledPass(pass.Name, vertexCode, pixelCode);
}
#endregion
@ -108,13 +109,15 @@ namespace DX11MetroShaderGenerator
int indexOfOpenParenthesis = entryPoint.IndexOf('(');
entryPoint = entryPoint.Substring(0, indexOfOpenParenthesis);
ShaderBytecode byteCode = ShaderBytecode.Compile(resultSourceCode,
/*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 result;*/
return Execute(resultSourceCode, profile, entryPoint);
}
#endregion
@ -175,6 +178,7 @@ namespace DX11MetroShaderGenerator
writer.Write(passes.Length);
foreach (CompiledPass pass in passes)
{
writer.Write(pass.Name);
writer.Write(pass.VertexShaderCode.Length);
writer.Write(pass.VertexShaderCode);
writer.Write(pass.PixelShaderCode.Length);
@ -183,5 +187,50 @@ namespace DX11MetroShaderGenerator
}
}
#endregion
private byte[] Execute(string source, string profile, string entryPoint)
{
string tempSourcePath = Path.GetTempFileName() + ".fx";
string tempDestPath = Path.GetTempFileName() + ".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 + " \"" +
tempSourcePath + "\" /Fo" + tempDestPath;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
string output = "";
DataReceivedEventHandler handler = delegate(object sender, DataReceivedEventArgs e)
{
if (String.IsNullOrEmpty(e.Data) == false)
{
output += e.Data + "\n";
}
};
process.OutputDataReceived += handler;
process.ErrorDataReceived += handler;
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.WaitForExit();
if (File.Exists(tempSourcePath))
{
File.Delete(tempSourcePath);
}
if (File.Exists(tempDestPath))
{
byte[] result = File.ReadAllBytes(tempDestPath);
File.Delete(tempDestPath);
return result;
}
return new byte[0];
}
}
}

View File

@ -91,7 +91,10 @@ namespace HLSLParser
string text = walker.Text;
if (text.StartsWith(":"))
{
int lengthBeforeCut = text.Length;
text = text.Substring(1).TrimStart(' ', '\t');
int cutLength = lengthBeforeCut - text.Length;
Register = "";
int registerParseIndex = 0;
while (registerParseIndex < text.Length)
@ -111,7 +114,7 @@ namespace HLSLParser
Register = Register.Trim(' ', '\t', '\n', '\r');
walker.Seek(registerParseIndex);
walker.Seek(registerParseIndex + cutLength);
}
}
#endregion
@ -121,20 +124,10 @@ namespace HLSLParser
{
string text = walker.Text;
int searchStatesStartIndex = 0;
while (searchStatesStartIndex < text.Length)
{
char currentChar = text[searchStatesStartIndex];
if (currentChar == ';')
return;
if (text[0] == ';')
return;
if (currentChar == '{')
break;
searchStatesStartIndex++;
}
walker.Seek(searchStatesStartIndex + 1);
walker.Seek(1);
text = walker.Text;

View File

@ -22,8 +22,7 @@ namespace StockShaderCodeGenerator
{
Console.WriteLine("No command line arguments provided. Trying to load build.xml from current directory.");
//buildFile = "build.xml";
buildFile = @"D:\code\csharp\ANX.Framework\shader\Metro\build.xml";
buildFile = "build.xml";
}
else
{