Added UIX.RenderApi

This commit is contained in:
Joshua Askharoun
2022-03-03 08:40:19 -06:00
parent 86c3d1ed19
commit ab33f58c69
456 changed files with 45568 additions and 5 deletions
@@ -0,0 +1,47 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.AncestorEnumerator
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using System.Collections;
namespace Microsoft.Iris.Render.Graphics
{
internal struct AncestorEnumerator : IEnumerator, IEnumerable
{
private TreeNode m_nodeStart;
private TreeNode m_nodeCurrent;
private TreeNode m_nodeNext;
internal AncestorEnumerator(TreeNode nodeStart)
{
this.m_nodeStart = nodeStart;
this.m_nodeCurrent = null;
this.m_nodeNext = this.m_nodeStart;
}
object IEnumerator.Current => m_nodeCurrent;
public TreeNode Current => this.m_nodeCurrent;
IEnumerator IEnumerable.GetEnumerator() => this;
public AncestorEnumerator GetEnumerator() => this;
public void Reset()
{
this.m_nodeCurrent = null;
this.m_nodeNext = this.m_nodeStart;
}
public bool MoveNext()
{
this.m_nodeCurrent = this.m_nodeNext;
if (this.m_nodeNext == null)
return false;
this.m_nodeNext = this.m_nodeNext.Parent;
return true;
}
}
}
@@ -0,0 +1,185 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Camera
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Render.Animation;
using Microsoft.Iris.Render.Common;
using Microsoft.Iris.Render.Internal;
using Microsoft.Iris.Render.Protocol;
using Microsoft.Iris.Render.Protocols.Splash.Rendering;
using System;
namespace Microsoft.Iris.Render.Graphics
{
internal class Camera :
SharedRenderObject,
ICamera,
IAnimatableObject,
IAnimatable,
ISharedRenderObject,
IRenderHandleOwner
{
public static readonly string EyeProperty = "CameraEye";
public static readonly string AtProperty = "CameraAt";
public static readonly string UpProperty = "CameraUp";
public static readonly string ZnProperty = "CameraZn";
private RenderSession m_session;
private RemoteCamera m_remoteCamera;
private Vector3 m_vEye;
private Vector3 m_vAt;
private Vector3 m_vUp;
private float m_flZn;
private bool m_fPerspective;
internal Camera(RenderSession session)
{
this.m_session = session;
Debug2.Validate(this.m_session != null, typeof(ArgumentNullException), "Must have valid RenderSession");
this.m_session.AssertOwningThread();
this.m_remoteCamera = this.m_session.BuildRemoteCamera(this);
this.SetEye(new Vector3(0.0, 0.0, -4.0));
this.SetAt(new Vector3(0.0, 0.0, 0.0));
this.SetUp(new Vector3(0.0, 1.0, 0.0));
this.SetZn(2f);
this.SetPerspective(true);
}
protected override void Dispose(bool fInDispose)
{
try
{
if (!fInDispose || this.m_remoteCamera == null)
return;
this.m_remoteCamera.Dispose();
this.m_remoteCamera = null;
}
finally
{
base.Dispose(fInDispose);
}
}
RENDERHANDLE IRenderHandleOwner.RenderHandle => this.m_remoteCamera.RenderHandle;
void IRenderHandleOwner.OnDisconnect() => this.m_remoteCamera = null;
internal RemoteCamera RemoteStub => this.m_remoteCamera;
Vector3 ICamera.Eye
{
get => this.m_vEye;
set => this.SetEye(value);
}
Vector3 ICamera.At
{
get => this.m_vAt;
set => this.SetAt(value);
}
Vector3 ICamera.Up
{
get => this.m_vUp;
set => this.SetUp(value);
}
float ICamera.Zn
{
get => this.m_flZn;
set => this.SetZn(value);
}
bool ICamera.Perspective
{
get => this.m_fPerspective;
set => this.SetPerspective(value);
}
private void SetEye(Vector3 vEye)
{
if (!(this.m_vEye != vEye))
return;
this.m_vEye = vEye;
if (!this.m_session.IsValid || !this.m_remoteCamera.IsValid)
return;
this.m_remoteCamera.SendSetEye(vEye);
}
private void SetAt(Vector3 vAt)
{
if (!(this.m_vAt != vAt))
return;
this.m_vAt = vAt;
if (!this.m_session.IsValid || !this.m_remoteCamera.IsValid)
return;
this.m_remoteCamera.SendSetAt(vAt);
}
private void SetUp(Vector3 vUp)
{
if (!(this.m_vUp != vUp))
return;
this.m_vUp = vUp;
if (!this.m_session.IsValid || !this.m_remoteCamera.IsValid)
return;
this.m_remoteCamera.SendSetUp(vUp);
}
private void SetZn(float flZn)
{
if (m_flZn == (double)flZn)
return;
this.m_flZn = flZn;
if (!this.m_session.IsValid || !this.m_remoteCamera.IsValid)
return;
this.m_remoteCamera.SendSetZn(flZn);
}
private void SetPerspective(bool fPerspective)
{
if (this.m_fPerspective == fPerspective)
return;
this.m_fPerspective = fPerspective;
if (!this.m_session.IsValid || !this.m_remoteCamera.IsValid)
return;
this.m_remoteCamera.SendSetPerspective(fPerspective);
}
RENDERHANDLE IAnimatableObject.GetObjectId() => ((IRenderHandleOwner)this).RenderHandle;
uint IAnimatableObject.GetPropertyId(string propertyName)
{
if (propertyName == EyeProperty)
return 1;
if (propertyName == AtProperty)
return 2;
if (propertyName == UpProperty)
return 3;
if (propertyName == ZnProperty)
return 4;
Debug2.Validate(false, typeof(ArgumentException), "Unsupported property");
return 0;
}
AnimationInputType IAnimatableObject.GetPropertyType(
string propertyName)
{
if (propertyName == EyeProperty || propertyName == AtProperty || propertyName == UpProperty)
return AnimationInputType.Vector3;
if (propertyName == ZnProperty)
return AnimationInputType.Float;
Debug2.Validate(false, typeof(ArgumentException), "Unsupported property");
return AnimationInputType.Float;
}
private enum AnimatableProperties : uint
{
Eye = 1,
At = 2,
Up = 3,
Zn = 4,
}
}
}
@@ -0,0 +1,16 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.DataBufferCleanupInfo
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using System;
namespace Microsoft.Iris.Render.Graphics
{
internal class DataBufferCleanupInfo
{
public IntPtr rgConvertData;
public ImageLoadInfo imageLoadInfo;
}
}
@@ -0,0 +1,92 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9BlendElement
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Library;
using Microsoft.Iris.Render.Common;
namespace Microsoft.Iris.Render.Graphics
{
internal class Dx9BlendElement
{
internal static void Generate(
BlendElement efiBlend,
string stBlendOutput1,
string stBlendOutput2,
ref Dx9EffectBuilder effectBuilder)
{
effectBuilder.PixelShaderOutput = effectBuilder.GenerateLocalVariable(Dx9VariableType.Vector4, efiBlend.Name);
string str1 = null;
switch (efiBlend.ColorOperation)
{
case ColorOperation.Add:
str1 = InvariantString.Format(" // Blend the RGB - result\r\n float4 {0};\r\n {0}.rgb = {1}.rgb + {2}.rgb;\r\n", effectBuilder.PixelShaderOutput, stBlendOutput1, stBlendOutput2);
break;
case ColorOperation.Subtract:
str1 = InvariantString.Format(" // Blend the RGB - result\r\n float4 {0};\r\n {0}.rgb = float3(abs({1}.rgb - {2}.rgb));\r\n", effectBuilder.PixelShaderOutput, stBlendOutput1, stBlendOutput2);
break;
case ColorOperation.Multiply:
str1 = InvariantString.Format(" // Blend the RGB result\r\n float4 {0};\r\n {0}.rgb = {1}.rgb * {2}.rgb;\r\n", effectBuilder.PixelShaderOutput, stBlendOutput1, stBlendOutput2);
break;
case ColorOperation.Lighten:
str1 = InvariantString.Format(" // Blend the RGB result\r\n float4 {0};\r\n {0}.rgb = max({1}.rgb, {2}.rgb);\r\n", effectBuilder.PixelShaderOutput, stBlendOutput1, stBlendOutput2);
break;
case ColorOperation.Darken:
str1 = InvariantString.Format(" // Blend the RGB result\r\n float4 {0};\r\n {0}.rgb = min({1}.rgb, {2}.rgb);\r\n", effectBuilder.PixelShaderOutput, stBlendOutput1, stBlendOutput2);
break;
case ColorOperation.ColorDodge:
str1 = InvariantString.Format(" // Blend the RGB result\r\n float4 {0};\r\n {0}.rgb = {1}.rgb / (1 - {2}.rgb);\r\n", effectBuilder.PixelShaderOutput, stBlendOutput1, stBlendOutput2);
break;
case ColorOperation.ColorBurn:
str1 = InvariantString.Format(" // Blend the RGB result\r\n float4 {0};\r\n {0}.rgb = 1 - ((1 - {1}.rgb) / {2}.rgb);\r\n", effectBuilder.PixelShaderOutput, stBlendOutput1, stBlendOutput2);
break;
case ColorOperation.Screen:
str1 = InvariantString.Format(" // Blend the RGB result\r\n float4 {0};\r\n {0}.rgb = 1 - ((1 - {1}.rgb) * (1 - {2}.rgb));\r\n", effectBuilder.PixelShaderOutput, stBlendOutput1, stBlendOutput2);
break;
case ColorOperation.Overlay:
string localVariable1 = effectBuilder.GenerateLocalVariable(Dx9VariableType.Float, "trueClause");
str1 = InvariantString.Format(" // Blend the RGB result\r\n float3 {3} = ceil({1}.rgb - 0.5);\r\n float4 {0};\r\n {0}.rgb = {3}.rgb * (1 - (1 - 2 * ({1}.rgb - 0.5)) * (1 - {2}.rgb)) \r\n + (1 - {3}.rgb) * (2 * {1}.rgb * {2}.rgb);\r\n", effectBuilder.PixelShaderOutput, stBlendOutput1, stBlendOutput2, localVariable1);
break;
case ColorOperation.SoftLight:
string localVariable2 = effectBuilder.GenerateLocalVariable(Dx9VariableType.Float, "trueClause");
str1 = InvariantString.Format(" // Blend the RGB result\r\n float3 {3} = ceil({2}.rgb - 0.5);\r\n float4 {0};\r\n {0}.rgb = {3}.rgb * (1 - (2 * (1 - (({1}.rgb / 2) + 0.25)) * (1 - {2}.rgb)))\r\n + (1 - {3}.rgb) * (2 * ({1}.rgb / 2 + 0.25) * {2}.rgb);\r\n", effectBuilder.PixelShaderOutput, stBlendOutput1, stBlendOutput2, localVariable2);
break;
case ColorOperation.HardLight:
string localVariable3 = effectBuilder.GenerateLocalVariable(Dx9VariableType.Float, "trueClause");
str1 = InvariantString.Format(" // Blend the RGB result\r\n float3 {3} = ceil({2}.rgb - 0.5);\r\n float4 {0};\r\n {0}.rgb = {3}.rgb * (1 - (1 - 2 * ({2}.rgb - 0.5)) * (1 - {1}.rgb)) \r\n + (1 - {3}.rgb) * (2 * {1}.rgb * {2}.rgb);\r\n", effectBuilder.PixelShaderOutput, stBlendOutput1, stBlendOutput2, localVariable3);
break;
case ColorOperation.LinearBurn:
str1 = InvariantString.Format(" // Blend the RGB result\r\n float4 {0};\r\n {0}.rgb = {1}.rgb + {2}.rgb - 1;\r\n", effectBuilder.PixelShaderOutput, stBlendOutput1, stBlendOutput2);
break;
default:
Debug2.Throw(false, "Unknown color blend operation");
break;
}
string str2 = null;
switch (efiBlend.AlphaOperation)
{
case AlphaOperation.Add:
str2 = InvariantString.Format(" // Blend the Alpha result\r\n {0}.a = {1}.a + {2}.a;\r\n\r\n", effectBuilder.PixelShaderOutput, stBlendOutput1, stBlendOutput2);
break;
case AlphaOperation.Subtract:
str2 = InvariantString.Format(" // Blend the Alpha result\r\n {0}.a = {1}.a - {2}.a;\r\n\r\n", effectBuilder.PixelShaderOutput, stBlendOutput1, stBlendOutput2);
break;
case AlphaOperation.Multiply:
str2 = InvariantString.Format(" // Blend the Alpha result\r\n {0}.a = {1}.a * {2}.a;\r\n\r\n", effectBuilder.PixelShaderOutput, stBlendOutput1, stBlendOutput2);
break;
case AlphaOperation.Source1:
str2 = InvariantString.Format(" // Blend the Alpha result\r\n {0}.a = {1}.a;\r\n\r\n", effectBuilder.PixelShaderOutput, stBlendOutput1);
break;
case AlphaOperation.Source2:
str2 = InvariantString.Format(" // Blend the Alpha result\r\n {0}.a = {1}.a;\r\n\r\n", effectBuilder.PixelShaderOutput, stBlendOutput2);
break;
default:
Debug2.Throw(false, "Unknown alpha blend operation");
break;
}
effectBuilder.EmitPixelFragment(str1 + str2);
}
}
}
@@ -0,0 +1,29 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9BrightnessElement
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Library;
namespace Microsoft.Iris.Render.Graphics
{
internal class Dx9BrightnessElement
{
internal static void Generate(
BrightnessElement efoBrightness,
ref Dx9EffectBuilder effectBuilder)
{
VariableInfo variableInfo = new VariableInfo()
{
ID = efoBrightness.BrightnessID,
Type = Dx9VariableType.Float,
IsDynamic = efoBrightness.IsDynamicProperty("Brightness")
};
variableInfo.Name = variableInfo.IsDynamic ? effectBuilder.GenerateGlobalVariable(variableInfo.Type, efoBrightness.Name) : effectBuilder.GenerateGlobalConstant(variableInfo.Type, efoBrightness.Name);
variableInfo.DefaultValue = efoBrightness.Brightness;
effectBuilder.AddPropertyVariable(variableInfo);
effectBuilder.EmitPixelFragment(InvariantString.Format(" {{\r\n // adjust brightness based on input\r\n {0}.rgb += float3({1}, {1}, {1});\r\n }}\r\n", effectBuilder.PixelShaderOutput, variableInfo.Name));
}
}
}
@@ -0,0 +1,29 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9ColorElement
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Library;
namespace Microsoft.Iris.Render.Graphics
{
internal class Dx9ColorElement
{
internal static void Generate(ColorElement efiColor, ref Dx9EffectBuilder effectBuilder)
{
VariableInfo variableInfo = new VariableInfo()
{
ID = efiColor.ColorID,
Type = Dx9VariableType.Vector4,
IsDynamic = efiColor.IsDynamicProperty("Color")
};
variableInfo.Name = variableInfo.IsDynamic ? effectBuilder.GenerateGlobalVariable(variableInfo.Type, efiColor.Name) : effectBuilder.GenerateGlobalConstant(variableInfo.Type, efiColor.Name);
variableInfo.DefaultValue = efiColor.Color.ToVector4();
effectBuilder.AddPropertyVariable(variableInfo);
string name = variableInfo.Name;
effectBuilder.PixelShaderOutput = effectBuilder.GenerateLocalVariable(Dx9VariableType.Vector4, efiColor.Name);
effectBuilder.EmitPixelFragment(InvariantString.Format(" // Load the color\r\n float4 {0} = {1};\r\n\r\n", effectBuilder.PixelShaderOutput, name));
}
}
}
@@ -0,0 +1,67 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9ComplexImageElement
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Library;
namespace Microsoft.Iris.Render.Graphics
{
internal class Dx9ComplexImageElement
{
internal static void Generate(ComplexImageElement efiImage, ref Dx9EffectBuilder effectBuilder)
{
VariableInfo variableInfo1 = new VariableInfo()
{
ID = efiImage.MinFilterID,
Type = Dx9VariableType.Integer,
IsDynamic = efiImage.IsDynamicProperty("MinFilter")
};
variableInfo1.Name = variableInfo1.IsDynamic ? effectBuilder.GenerateGlobalVariable(variableInfo1.Type, efiImage.Name + "MinFilter") : effectBuilder.GenerateGlobalConstant(variableInfo1.Type, efiImage.Name + "MinFilter");
variableInfo1.DefaultValue = (int)efiImage.MinFilter;
effectBuilder.AddPropertyVariable(variableInfo1);
string name1 = variableInfo1.Name;
VariableInfo variableInfo2 = new VariableInfo()
{
ID = efiImage.MagFilterID,
Type = Dx9VariableType.Integer,
IsDynamic = efiImage.IsDynamicProperty("MagFilter")
};
variableInfo2.Name = variableInfo2.IsDynamic ? effectBuilder.GenerateGlobalVariable(variableInfo2.Type, efiImage.Name + "MagFilter") : effectBuilder.GenerateGlobalConstant(variableInfo2.Type, efiImage.Name + "MagFilter");
variableInfo2.DefaultValue = (int)efiImage.MagFilter;
effectBuilder.AddPropertyVariable(variableInfo2);
string name2 = variableInfo2.Name;
effectBuilder.AddPropertyVariable(new VariableInfo()
{
ID = efiImage.CoordinateMapIndexID,
Type = Dx9VariableType.Integer,
IsDynamic = efiImage.IsDynamicProperty("CoordinateMapIndex"),
Name = null,
DefaultValue = (int)efiImage.CoordinateMapIndex
});
Dx9TextureInfo dx9TextureInfo = effectBuilder.AllocateTexture();
TextureVariableInfo textureVariableInfo = new TextureVariableInfo();
textureVariableInfo.ID = efiImage.ImageID;
textureVariableInfo.Type = Dx9VariableType.Texture;
textureVariableInfo.Name = effectBuilder.GenerateGlobalVariable(textureVariableInfo.Type, efiImage.Name);
textureVariableInfo.DefaultValue = efiImage.Image;
textureVariableInfo.SamplerName = dx9TextureInfo.Sampler;
textureVariableInfo.MinFilter = InvariantString.Format("<{0}>", name1);
textureVariableInfo.MagFilter = InvariantString.Format("<{0}>", name2);
textureVariableInfo.CoordinateMapID = efiImage.CoordinateMapIndexID;
textureVariableInfo.ImageIndexID = efiImage.ImageIndexID;
effectBuilder.AddPropertyVariable(textureVariableInfo);
effectBuilder.PixelShaderOutput = effectBuilder.GenerateLocalVariable(Dx9VariableType.Vector4, efiImage.Name);
effectBuilder.EmitPixelFragment(InvariantString.Format(" // Load the image\r\n float4 {0} = tex2D({1}, {2});\r\n\r\n", effectBuilder.PixelShaderOutput, dx9TextureInfo.Sampler, dx9TextureInfo.TexCoordInput));
effectBuilder.AddPropertyVariable(new VariableInfo()
{
ID = efiImage.ImageIndexID,
Type = Dx9VariableType.Integer,
IsDynamic = efiImage.IsDynamicProperty("ImageIndex"),
Name = null,
DefaultValue = (int)efiImage.ImageIndex
});
}
}
}
@@ -0,0 +1,27 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9ContrastElement
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Library;
namespace Microsoft.Iris.Render.Graphics
{
internal class Dx9ContrastElement
{
internal static void Generate(ContrastElement efoContrast, ref Dx9EffectBuilder effectBuilder)
{
VariableInfo variableInfo = new VariableInfo()
{
ID = efoContrast.ContrastID,
Type = Dx9VariableType.Float,
IsDynamic = efoContrast.IsDynamicProperty("Contrast")
};
variableInfo.Name = variableInfo.IsDynamic ? effectBuilder.GenerateGlobalVariable(variableInfo.Type, efoContrast.Name) : effectBuilder.GenerateGlobalConstant(variableInfo.Type, efoContrast.Name);
variableInfo.DefaultValue = efoContrast.Contrast;
effectBuilder.AddPropertyVariable(variableInfo);
effectBuilder.EmitPixelFragment(InvariantString.Format(" {{\r\n // apply the gain factor \r\n {0}.rgb -= float3(0.5f, 0.5f, 0.5f)\r\n; {0}.rgb *= float3({1}, {1}, {1});\r\n {0}.rgb += float3(0.5f, 0.5f, 0.5f)\r\n; }}\r\n", effectBuilder.PixelShaderOutput, variableInfo.Name));
}
}
}
@@ -0,0 +1,30 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9DesaturateElement
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Library;
namespace Microsoft.Iris.Render.Graphics
{
internal class Dx9DesaturateElement
{
internal static void Generate(
DesaturateElement efoDesaturate,
ref Dx9EffectBuilder effectBuilder)
{
VariableInfo variableInfo = new VariableInfo()
{
ID = efoDesaturate.DesaturateID,
Type = Dx9VariableType.Float,
DefaultValue = efoDesaturate.Desaturate,
IsDynamic = efoDesaturate.IsDynamicProperty("Desaturate")
};
variableInfo.Name = variableInfo.IsDynamic ? effectBuilder.GenerateGlobalVariable(variableInfo.Type, efoDesaturate.Name) : effectBuilder.GenerateGlobalConstant(variableInfo.Type, efoDesaturate.Name);
effectBuilder.AddPropertyVariable(variableInfo);
string name = variableInfo.Name;
effectBuilder.EmitPixelFragment(InvariantString.Format(" // Desaturate the value\r\n {{\r\n float3 vGray = {{.15, .55, .30}};\r\n float fLuminance = dot({0}.rgb, vGray);\r\n {0}.rgb = lerp({0}.rgb, fLuminance.rrr, {1});\r\n\r\n }}\r\n", effectBuilder.PixelShaderOutput, name));
}
}
}
@@ -0,0 +1,56 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9DestinationElement
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Library;
namespace Microsoft.Iris.Render.Graphics
{
internal class Dx9DestinationElement
{
internal static void Generate(
DestinationElement efiDestination,
ref Dx9EffectBuilder effectBuilder)
{
Dx9TextureInfo textureInfo = effectBuilder.AllocateTexture();
effectBuilder.AddRequirement(textureInfo, Dx9TextureRequirements.SampleBackbuffer, (int)efiDestination.DownsampleID);
effectBuilder.AddRequirement(textureInfo, Dx9TextureRequirements.DisablePerspectiveCorrection, null);
effectBuilder.AddRequirement(textureInfo, Dx9TextureRequirements.TexelSize, null);
TextureVariableInfo textureVariableInfo = new TextureVariableInfo();
textureVariableInfo.ID = efiDestination.DestinationID;
textureVariableInfo.Type = Dx9VariableType.Texture;
textureVariableInfo.Name = effectBuilder.GenerateGlobalVariable(textureVariableInfo.Type, efiDestination.Name);
textureVariableInfo.DefaultValue = null;
textureVariableInfo.SamplerName = textureInfo.Sampler;
textureVariableInfo.MinFilter = "Linear";
textureVariableInfo.MagFilter = "Linear";
textureVariableInfo.CoordinateMapID = -1;
textureVariableInfo.ImageIndexID = -1;
effectBuilder.AddPropertyVariable(textureVariableInfo);
effectBuilder.AddPropertyVariable(new VariableInfo()
{
ID = efiDestination.DownsampleID,
Type = Dx9VariableType.Float,
IsDynamic = efiDestination.IsDynamicProperty("Downsample"),
Name = null,
DefaultValue = efiDestination.Downsample
});
VariableInfo variableInfo = new VariableInfo()
{
ID = efiDestination.UVOffsetID,
Type = Dx9VariableType.Vector2,
IsDynamic = efiDestination.IsDynamicProperty("UVOffset")
};
variableInfo.Name = variableInfo.IsDynamic ? effectBuilder.GenerateGlobalVariable(variableInfo.Type, "UVOffset") : effectBuilder.GenerateGlobalConstant(variableInfo.Type, "UVOffset");
variableInfo.DefaultValue = efiDestination.UVOffset;
effectBuilder.AddPropertyVariable(variableInfo);
effectBuilder.PixelShaderOutput = effectBuilder.GenerateLocalVariable(Dx9VariableType.Texture, efiDestination.Name);
if (variableInfo.IsDynamic || !efiDestination.UVOffset.IsApproximate(Vector2.Zero))
effectBuilder.EmitPixelFragment(InvariantString.Format(" // Load the image\r\n float4 {0} = tex2D({1}, {2} + float2({3}.x * {4}.x, {3}.y * {4}.y));\r\n\r\n", effectBuilder.PixelShaderOutput, textureInfo.Sampler, textureInfo.TexCoordInput, textureInfo.TexelSize, variableInfo.Name));
else
effectBuilder.EmitPixelFragment(InvariantString.Format(" // Load the image\r\n float4 {0} = tex2D({1}, {2});\r\n\r\n", effectBuilder.PixelShaderOutput, textureInfo.Sampler, textureInfo.TexCoordInput));
}
}
}
@@ -0,0 +1,31 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9EdgeDetectionElement
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Library;
namespace Microsoft.Iris.Render.Graphics
{
internal class Dx9EdgeDetectionElement
{
internal static void Generate(
EdgeDetectionElement efoEdgeDetection,
ref Dx9EffectBuilder effectBuilder)
{
Dx9TextureInfo textureInfo = effectBuilder.GetTextureInfo(effectBuilder.ImageCount - 1);
effectBuilder.AddRequirement(textureInfo, Dx9TextureRequirements.TexelSize, null);
VariableInfo variableInfo = new VariableInfo()
{
ID = efoEdgeDetection.EdgeLimitID,
Type = Dx9VariableType.Float,
IsDynamic = efoEdgeDetection.IsDynamicProperty("EdgeLimit")
};
variableInfo.Name = variableInfo.IsDynamic ? effectBuilder.GenerateGlobalVariable(variableInfo.Type, efoEdgeDetection.Name) : effectBuilder.GenerateGlobalConstant(variableInfo.Type, efoEdgeDetection.Name);
variableInfo.DefaultValue = efoEdgeDetection.EdgeLimit;
effectBuilder.AddPropertyVariable(variableInfo);
effectBuilder.EmitPixelFragment(InvariantString.Format(" {{\r\n // Sample neightbour pixel\r\n float4 vBottomPixel = tex2D({1}, {2} + float2(0.0f, {3}.y));\r\n float currentAvg = {0}.r + {0}.g + {0}.b;\r\n currentAvg = currentAvg / 3.0f;\r\n float bottomAvg = vBottomPixel.r + vBottomPixel.g + vBottomPixel.b;\r\n bottomAvg = bottomAvg / 3.0f;\r\n float diff = abs(currentAvg - bottomAvg);\r\n // change color into black or white depending on what the delta is\r\n if (diff < {4})\r\n {{\r\n {0}.rgb = 1.0f;\r\n }}\r\n else\r\n {{\r\n {0}.rgb = 0.0f;\r\n }}\r\n }}\r\n\r\n", effectBuilder.PixelShaderOutput, textureInfo.Sampler, textureInfo.TexCoordInput, textureInfo.TexelSize, variableInfo.Name));
}
}
}
@@ -0,0 +1,46 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9Effect
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Render.Protocols.Splash.Rendering;
namespace Microsoft.Iris.Render.Graphics
{
internal class Dx9Effect : Effect
{
internal Dx9Effect(Dx9EffectTemplate effectTemplate)
: base(effectTemplate)
=> this.m_remoteEffect = this.m_effectTemplate.Session.BuildRemoteDx9Effect(this);
internal Dx9EffectManager EffectManager => ((Dx9GraphicsDevice)this.m_effectTemplate.Device).EffectManager;
internal override void RemoteEffect()
{
((RemoteDx9Effect)this.m_remoteEffect).SendLoadEffectResource(((Dx9EffectTemplate)this.m_effectTemplate).EffectResource.RemoteStub);
this.Initialize();
}
internal override void SetProperty(string stPropertyName, Image image)
{
if (image != null)
{
Dx9EffectResource effectResource = ((Dx9EffectTemplate)this.m_effectTemplate).EffectResource;
image.GutterSize = effectResource.GutterSize;
}
base.SetProperty(stPropertyName, image);
}
internal override void SetProperty(string stPropertyName, IImage[] images)
{
Dx9EffectResource effectResource = ((Dx9EffectTemplate)this.m_effectTemplate).EffectResource;
for (int index = 0; index < images.Length; ++index)
{
if (images[index] is Image image)
image.GutterSize = effectResource.GutterSize;
}
base.SetProperty(stPropertyName, images);
}
}
}
@@ -0,0 +1,376 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9EffectBuilder
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Library;
using Microsoft.Iris.Render.Internal;
using System.IO;
using System.Text;
namespace Microsoft.Iris.Render.Graphics
{
internal class Dx9EffectBuilder
{
private string m_stPixelOutput;
private StringBuilder m_sbPixelShader;
private StringBuilder m_sbVertexShader;
private StringBuilder m_sbDeclarations;
private StringBuilder m_sbEffect;
private Vector<VariableInfo> m_alPropertyVariables;
private int m_nUniqueVariableID;
private Vector<Dx9TextureInfo> m_alTextureInfos;
private Vector<VariableInfo> m_alGlobalVariables;
private Vector<string> m_alIncludes;
private int m_cMaxSimultaneousTextures;
private int m_cMaxRenderTargets;
private int m_nRequirements;
internal Dx9EffectBuilder(GraphicsCaps caps)
{
this.m_cMaxSimultaneousTextures = caps.MaxSimultaneousTextures;
this.m_cMaxRenderTargets = caps.AvailableRenderTargets;
}
internal void EmitPixelFragment(string stData)
{
if (this.m_sbPixelShader == null)
this.m_sbPixelShader = new StringBuilder(128);
this.m_sbPixelShader.Append(stData);
}
internal void EmitEffectFragment(string stData)
{
if (this.m_sbEffect == null)
this.m_sbEffect = new StringBuilder(512);
this.m_sbEffect.Append(stData);
}
internal void EmitIncludesFragment(string stData)
{
if (this.m_alIncludes == null)
this.m_alIncludes = new Vector<string>();
if (this.m_alIncludes.Contains(stData))
return;
this.m_alIncludes.Add(stData);
}
internal string GenerateGlobalConstant(Dx9VariableType typeProperty, string stName) => this.GenerateVariableName(VariableScope.Const, typeProperty, stName);
internal string GenerateLocalVariable(Dx9VariableType typeProperty, string stName) => this.GenerateVariableName(VariableScope.Local, typeProperty, stName);
internal string GenerateGlobalVariable(Dx9VariableType typeProperty, string stName) => this.GenerateVariableName(VariableScope.Global, typeProperty, stName);
internal void AddPropertyVariable(VariableInfo variableInfo)
{
if (this.m_alPropertyVariables == null)
this.m_alPropertyVariables = new Vector<VariableInfo>();
this.m_alPropertyVariables.Add(variableInfo);
}
internal void AddGlobalVariable(VariableInfo variableInfo)
{
if (this.m_alGlobalVariables == null)
this.m_alGlobalVariables = new Vector<VariableInfo>();
this.m_alGlobalVariables.Add(variableInfo);
}
private string GenerateVariableName(
VariableScope scope,
Dx9VariableType typeProperty,
string stName)
{
StringBuilder stringBuilder = new StringBuilder(32);
switch (scope)
{
case VariableScope.Global:
stringBuilder.Append("g_");
break;
case VariableScope.Const:
stringBuilder.Append("k_");
break;
}
switch (typeProperty)
{
case Dx9VariableType.Integer:
stringBuilder.Append("n");
break;
case Dx9VariableType.Float:
stringBuilder.Append("fl");
break;
case Dx9VariableType.Vector2:
case Dx9VariableType.Vector3:
case Dx9VariableType.Vector4:
stringBuilder.Append("v");
break;
case Dx9VariableType.Texture:
stringBuilder.Append("tex");
break;
}
if (stName != null)
{
if (stName.Length > 15)
stName = stName.Substring(0, 15);
stringBuilder.Append(stName);
}
else
stringBuilder.Append("Temp");
return stringBuilder.ToString() + this.m_nUniqueVariableID++;
}
internal void Clear()
{
this.m_stPixelOutput = null;
this.m_nUniqueVariableID = 0;
this.m_nRequirements = 0;
this.m_sbPixelShader = null;
this.m_sbVertexShader = null;
this.m_sbDeclarations = null;
this.m_sbEffect = null;
if (this.m_alPropertyVariables != null)
this.m_alPropertyVariables.Clear();
if (this.m_alGlobalVariables != null)
this.m_alGlobalVariables.Clear();
if (this.m_alTextureInfos != null)
this.m_alTextureInfos.Clear();
if (this.m_alIncludes == null)
return;
this.m_alIncludes.Clear();
}
internal string ConvertToString(Dx9VariableType type)
{
switch (type)
{
case Dx9VariableType.Integer:
return "int";
case Dx9VariableType.Float:
return "float";
case Dx9VariableType.Vector2:
return "float2";
case Dx9VariableType.Vector3:
return "float3";
case Dx9VariableType.Vector4:
return "float4";
case Dx9VariableType.Texture:
return "texture";
default:
return "";
}
}
internal string ConvertToString(FilterMode mode)
{
switch (mode)
{
case FilterMode.Point:
return "Point";
case FilterMode.Linear:
return "Linear";
default:
return "";
}
}
internal bool Validate() => this.ImageCount <= this.m_cMaxSimultaneousTextures && this.GetRenderTargetCount() <= this.m_cMaxRenderTargets;
internal Dx9TextureInfo AllocateTexture()
{
Dx9TextureInfo dx9TextureInfo = new Dx9TextureInfo()
{
ImageIndex = this.ImageCount
};
dx9TextureInfo.TexCoordInput = InvariantString.Format("{0}{1}", "vTexCoord", dx9TextureInfo.ImageIndex);
dx9TextureInfo.Sampler = InvariantString.Format("{0}{1}", "Sampler", dx9TextureInfo.ImageIndex);
dx9TextureInfo.DownsamplePropertyID = -1;
if (this.m_alTextureInfos == null)
this.m_alTextureInfos = new Vector<Dx9TextureInfo>();
this.m_alTextureInfos.Add(dx9TextureInfo);
return dx9TextureInfo;
}
internal void AddRequirement(
Dx9TextureInfo textureInfo,
Dx9TextureRequirements type,
object oValue)
{
textureInfo.Requirements |= (int)type;
switch (type)
{
case Dx9TextureRequirements.TexelSize:
if (textureInfo.TexelSize != null)
break;
string stName1 = InvariantString.Format("{0}{1}", "TexelSize", textureInfo.ImageIndex);
VariableInfo variableInfo1 = new VariableInfo()
{
IsDynamic = true,
ID = -1,
Type = Dx9VariableType.Vector2
};
variableInfo1.Name = this.GenerateGlobalVariable(variableInfo1.Type, stName1);
variableInfo1.DefaultValue = new Vector2(0.0f, 0.0f);
this.AddGlobalVariable(variableInfo1);
textureInfo.TexelSize = variableInfo1.Name;
break;
case Dx9TextureRequirements.SampleBackbuffer:
textureInfo.DownsamplePropertyID = (int)oValue;
break;
case Dx9TextureRequirements.TexUVSize:
if (textureInfo.TexUVSize != null)
break;
string stName2 = InvariantString.Format("{0}{1}", "TexUVSize", textureInfo.ImageIndex);
VariableInfo variableInfo2 = new VariableInfo()
{
IsDynamic = true,
ID = -1,
Type = Dx9VariableType.Vector2
};
variableInfo2.Name = this.GenerateGlobalVariable(variableInfo2.Type, stName2);
variableInfo2.DefaultValue = new Vector2(0.0f, 0.0f);
this.AddGlobalVariable(variableInfo2);
textureInfo.TexUVSize = variableInfo2.Name;
break;
case Dx9TextureRequirements.TexUVRefPoint:
if (textureInfo.TexUVRefPoint != null)
break;
string stName3 = InvariantString.Format("{0}{1}", "TexUVRefPoint", textureInfo.ImageIndex);
VariableInfo variableInfo3 = new VariableInfo()
{
IsDynamic = true,
ID = -1,
Type = Dx9VariableType.Vector2
};
variableInfo3.Name = this.GenerateGlobalVariable(variableInfo3.Type, stName3);
variableInfo3.DefaultValue = new Vector2(0.0f, 0.0f);
this.AddGlobalVariable(variableInfo3);
textureInfo.TexUVRefPoint = variableInfo3.Name;
break;
}
}
internal void AddRequirement(EffectRequirements requirement) => Bits.SetFlag(ref this.m_nRequirements, (int)requirement);
internal Dx9TextureInfo GetTextureInfo(int idxTexture) => this.m_alTextureInfos[idxTexture];
internal string PixelShaderOutput
{
get => this.m_stPixelOutput;
set => this.m_stPixelOutput = value;
}
internal string ShaderDeclarations => this.GenerateDeclarations();
internal string IncludesFragment
{
get
{
if (this.m_alIncludes == null)
return "";
StringBuilder stringBuilder = new StringBuilder();
for (int index = 0; index < this.m_alIncludes.Count; ++index)
stringBuilder.AppendFormat("#include {0}\r\n", this.m_alIncludes[index]);
return stringBuilder.ToString();
}
}
internal string PixelShader => this.GeneratePixelShader();
internal string VertexShader => this.GenerateVertexShader();
internal Vector<VariableInfo> PropertyVariables => this.m_alPropertyVariables;
internal Vector<VariableInfo> GlobalVariables => this.m_alGlobalVariables;
internal string EffectDefinition => this.m_sbEffect.ToString();
internal int ImageCount => this.m_alTextureInfos == null ? 0 : this.m_alTextureInfos.Count;
internal Vector<Dx9TextureInfo> TextureInfoList => this.m_alTextureInfos;
internal void SaveEffect(string stFilename)
{
StreamWriter streamWriter = new StreamWriter(stFilename);
streamWriter.WriteLine(this.m_sbEffect.ToString());
streamWriter.Close();
}
private string GenerateDeclarations()
{
if (this.m_sbDeclarations == null)
this.m_sbDeclarations = new StringBuilder(128);
if (this.m_sbDeclarations.Length == 0)
{
this.m_sbDeclarations.Append("struct PS_OUTPUT\r\n{\r\n float4 Color : COLOR; // Object space position\r\n};\r\n\r\n");
this.m_sbDeclarations.Append("struct VS_INPUT\r\n{\r\n float4 ObjPos : POSITION; // Object space position\r\n float4 Color : COLOR; // Vertex color\r\n");
for (int index = 0; index < this.ImageCount; ++index)
this.m_sbDeclarations.AppendFormat(" float2 TexCoord{0} : TEXCOORD{0}; // Texture {0} UV coordinates\r\n", index);
this.m_sbDeclarations.Append("};\r\n\r\n");
this.m_sbDeclarations.Append("struct VS_OUTPUT\r\n{\r\n float4 ProjPos : POSITION; // Projected space position\r\n float4 Color : COLOR; // Vertex color\r\n");
if (Bits.TestFlag(this.m_nRequirements, 1))
this.m_sbDeclarations.Append(" float3 ViewPos : TEXCOORD5; // View space position\r\n");
for (int index = 0; index < this.ImageCount; ++index)
{
if (Bits.TestFlag(this.m_alTextureInfos[index].Requirements, 16))
this.m_sbDeclarations.AppendFormat(" float3 TexCoord{0} : TEXCOORD{0}; // Texture {0} UVW coordinates\r\n", index);
else
this.m_sbDeclarations.AppendFormat(" float2 TexCoord{0} : TEXCOORD{0}; // Texture {0} UV coordinates\r\n", index);
}
this.m_sbDeclarations.Append("};\r\n\r\n");
}
return this.m_sbDeclarations.ToString();
}
private string GenerateVertexShader()
{
if (this.m_sbVertexShader == null)
this.m_sbVertexShader = new StringBuilder(128);
if (this.m_sbVertexShader.Length == 0)
{
this.m_sbVertexShader.Append(" //\r\n // Compute the accumulated WVP matrix. If the separate matrices are not referenced\r\n // by effect elements, the D3DX preshader will combine these on the CPU and set the\r\n // result via VS constants.\r\n //\r\n\r\n float4x4 matAccumulated = mul(g_matWorldView, g_matProjection);\r\n\r\n\r\n //\r\n // Setup the resulting device vertex.\r\n //\r\n\r\n Output.ProjPos = mul(Input.ObjPos, matAccumulated);\r\n Output.Color = Input.Color;\r\n");
if (Bits.TestFlag(this.m_nRequirements, 1))
this.m_sbVertexShader.Append(" Output.ViewPos = mul(Input.ObjPos, g_matWorldView);\r\n");
for (int index = 0; index < this.ImageCount; ++index)
{
if (Bits.TestFlag(this.m_alTextureInfos[index].Requirements, 16))
this.m_sbVertexShader.AppendFormat(" Output.TexCoord{0} = float3(Input.TexCoord{0}.x * Output.ProjPos.w, Input.TexCoord{0}.y * Output.ProjPos.w, Output.ProjPos.w);\r\n", index);
else
this.m_sbVertexShader.AppendFormat(" Output.TexCoord{0} = Input.TexCoord{0};\r\n", index);
}
}
return this.m_sbVertexShader.ToString();
}
private string GeneratePixelShader()
{
StringBuilder stringBuilder = new StringBuilder(128);
for (int index = 0; index < this.ImageCount; ++index)
{
Dx9TextureInfo alTextureInfo = this.m_alTextureInfos[index];
if (Bits.TestFlag(alTextureInfo.Requirements, 16))
stringBuilder.AppendFormat(" float2 {0} = Input.TexCoord{1}.xy / Input.TexCoord{1}.z;\r\n", alTextureInfo.TexCoordInput, index);
else
stringBuilder.AppendFormat(" float2 {0} = Input.TexCoord{1};\r\n", alTextureInfo.TexCoordInput, index);
}
stringBuilder.Append("\r\n");
stringBuilder.Append(this.m_sbPixelShader.ToString());
return stringBuilder.ToString();
}
private int GetRenderTargetCount()
{
if (this.m_alTextureInfos == null)
return 0;
int num = 0;
foreach (Dx9TextureInfo alTextureInfo in this.m_alTextureInfos)
{
if ((alTextureInfo.Requirements & 2) > 0)
{
++num;
break;
}
}
return num;
}
}
}
@@ -0,0 +1,129 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9EffectManager
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Render.Common;
using Microsoft.Iris.Render.Internal;
using System;
namespace Microsoft.Iris.Render.Graphics
{
internal class Dx9EffectManager : RenderObject
{
private const int k_cMaxTargetItems = 50;
private RenderSession m_session;
private Dx9GraphicsDevice m_device;
private Dx9EffectBuilder m_effectBuilder;
private Map<ByteBuilder, Dx9EffectResource> m_mapEffectCache;
private bool m_fPendingCacheUpdate;
private readonly DeferredHandler m_cbUpdateCache;
internal Dx9EffectManager(RenderSession session, Dx9GraphicsDevice dx9Device)
{
this.m_session = session;
this.m_device = dx9Device;
this.m_cbUpdateCache = new DeferredHandler(this.UpdateCache);
this.m_effectBuilder = new Dx9EffectBuilder(this.m_device.GraphicsCaps);
}
protected override void Dispose(bool fInDispose)
{
try
{
if (!fInDispose || this.m_mapEffectCache == null)
return;
Map<ByteBuilder, Dx9EffectResource>.ValueCollection.Enumerator enumerator = this.m_mapEffectCache.Values.GetEnumerator();
while (enumerator.MoveNext())
enumerator.Current?.UnregisterUsage(this);
this.m_mapEffectCache = null;
}
finally
{
base.Dispose(fInDispose);
}
}
internal Dx9EffectBuilder EffectBuilder => this.m_effectBuilder;
internal Dx9GraphicsDevice Device => this.m_device;
private bool CacheLookup(ByteBuilder cacheKey, out Dx9EffectResource resource)
{
if (this.m_mapEffectCache == null)
{
resource = null;
return false;
}
bool flag = this.m_mapEffectCache.ContainsKey(cacheKey);
resource = !flag ? null : this.m_mapEffectCache[cacheKey];
return flag;
}
private void AddCachedEffect(ByteBuilder cacheWriter, Dx9EffectResource effect)
{
if (this.m_mapEffectCache == null)
this.m_mapEffectCache = new Map<ByteBuilder, Dx9EffectResource>(50);
this.m_mapEffectCache.Add(cacheWriter, effect);
if (effect == null)
return;
this.ScheduleCacheUpdate();
}
internal bool CreateEffectResource(
string stName,
EffectInput element,
int nPropCacheSize,
out Dx9EffectResource dxEffectResource)
{
Dx9EffectResource resource = null;
ByteBuilder byteBuilder = new ByteBuilder(nPropCacheSize);
element.AddCacheKey(byteBuilder);
if (!this.CacheLookup(byteBuilder, out resource))
{
resource = new Dx9EffectResource(this.m_session, stName, this);
resource.RegisterUsage(this);
if (!resource.Create(element))
{
resource.UnregisterUsage(this);
dxEffectResource = null;
this.AddCachedEffect(byteBuilder, null);
return false;
}
this.AddCachedEffect(byteBuilder, resource);
}
dxEffectResource = resource;
return dxEffectResource != null;
}
private void UpdateCache(object arg)
{
if (this.m_mapEffectCache != null)
{
Map<ByteBuilder, Dx9EffectResource> map = new Map<ByteBuilder, Dx9EffectResource>(Math.Max(50, this.m_mapEffectCache.Count));
foreach (KeyValueEntry<ByteBuilder, Dx9EffectResource> keyValueEntry in this.m_mapEffectCache)
{
if (keyValueEntry.Value != null)
{
if (keyValueEntry.Value.UsageCount == 1)
keyValueEntry.Value.UnregisterUsage(this);
else
map.Add(keyValueEntry.Key, keyValueEntry.Value);
}
}
if (map.Count != this.m_mapEffectCache.Count)
this.m_mapEffectCache = map;
}
this.m_fPendingCacheUpdate = false;
}
private void ScheduleCacheUpdate()
{
if (this.m_fPendingCacheUpdate || this.m_mapEffectCache.Count < 50)
return;
this.m_session.DeferredInvoke(m_cbUpdateCache, null, DeferredInvokePriority.Idle, new TimeSpan(0, 0, 5));
this.m_fPendingCacheUpdate = true;
}
}
}
@@ -0,0 +1,396 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9EffectResource
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Library;
using Microsoft.Iris.Render.Common;
using Microsoft.Iris.Render.Internal;
using Microsoft.Iris.Render.Protocol;
using Microsoft.Iris.Render.Protocols.Splash.Rendering;
using System;
using System.Collections;
using System.Runtime.InteropServices;
namespace Microsoft.Iris.Render.Graphics
{
internal class Dx9EffectResource : SharedRenderObject, IRenderHandleOwner
{
private RenderSession m_session;
private RemoteDx9EffectResource m_remoteEffect;
private string m_stName;
private Dx9EffectManager m_effectManager;
private DataBufferTracker m_tracker;
private Size m_sizeGutter;
private static string k_stVertexShaderName = "ExecuteVertexShader";
private static string k_stPixelShaderName = "ExecutePixelShader";
internal Dx9EffectResource(
RenderSession session,
string stName,
Dx9EffectManager effectManager)
{
this.m_session = session;
this.m_stName = stName;
this.m_effectManager = effectManager;
this.m_tracker = MessagingSession.Current.CreateDataBufferTracker(this);
}
protected override void Dispose(bool fInDispose)
{
try
{
if (fInDispose)
{
if (this.m_tracker != null)
MessagingSession.Current.ReturnDataBufferTracker(this.m_tracker);
if (this.m_remoteEffect != null)
this.m_remoteEffect.Dispose();
}
this.m_tracker = null;
this.m_remoteEffect = null;
}
finally
{
base.Dispose(fInDispose);
}
}
public RemoteDx9EffectResource RemoteStub => this.m_remoteEffect;
private string PixelShaderVersion => this.m_effectManager.Device.PixelShaderProfile;
private string VertexShaderVersion => this.m_effectManager.Device.VertexShaderProfile;
internal Size GutterSize => this.m_sizeGutter;
RENDERHANDLE IRenderHandleOwner.RenderHandle => this.m_remoteEffect.RenderHandle;
void IRenderHandleOwner.OnDisconnect() => this.m_remoteEffect = null;
internal bool Create(EffectInput element)
{
Dx9EffectBuilder effectBuilder = this.m_effectManager.EffectBuilder;
effectBuilder.Clear();
if (!this.ProcessEffectInput(element, ref effectBuilder))
return false;
this.GenerateEffect(effectBuilder);
uint nBlobSize = 0;
IntPtr pEffectBlob = IntPtr.Zero;
IntPtr pBlobBuffer = IntPtr.Zero;
if (!this.CompileEffect(effectBuilder, out pEffectBlob, out pBlobBuffer, out nBlobSize))
return false;
Vector<VariableInfo> propertyVariables = effectBuilder.PropertyVariables;
if (propertyVariables != null)
{
int index = 0;
while (index < propertyVariables.Count)
{
if (!propertyVariables[index].IsDynamic)
propertyVariables.RemoveAt(index);
else
++index;
}
}
this.RemoteEffect(effectBuilder, pEffectBlob, pBlobBuffer, nBlobSize);
return true;
}
private bool CompileEffect(
Dx9EffectBuilder effectBuilder,
out IntPtr pEffectBlob,
out IntPtr pBlobBuffer,
out uint nBlobSize)
{
bool flag = false;
IntPtr pErrorString = IntPtr.Zero;
IntPtr pErrorBuffer = IntPtr.Zero;
pEffectBlob = IntPtr.Zero;
pBlobBuffer = IntPtr.Zero;
nBlobSize = 0U;
try
{
EngineApi.IFC(EngineApi.SpDx9CompileEffect(effectBuilder.EffectDefinition, null, out pErrorString, out pErrorBuffer, out pEffectBlob, out nBlobSize, out pBlobBuffer));
flag = true;
}
catch (Exception ex)
{
if (Marshal.PtrToStringAnsi(pErrorString) == null)
throw;
}
finally
{
if (pErrorBuffer != IntPtr.Zero)
Marshal.Release(pErrorBuffer);
}
return flag;
}
private void RemoteEffect(
Dx9EffectBuilder effectBuilder,
IntPtr pEffectBlob,
IntPtr pBlobBuffer,
uint nBlobSize)
{
DataBuffer dataBuffer = this.m_session.BuildDataBuffer(pEffectBlob, nBlobSize);
this.m_tracker.Track(dataBuffer, new DataBufferTracker.CleanupEventHandler(OnReleaseLocalData), pBlobBuffer);
dataBuffer.Commit();
this.m_remoteEffect = this.m_session.BuildRemoteDx9EffectResource(this, this.m_effectManager.Device, dataBuffer);
Vector<VariableInfo> propertyVariables = effectBuilder.PropertyVariables;
if (propertyVariables != null)
{
foreach (VariableInfo variableInfo in propertyVariables)
{
switch (variableInfo.Type)
{
case Dx9VariableType.Integer:
this.m_remoteEffect.SendAddProperty(variableInfo.Name, (int)variableInfo.DefaultValue);
continue;
case Dx9VariableType.Float:
this.m_remoteEffect.SendAddProperty(variableInfo.Name, (float)variableInfo.DefaultValue);
continue;
case Dx9VariableType.Vector2:
this.m_remoteEffect.SendAddProperty(variableInfo.Name, (Vector2)variableInfo.DefaultValue);
continue;
case Dx9VariableType.Vector3:
this.m_remoteEffect.SendAddProperty(variableInfo.Name, (Vector3)variableInfo.DefaultValue);
continue;
case Dx9VariableType.Vector4:
this.m_remoteEffect.SendAddProperty(variableInfo.Name, (Vector4)variableInfo.DefaultValue);
continue;
case Dx9VariableType.Texture:
TextureVariableInfo textureVariableInfo = (TextureVariableInfo)variableInfo;
this.m_remoteEffect.SendAddProperty(variableInfo.Name, textureVariableInfo.CoordinateMapID, textureVariableInfo.ImageIndexID);
continue;
default:
continue;
}
}
}
this.m_remoteEffect.SendPostPropertiesAdded();
this.m_remoteEffect.SendSetGutterSize(this.m_sizeGutter);
if (effectBuilder.TextureInfoList == null)
return;
foreach (Dx9TextureInfo textureInfo in effectBuilder.TextureInfoList)
{
if (textureInfo.Requirements != 0)
this.m_remoteEffect.SendAddTextureRequirements(textureInfo.ImageIndex, textureInfo.Requirements, textureInfo.TexelSize, textureInfo.TexUVSize, textureInfo.TexUVRefPoint, textureInfo.DownsamplePropertyID);
}
}
private static void OnReleaseLocalData(object sender, DataBufferTracker.CleanupEventArgs args)
{
IntPtr contextData = (IntPtr)args.ContextData;
if (!(contextData != IntPtr.Zero))
return;
Marshal.Release(contextData);
IntPtr zero = IntPtr.Zero;
}
private string GenerateFileName() => this.m_stName + ".fx";
protected void EmitHeader(Dx9EffectBuilder effectBuilder)
{
effectBuilder.EmitEffectFragment("#include \"Common.fx\"\r\n");
effectBuilder.EmitEffectFragment(effectBuilder.IncludesFragment + "\r\n\r\n");
Vector<VariableInfo>[] vectorArray = new Vector<VariableInfo>[2]
{
effectBuilder.PropertyVariables,
effectBuilder.GlobalVariables
};
for (int index = 0; index < vectorArray.Length; ++index)
{
if (vectorArray[index] != null)
{
foreach (VariableInfo variableInfo in vectorArray[index])
{
if (variableInfo.Name != null)
{
switch (variableInfo.Type)
{
case Dx9VariableType.Integer:
if (variableInfo.IsDynamic)
{
effectBuilder.EmitEffectFragment(InvariantString.Format("{0} {1};\r\n", effectBuilder.ConvertToString(variableInfo.Type), variableInfo.Name));
continue;
}
effectBuilder.EmitEffectFragment(InvariantString.Format("static const {0} {1} = {2};\r\n", effectBuilder.ConvertToString(variableInfo.Type), variableInfo.Name, (int)variableInfo.DefaultValue));
continue;
case Dx9VariableType.Float:
if (variableInfo.IsDynamic)
{
effectBuilder.EmitEffectFragment(InvariantString.Format("{0} {1};\r\n", effectBuilder.ConvertToString(variableInfo.Type), variableInfo.Name));
continue;
}
effectBuilder.EmitEffectFragment(InvariantString.Format("static const {0} {1} = {2};\r\n", effectBuilder.ConvertToString(variableInfo.Type), variableInfo.Name, (float)variableInfo.DefaultValue));
continue;
case Dx9VariableType.Vector2:
if (variableInfo.IsDynamic)
{
effectBuilder.EmitEffectFragment(InvariantString.Format("{0} {1};\r\n", effectBuilder.ConvertToString(variableInfo.Type), variableInfo.Name));
continue;
}
effectBuilder.EmitEffectFragment(InvariantString.Format("static const {0} {1} = {2};\r\n", effectBuilder.ConvertToString(variableInfo.Type), variableInfo.Name, ((Vector2)variableInfo.DefaultValue).ToDxShaderString()));
continue;
case Dx9VariableType.Vector3:
if (variableInfo.IsDynamic)
{
effectBuilder.EmitEffectFragment(InvariantString.Format("{0} {1};\r\n", effectBuilder.ConvertToString(variableInfo.Type), variableInfo.Name));
continue;
}
effectBuilder.EmitEffectFragment(InvariantString.Format("static const {0} {1} = {2};\r\n", effectBuilder.ConvertToString(variableInfo.Type), variableInfo.Name, ((Vector3)variableInfo.DefaultValue).ToDxShaderString()));
continue;
case Dx9VariableType.Vector4:
if (variableInfo.IsDynamic)
{
effectBuilder.EmitEffectFragment(InvariantString.Format("{0} {1};\r\n", effectBuilder.ConvertToString(variableInfo.Type), variableInfo.Name));
continue;
}
effectBuilder.EmitEffectFragment(InvariantString.Format("static const {0} {1} = {2};\r\n", effectBuilder.ConvertToString(variableInfo.Type), variableInfo.Name, ((Vector4)variableInfo.DefaultValue).ToDxShaderString()));
continue;
case Dx9VariableType.Texture:
TextureVariableInfo textureVariableInfo = (TextureVariableInfo)variableInfo;
effectBuilder.EmitEffectFragment(InvariantString.Format("\r\n{0} {1};\r\n", effectBuilder.ConvertToString(textureVariableInfo.Type), textureVariableInfo.Name));
effectBuilder.EmitEffectFragment(InvariantString.Format("sampler {0} = \r\n sampler_state\r\n {{\r\n Texture = <{1}>;\r\n MinFilter = {2};\r\n MagFilter = {3};\r\n AddressU = Clamp;\r\n AddressV = Clamp;\r\n }};\r\n\r\n", textureVariableInfo.SamplerName, textureVariableInfo.Name, textureVariableInfo.MinFilter, textureVariableInfo.MagFilter));
continue;
default:
continue;
}
}
}
}
}
effectBuilder.EmitEffectFragment("\r\n");
}
protected void EmitShaders(Dx9EffectBuilder effectBuilder)
{
effectBuilder.EmitEffectFragment(effectBuilder.ShaderDeclarations);
effectBuilder.EmitEffectFragment(InvariantString.Format("VS_OUTPUT {0}(VS_INPUT Input)\r\n{{\r\n VS_OUTPUT Output;\r\n\r\n{1}\r\n return Output;\r\n}}\r\n\r\n", k_stVertexShaderName, effectBuilder.VertexShader));
effectBuilder.EmitEffectFragment(InvariantString.Format("PS_OUTPUT {0}(VS_OUTPUT Input)\r\n{{\r\n PS_OUTPUT Output;\r\n\r\n{1} // Include Vertex color contribution\r\n Output.Color = {2} * Input.Color;\r\n\r\n // Return the final result\r\n return Output;\r\n}}\r\n\r\n", k_stPixelShaderName, effectBuilder.PixelShader, effectBuilder.PixelShaderOutput));
}
protected void EmitTechnique(Dx9EffectBuilder effectBuilder) => effectBuilder.EmitEffectFragment(InvariantString.Format("technique GeneratedTechnique\r\n{{\r\n pass P0\r\n {{\r\n // Shaders\r\n PixelShader = compile {0} {1}();\r\n VertexShader = compile {2} {3}();\r\n }}\r\n}}\r\n", PixelShaderVersion, k_stPixelShaderName, VertexShaderVersion, k_stVertexShaderName));
private void GenerateEffect(Dx9EffectBuilder effectBuilder)
{
this.EmitHeader(effectBuilder);
this.EmitShaders(effectBuilder);
this.EmitTechnique(effectBuilder);
}
private bool ProcessEffectInput(EffectInput efiCurrent, ref Dx9EffectBuilder effectBuilder)
{
bool flag = true;
switch (efiCurrent.Type)
{
case EffectInputType.Color:
Dx9ColorElement.Generate((ColorElement)efiCurrent, ref effectBuilder);
break;
case EffectInputType.Image:
Dx9ImageElement.Generate((ImageElement)efiCurrent, ref effectBuilder);
break;
case EffectInputType.Blend:
BlendElement efiBlend = (BlendElement)efiCurrent;
this.ProcessEffectInput(efiBlend.Input1, ref effectBuilder);
string pixelShaderOutput1 = effectBuilder.PixelShaderOutput;
this.ProcessEffectInput(efiBlend.Input2, ref effectBuilder);
string pixelShaderOutput2 = effectBuilder.PixelShaderOutput;
Dx9BlendElement.Generate(efiBlend, pixelShaderOutput1, pixelShaderOutput2, ref effectBuilder);
break;
case EffectInputType.Interpolate:
InterpolateElement efiInterpolate = (InterpolateElement)efiCurrent;
this.ProcessEffectInput(efiInterpolate.Input1, ref effectBuilder);
string pixelShaderOutput3 = effectBuilder.PixelShaderOutput;
this.ProcessEffectInput(efiInterpolate.Input2, ref effectBuilder);
string pixelShaderOutput4 = effectBuilder.PixelShaderOutput;
Dx9InterpolateElement.Generate(efiInterpolate, pixelShaderOutput3, pixelShaderOutput4, ref effectBuilder);
break;
case EffectInputType.Layer:
flag = this.ProcessEffectLayer((EffectLayer)efiCurrent, ref effectBuilder);
break;
case EffectInputType.ComplexImage:
Dx9ComplexImageElement.Generate((ComplexImageElement)efiCurrent, ref effectBuilder);
break;
case EffectInputType.Video:
Dx9VideoElement.Generate((VideoElement)efiCurrent, ref effectBuilder);
break;
case EffectInputType.Spotlight2D:
Dx9SpotLight2DElement.Generate((SpotLight2DElement)efiCurrent, ref effectBuilder);
break;
case EffectInputType.PointLight2D:
Dx9PointLight2DElement.Generate((PointLight2DElement)efiCurrent, ref effectBuilder);
break;
case EffectInputType.Destination:
Dx9DestinationElement.Generate((DestinationElement)efiCurrent, ref effectBuilder);
this.m_sizeGutter.Width = Math.Max(this.m_sizeGutter.Width, 1);
this.m_sizeGutter.Height = Math.Max(this.m_sizeGutter.Height, 1);
break;
}
return flag && effectBuilder.Validate();
}
private bool ProcessEffectLayer(EffectLayer eflCurrent, ref Dx9EffectBuilder effectBuilder)
{
if (!this.ProcessEffectInput(eflCurrent.Input, ref effectBuilder))
return false;
if (eflCurrent.Operations != null)
{
foreach (EffectOperation operation in eflCurrent.Operations)
{
switch (operation.Type)
{
case EffectOperationType.Brightness:
Dx9BrightnessElement.Generate((BrightnessElement)operation, ref effectBuilder);
continue;
case EffectOperationType.Contrast:
Dx9ContrastElement.Generate((ContrastElement)operation, ref effectBuilder);
continue;
case EffectOperationType.Desaturate:
Dx9DesaturateElement.Generate((DesaturateElement)operation, ref effectBuilder);
continue;
case EffectOperationType.EdgeDetection:
Dx9EdgeDetectionElement.Generate((EdgeDetectionElement)operation, ref effectBuilder);
continue;
case EffectOperationType.Emboss:
Dx9EmbossElement.Generate((EmbossElement)operation, ref effectBuilder);
continue;
case EffectOperationType.GaussianBlur:
Debug2.Validate(eflCurrent.Input.Type == EffectInputType.Image || eflCurrent.Input.Type == EffectInputType.Video || eflCurrent.Input.Type == EffectInputType.Destination, typeof(InvalidOperationException), "GaussianBlurElement only valid for inputs with ImageElement inputs");
GaussianBlurElement efoBlur = (GaussianBlurElement)operation;
Dx9GaussianBlurElement.Generate(efoBlur, ref effectBuilder);
this.m_sizeGutter.Width = Math.Max(this.m_sizeGutter.Width, efoBlur.KernelRadius + 1);
this.m_sizeGutter.Height = Math.Max(this.m_sizeGutter.Height, efoBlur.KernelRadius + 1);
continue;
case EffectOperationType.HSL:
Dx9HSLElement.Generate((HSLElement)operation, ref effectBuilder);
continue;
case EffectOperationType.HSV:
Dx9HSVElement.Generate((HSVElement)operation, ref effectBuilder);
continue;
case EffectOperationType.InvAlpha:
Dx9InvAlphaElement.Generate(operation, ref effectBuilder);
continue;
case EffectOperationType.InvColor:
Dx9InvColorElement.Generate(operation, ref effectBuilder);
continue;
case EffectOperationType.Invert:
Dx9InvertElement.Generate((InvertElement)operation, ref effectBuilder);
continue;
case EffectOperationType.LightShaft:
Debug2.Validate(eflCurrent.Input.Type == EffectInputType.Image || eflCurrent.Input.Type == EffectInputType.Video || eflCurrent.Input.Type == EffectInputType.Destination, typeof(InvalidOperationException), "LightShaftElement only valid for inputs with ImageElement inputs");
Dx9LightShaftElement.Generate((LightShaftElement)operation, ref effectBuilder);
continue;
case EffectOperationType.Sepia:
Dx9SepiaElement.Generate((SepiaElement)operation, ref effectBuilder);
continue;
default:
continue;
}
}
}
return true;
}
}
}
@@ -0,0 +1,92 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9EffectTemplate
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Render.Common;
using Microsoft.Iris.Render.Internal;
using System;
namespace Microsoft.Iris.Render.Graphics
{
internal class Dx9EffectTemplate : EffectTemplate
{
private Dx9EffectResource m_effectResource;
internal Dx9EffectTemplate(RenderSession session, GraphicsDevice device, string stName)
: base(session, device, stName)
{
}
protected override void Dispose(bool fInDispose)
{
try
{
if (!fInDispose || this.m_effectResource == null)
return;
this.m_effectResource.UnregisterUsage(this);
this.m_effectResource = null;
}
finally
{
base.Dispose(fInDispose);
}
}
internal Dx9EffectManager EffectManager => ((Dx9GraphicsDevice)this.m_graphicsDevice).EffectManager;
internal Dx9EffectResource EffectResource => this.m_effectResource;
protected override bool Build(EffectInput input)
{
int nPropCacheSize = 0;
if (!this.GenerateProperties(input, this.m_dynamicProperties, out nPropCacheSize) || !this.ProcessEffectElement(input, this.m_dynamicProperties, nPropCacheSize))
return false;
Map<string, EffectProperty>.Enumerator enumerator = this.m_dynamicProperties.GetEnumerator();
while (enumerator.MoveNext())
{
EffectProperty effectProperty = enumerator.Current.Value;
if (effectProperty == null || !effectProperty.IsDynamic)
{
this.m_dynamicProperties.Remove(enumerator.Current.Key);
enumerator = this.m_dynamicProperties.GetEnumerator();
}
}
return true;
}
public override IEffect CreateInstance(object objUser)
{
Debug2.Validate(this.m_fBuilt, typeof(InvalidOperationException), "Cannot create instance if the template is not built");
Dx9Effect dx9Effect = null;
if (this.m_cache != null)
dx9Effect = (Dx9Effect)this.m_cache.Remove(objUser);
if (dx9Effect == null)
{
dx9Effect = new Dx9Effect(this);
dx9Effect.Cache = this.m_cache;
dx9Effect.RegisterUsage(objUser);
dx9Effect.RemoteEffect();
}
return dx9Effect;
}
private bool ProcessEffectElement(
EffectInput element,
Map<string, EffectProperty> allProps,
int nPropCacheSize)
{
if (!(this.m_graphicsDevice as Dx9GraphicsDevice).EffectManager.CreateEffectResource(this.m_stName, element, nPropCacheSize, out this.m_effectResource))
return false;
this.m_effectResource.RegisterUsage(this);
foreach (KeyValueEntry<string, EffectProperty> allProp in allProps)
{
EffectProperty effectProperty = allProp.Value;
if (effectProperty.Type == EffectPropertyType.Image && effectProperty.Value != null)
((Image)effectProperty.Value).GutterSize = this.m_effectResource.GutterSize;
}
return true;
}
}
}
@@ -0,0 +1,38 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9EmbossElement
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Library;
namespace Microsoft.Iris.Render.Graphics
{
internal class Dx9EmbossElement
{
internal static void Generate(EmbossElement efoEmboss, ref Dx9EffectBuilder effectBuilder)
{
Dx9TextureInfo textureInfo = effectBuilder.GetTextureInfo(effectBuilder.ImageCount - 1);
effectBuilder.AddRequirement(textureInfo, Dx9TextureRequirements.TexelSize, null);
VariableInfo variableInfo1 = new VariableInfo()
{
ID = efoEmboss.DirectionID,
Type = Dx9VariableType.Integer,
IsDynamic = efoEmboss.IsDynamicProperty("Direction")
};
variableInfo1.Name = variableInfo1.IsDynamic ? effectBuilder.GenerateGlobalVariable(variableInfo1.Type, efoEmboss.Name + "Direction") : effectBuilder.GenerateGlobalConstant(variableInfo1.Type, efoEmboss.Name + "Direction");
variableInfo1.DefaultValue = efoEmboss.Direction;
effectBuilder.AddPropertyVariable(variableInfo1);
VariableInfo variableInfo2 = new VariableInfo()
{
ID = efoEmboss.GrayLevelID,
Type = Dx9VariableType.Float,
IsDynamic = efoEmboss.IsDynamicProperty("GrayLevel")
};
variableInfo2.Name = variableInfo2.IsDynamic ? effectBuilder.GenerateGlobalVariable(variableInfo2.Type, efoEmboss.Name + "GrayLevel") : effectBuilder.GenerateGlobalConstant(variableInfo2.Type, efoEmboss.Name + "GrayLevel");
variableInfo2.DefaultValue = efoEmboss.GrayLevel;
effectBuilder.AddPropertyVariable(variableInfo2);
effectBuilder.EmitPixelFragment(InvariantString.Format(" {{\r\n // Sample neightbour pixel\r\n float4 vNeightbourPixel;\r\n if ({5} == 0)\r\n {{\r\n vNeightbourPixel = tex2D({1}, {2} + float2(-{3}.x, -{3}.y));\r\n }}\r\n else\r\n {{\r\n vNeightbourPixel = tex2D({1}, {2} + float2(+{3}.x, +{3}.y));\r\n }}\r\n float4 vDiff = {0} - vNeightbourPixel;\r\n float maxDiffColor = vDiff.r;\r\n if (abs(vDiff.g) > abs(maxDiffColor))\r\n {{\r\n maxDiffColor = vDiff.g;\r\n }}\r\n if (abs(vDiff.b) > abs(maxDiffColor))\r\n {{\r\n maxDiffColor = vDiff.b;\r\n }}\r\n maxDiffColor += {4};\r\n float minGray = min(maxDiffColor, 1.0f);\r\n float grayLevel = max(minGray, 0.0f);\r\n {0}.rgb = grayLevel;\r\n }}\r\n\r\n", effectBuilder.PixelShaderOutput, textureInfo.Sampler, textureInfo.TexCoordInput, textureInfo.TexelSize, variableInfo2.Name, variableInfo1.Name));
}
}
}
@@ -0,0 +1,116 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9GaussianBlurElement
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Library;
using Microsoft.Iris.Render.Common;
using System;
namespace Microsoft.Iris.Render.Graphics
{
internal class Dx9GaussianBlurElement
{
private static void GenerateWeights1D(int nKernelRadius, double flDeviation, double[] arKernel)
{
Debug2.Validate(flDeviation > 0.0, typeof(ArgumentOutOfRangeException), "Standard deviation must be > 0.0");
Debug2.Validate(nKernelRadius >= 1, typeof(ArgumentOutOfRangeException), "Kernel radius must be >= 1");
int num1 = 1 + 2 * nKernelRadius;
double num2 = 0.0;
Debug2.Validate(arKernel != null && num1 == arKernel.GetLength(0), typeof(ArgumentException), nameof(arKernel));
double num3 = 2.0 * (flDeviation * flDeviation);
double num4 = Math.Sqrt(2.0 * Math.PI) * flDeviation;
for (int index = 0; index < num1; ++index)
{
double num5 = index - nKernelRadius;
double num6 = Math.Exp(-(num5 * num5) / num3);
arKernel[index] = num6 / num4;
num2 += arKernel[index];
}
for (int index = 0; index < num1; ++index)
arKernel[index] /= num2;
}
private static void GenerateWeights2D(
int nKernelRadius,
double flDeviation,
double[,] arKernel)
{
Debug2.Validate(flDeviation > 0.0, typeof(ArgumentOutOfRangeException), "Standard deviation must be > 0.0");
Debug2.Validate(nKernelRadius >= 1, typeof(ArgumentOutOfRangeException), "Kernel radius must be >= 1");
double num1 = 0.0;
int num2 = 1 + 2 * nKernelRadius;
Debug2.Validate(arKernel != null && num2 == arKernel.GetLength(0) && num2 == arKernel.GetLength(1), typeof(ArgumentException), nameof(arKernel));
double num3 = flDeviation * flDeviation;
double num4 = 2.0 * num3;
double num5 = 2.0 * Math.PI * num3;
for (int index1 = 0; index1 < num2; ++index1)
{
for (int index2 = 0; index2 < num2; ++index2)
{
double num6 = index2 - nKernelRadius;
double num7 = index1 - nKernelRadius;
double num8 = Math.Exp(-(num6 * num6 + num7 * num7) / num4);
arKernel[index2, index1] = num8 / num5;
num1 += arKernel[index2, index1];
}
}
for (int index1 = 0; index1 < num2; ++index1)
{
for (int index2 = 0; index2 < num2; ++index2)
arKernel[index2, index1] /= num1;
}
}
internal static void Generate(GaussianBlurElement efoBlur, ref Dx9EffectBuilder effectBuilder)
{
Dx9TextureInfo textureInfo = effectBuilder.GetTextureInfo(effectBuilder.ImageCount - 1);
effectBuilder.AddRequirement(textureInfo, Dx9TextureRequirements.TexelSize, null);
switch (efoBlur.Mode)
{
case GaussianBlurMode.Normal:
int length1 = 1 + efoBlur.KernelRadius * 2;
double[,] arKernel1 = new double[length1, length1];
GenerateWeights2D(efoBlur.KernelRadius, efoBlur.Bluriness, arKernel1);
effectBuilder.EmitPixelFragment(" {\r\n // Gaussian filter\r\n float4 vBlur = 0;\r\n");
for (int index1 = 0; index1 < length1; ++index1)
{
for (int index2 = 0; index2 < length1; ++index2)
{
int num1 = index2 - efoBlur.KernelRadius;
int num2 = index1 - efoBlur.KernelRadius;
if (num1 == 0 && num2 == 0)
effectBuilder.EmitPixelFragment(InvariantString.Format(" vBlur += {0} * {1};\r\n", effectBuilder.PixelShaderOutput, arKernel1[index2, index1]));
else
effectBuilder.EmitPixelFragment(InvariantString.Format(" vBlur += tex2D({0}, {1} + float2({2}.x * {3}, {2}.y * {4})) * {5};\r\n", textureInfo.Sampler, textureInfo.TexCoordInput, textureInfo.TexelSize, num1, num2, arKernel1[index2, index1]));
}
}
effectBuilder.EmitPixelFragment(InvariantString.Format(" {0} = vBlur;\r\n }}\r\n\r\n", effectBuilder.PixelShaderOutput));
break;
case GaussianBlurMode.Horizontal:
case GaussianBlurMode.Vertical:
bool flag = efoBlur.Mode == GaussianBlurMode.Horizontal;
int length2 = 1 + efoBlur.KernelRadius * 2;
double[] arKernel2 = new double[length2];
GenerateWeights1D(efoBlur.KernelRadius, efoBlur.Bluriness, arKernel2);
effectBuilder.EmitPixelFragment(" {\r\n // Gaussian filter\r\n float4 vBlur = 0;\r\n");
for (int index = 0; index < length2; ++index)
{
int num = index - efoBlur.KernelRadius;
if (num == 0)
effectBuilder.EmitPixelFragment(InvariantString.Format(" vBlur += {0} * {1};\r\n", effectBuilder.PixelShaderOutput, arKernel2[index]));
else if (flag)
effectBuilder.EmitPixelFragment(InvariantString.Format(" vBlur += tex2D({0}, {1} + float2({2}.x * {3}, 0)) * {4};\r\n", textureInfo.Sampler, textureInfo.TexCoordInput, textureInfo.TexelSize, num, arKernel2[index]));
else
effectBuilder.EmitPixelFragment(InvariantString.Format(" vBlur += tex2D({0}, {1} + float2(0, {2}.y * {3})) * {4};\r\n", textureInfo.Sampler, textureInfo.TexCoordInput, textureInfo.TexelSize, num, arKernel2[index]));
}
effectBuilder.EmitPixelFragment(InvariantString.Format(" {0} = vBlur;\r\n }}\r\n\r\n", effectBuilder.PixelShaderOutput));
break;
default:
Debug2.Validate(false, typeof(InvalidOperationException), "Unknown blur mode");
break;
}
}
}
}
@@ -0,0 +1,128 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9GraphicsDevice
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Render.Internal;
namespace Microsoft.Iris.Render.Graphics
{
internal abstract class Dx9GraphicsDevice : GraphicsDevice
{
private Dx9EffectManager m_effectManager;
protected Dx9GraphicsDevice(
RenderSession session,
string stDisplayName,
GraphicsDeviceType type,
GraphicsRenderingQuality renderingQuality)
: base(session, stDisplayName)
{
this.m_deviceType = type;
this.m_graphicsCaps = session.GetGraphicsCaps(type);
this.m_renderingQuality = renderingQuality;
if (this.m_renderingQuality != GraphicsRenderingQuality.MinQuality)
{
Dx9GraphicsDevice.PixelShaderProfileType pixelShaderProfile = (Dx9GraphicsDevice.PixelShaderProfileType)this.m_graphicsCaps.PixelShaderProfile;
if ((byte)this.m_graphicsCaps.VertexShaderProfile < 1 || pixelShaderProfile < PixelShaderProfileType.PS_2_0)
this.m_renderingQuality = GraphicsRenderingQuality.MinQuality;
}
this.m_sizeGutterPxl = new Size(1, 1);
this.m_effectManager = new Dx9EffectManager(session, this);
}
protected override void Dispose(bool fInDispose)
{
try
{
if (!fInDispose || this.m_effectManager == null)
return;
this.m_effectManager.Dispose();
this.m_effectManager = null;
}
finally
{
base.Dispose(fInDispose);
}
}
public override bool IsVideoComposited => true;
public override bool CanPlayAnimations => true;
internal Dx9EffectManager EffectManager => this.m_effectManager;
internal string PixelShaderProfile
{
get
{
switch ((byte)this.m_graphicsCaps.PixelShaderProfile)
{
case 0:
return "ps_1_1";
case 1:
return "ps_1_2";
case 2:
return "ps_1_3";
case 3:
return "ps_1_4";
case 4:
return "ps_2_0";
case 5:
return "ps_2_a";
case 6:
return "ps_2_b";
case 7:
return "ps_3_0";
default:
return "ps_1_1";
}
}
}
internal string VertexShaderProfile
{
get
{
switch ((byte)this.m_graphicsCaps.VertexShaderProfile)
{
case 0:
return "vs_1_1";
case 1:
return "vs_2_0";
case 2:
return "vs_2_a";
case 3:
return "vs_3_0";
default:
return "vs_1_1";
}
}
}
public override bool CanPlayAnimationType(AnimationInputType type) => true;
internal override EffectTemplate CreateEffectTemplate(string stName) => new Dx9EffectTemplate(this.m_session, this, stName);
private enum PixelShaderProfileType : byte
{
PS_1_1,
PS_1_2,
PS_1_3,
PS_1_4,
PS_2_0,
PS_2_A,
PS_2_B,
PS_3_0,
}
private enum VertexShaderProfileType : byte
{
VS_1_1,
VS_2_0,
VS_2_A,
VS_3_0,
}
}
}
@@ -0,0 +1,46 @@
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Graphics.Dx9HSLElement
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using Microsoft.Iris.Library;
namespace Microsoft.Iris.Render.Graphics
{
internal class Dx9HSLElement
{
internal static void Generate(HSLElement efoHSL, ref Dx9EffectBuilder effectBuilder)
{
effectBuilder.EmitIncludesFragment("\"HSL.fx\"");
VariableInfo variableInfo1 = new VariableInfo()
{
ID = efoHSL.HueID,
Type = Dx9VariableType.Float,
IsDynamic = efoHSL.IsDynamicProperty("Hue")
};
variableInfo1.Name = variableInfo1.IsDynamic ? effectBuilder.GenerateGlobalVariable(variableInfo1.Type, efoHSL.Name + "Hue") : effectBuilder.GenerateGlobalConstant(variableInfo1.Type, efoHSL.Name + "Hue");
variableInfo1.DefaultValue = efoHSL.Hue;
effectBuilder.AddPropertyVariable(variableInfo1);
VariableInfo variableInfo2 = new VariableInfo()
{
ID = efoHSL.SaturationID,
Type = Dx9VariableType.Float,
IsDynamic = efoHSL.IsDynamicProperty("Saturation")
};
variableInfo2.Name = variableInfo2.IsDynamic ? effectBuilder.GenerateGlobalVariable(variableInfo2.Type, efoHSL.Name + "Saturation") : effectBuilder.GenerateGlobalConstant(variableInfo2.Type, efoHSL.Name + "Saturation");
variableInfo2.DefaultValue = efoHSL.Saturation;
effectBuilder.AddPropertyVariable(variableInfo2);
VariableInfo variableInfo3 = new VariableInfo()
{
ID = efoHSL.LightnessID,
Type = Dx9VariableType.Float,
IsDynamic = efoHSL.IsDynamicProperty("Lightness")
};
variableInfo3.Name = variableInfo3.IsDynamic ? effectBuilder.GenerateGlobalVariable(variableInfo3.Type, efoHSL.Name + "Lightness") : effectBuilder.GenerateGlobalConstant(variableInfo3.Type, efoHSL.Name + "Lightness");
variableInfo3.DefaultValue = efoHSL.Lightness;
effectBuilder.AddPropertyVariable(variableInfo3);
effectBuilder.EmitPixelFragment(InvariantString.Format(" {{\r\n // convert to HSL color space\r\n float3 fHSL = RGBToHSL({0});\r\n\r\n // adjust Hue, Sat and Luma\r\n fHSL *= float3({1}, {2}, {3});\r\n fHSL = saturate(fHSL);\r\n\r\n // convert back to RGB space\r\n float3 fBackToRGB = HSLToRGB(fHSL);\r\n {0}.rgb = fBackToRGB;\r\n }}\r\n", effectBuilder.PixelShaderOutput, variableInfo1.Name, variableInfo2.Name, variableInfo3.Name));
}
}
}

Some files were not shown because too many files have changed in this diff Show More