├── .github └── funding.yml ├── .gitignore ├── LICENSE ├── README.md ├── RES ├── logo.psd └── logo_small.png ├── SharpShader.Core ├── Attributes │ ├── ColumnMajorAttribute.cs │ ├── ComputeGroupSharedAttribute.cs │ ├── ComputeShaderAttribute.cs │ ├── ConstantBufferAttribute.cs │ ├── DomainShaderAttribute.cs │ ├── EntryPointAttribute.cs │ ├── FragmentShaderAttribute.cs │ ├── GeometryShaderAttribute.cs │ ├── GloballyCoherentAttribute.cs │ ├── HullShaderAttribute.cs │ ├── InputPatchAttribute.cs │ ├── Interpolation.cs │ ├── IntrinsicVersionAttribute.cs │ ├── OutputPatchAttribute.cs │ ├── PackOffsetAttribute.cs │ ├── RegisterAttribute.cs │ ├── RegisteredTypeAttribute.cs │ ├── RowMajorAttribute.cs │ ├── SemanticAttribute.cs │ ├── ShaderIntrinsicAttribute.cs │ ├── SharpShaderAttribute.cs │ ├── UnorderedAccessTypeAttribute.cs │ └── VertexShaderAttribute.cs ├── CSharpShader.cs ├── CSharpShader.tt ├── EntryPointType.cs ├── IIntrinsicValue.cs ├── IShaderResource.cs ├── OutputLanguage.cs ├── Properties │ └── AssemblyInfo.cs ├── Resources │ ├── AppendStructuredBuffer.cs │ ├── Buffer.cs │ ├── ByteAddressBuffer.cs │ ├── IRWTextureBase.cs │ ├── ITexture1DBase.cs │ ├── ITexture2DBase.cs │ ├── ITextureBase.cs │ ├── ITextureCubeBase.cs │ ├── RWBuffer.cs │ ├── RWByteAddressBuffer.cs │ ├── RWStructuredBuffer.cs │ ├── RWTexture1D.cs │ ├── RWTexture1DArray.cs │ ├── RWTexture2D.cs │ ├── RWTexture2DArray.cs │ ├── RWTexture3D.cs │ ├── StructuredBuffer.cs │ ├── Texture1D.cs │ ├── Texture1DArray.cs │ ├── Texture2D.cs │ ├── Texture2DArray.cs │ ├── Texture3D.cs │ ├── TextureComparisonSampler.cs │ ├── TextureCube.cs │ ├── TextureCubeArray.cs │ └── TextureSampler.cs ├── Result │ ├── BindPointInfo.cs │ ├── ConstantBufferInfo.cs │ ├── EntryPointInfo.cs │ ├── ShaderElementInfo.cs │ ├── ShaderMember.cs │ ├── ShaderResourceInfo.cs │ ├── ShaderTranslationResult.cs │ └── TranslationResult.cs ├── SemanticType.cs ├── Shader.Geometry.Streams.cs ├── Shader.HullDomain.Enums.cs ├── ShaderDataType.cs ├── ShaderModel.cs ├── ShaderResourceBaseType.cs ├── ShaderResourceType.cs ├── ShaderStructureType.cs ├── SharpShader.Core.csproj ├── SharpShader.Core.nuspec ├── TranslationMessage.cs ├── TypeHelper.cs └── Types │ ├── Bool1x1.cs │ ├── Bool1x2.cs │ ├── Bool1x3.cs │ ├── Bool1x4.cs │ ├── Bool2.cs │ ├── Bool2x1.cs │ ├── Bool2x2.cs │ ├── Bool2x3.cs │ ├── Bool2x4.cs │ ├── Bool3.cs │ ├── Bool3x1.cs │ ├── Bool3x2.cs │ ├── Bool3x3.cs │ ├── Bool3x4.cs │ ├── Bool4.cs │ ├── Bool4x1.cs │ ├── Bool4x2.cs │ ├── Bool4x3.cs │ ├── Bool4x4.cs │ ├── Double1x1.cs │ ├── Double1x2.cs │ ├── Double1x3.cs │ ├── Double1x4.cs │ ├── Double2.cs │ ├── Double2x1.cs │ ├── Double2x2.cs │ ├── Double2x3.cs │ ├── Double2x4.cs │ ├── Double3.cs │ ├── Double3x1.cs │ ├── Double3x2.cs │ ├── Double3x3.cs │ ├── Double3x4.cs │ ├── Double4.cs │ ├── Double4x1.cs │ ├── Double4x2.cs │ ├── Double4x3.cs │ ├── Double4x4.cs │ ├── Int1x1.cs │ ├── Int1x2.cs │ ├── Int1x3.cs │ ├── Int1x4.cs │ ├── Int2.cs │ ├── Int2x1.cs │ ├── Int2x2.cs │ ├── Int2x3.cs │ ├── Int2x4.cs │ ├── Int3.cs │ ├── Int3x1.cs │ ├── Int3x2.cs │ ├── Int3x3.cs │ ├── Int3x4.cs │ ├── Int4.cs │ ├── Int4x1.cs │ ├── Int4x2.cs │ ├── Int4x3.cs │ ├── Int4x4.cs │ ├── Matrices.cs │ ├── Matrices.tt │ ├── Matrices1.cs │ ├── Matrix1x1.cs │ ├── Matrix1x2.cs │ ├── Matrix1x3.cs │ ├── Matrix1x4.cs │ ├── Matrix2x1.cs │ ├── Matrix2x2.cs │ ├── Matrix2x3.cs │ ├── Matrix2x4.cs │ ├── Matrix3x1.cs │ ├── Matrix3x2.cs │ ├── Matrix3x3.cs │ ├── Matrix3x4.cs │ ├── Matrix4x1.cs │ ├── Matrix4x2.cs │ ├── Matrix4x3.cs │ ├── Matrix4x4.cs │ ├── MultipleOutput.cs │ ├── MultipleOutput.tt │ ├── UInt1x1.cs │ ├── UInt1x2.cs │ ├── UInt1x3.cs │ ├── UInt1x4.cs │ ├── UInt2.cs │ ├── UInt2x1.cs │ ├── UInt2x2.cs │ ├── UInt2x3.cs │ ├── UInt2x4.cs │ ├── UInt3.cs │ ├── UInt3x1.cs │ ├── UInt3x2.cs │ ├── UInt3x3.cs │ ├── UInt3x4.cs │ ├── UInt4.cs │ ├── UInt4x1.cs │ ├── UInt4x2.cs │ ├── UInt4x3.cs │ ├── UInt4x4.cs │ ├── Vector2.cs │ ├── Vector3.cs │ ├── Vector4.cs │ ├── Vectors.cs │ └── Vectors.tt ├── SharpShader.sln ├── SharpShader ├── AnalysisInfo.cs ├── EmbeddedResource.cs ├── Exceptions │ └── ScopeException.cs ├── FormattingHelper.cs ├── Interlocker.cs ├── Languages │ ├── GLSL │ │ ├── GlslLanguage.cs │ │ └── lang.xml │ ├── HLSL │ │ ├── HlslLanguage.cs │ │ ├── Translators │ │ │ ├── ComputeTranslator.cs │ │ │ ├── DefaultEntryPointTranslator.cs │ │ │ ├── DomainTranslator.cs │ │ │ ├── GeometryTranslator.cs │ │ │ └── HullTranslator.cs │ │ └── lang.xml │ ├── IEntryPointTranslator.cs │ ├── ShaderLanguage.Modifier.cs │ ├── ShaderLanguage.Translation.cs │ └── ShaderLanguage.cs ├── MappedConstantBuffer.cs ├── MappedEntryPoint.cs ├── MappedField.cs ├── MethodBucket.cs ├── ObjectPool.cs ├── OutputSource.cs ├── Pooling.cs ├── Processors │ ├── ArgumentProcessor.cs │ ├── ArrayRankProcessor.cs │ ├── ArrayTypeProcessor.cs │ ├── ArrowExpressionProcessor.cs │ ├── AssignmentProcessor.cs │ ├── BinaryExpressionProcessor.cs │ ├── BlockProcessor.cs │ ├── ClassProcessor.cs │ ├── EqualsValueClauseProcessor.cs │ ├── FieldProcessor.cs │ ├── GenericWhereProcessor.cs │ ├── IdentifierProcessor.cs │ ├── IfStatementProcessor.cs │ ├── InitializerProcessor.cs │ ├── LiteralExpressionProcessor.cs │ ├── LoopProcessor.cs │ ├── MemberAccessProcessor.cs │ ├── MethodDeclarationProcessor.cs │ ├── NodeProcessor.cs │ ├── ObjectCreationProcessor.cs │ ├── ParameterProcessor.cs │ ├── ParenthesizedExpressionProcessor.cs │ ├── PredefinedTypeProcessor.cs │ ├── PropertyProcessor.cs │ ├── ReturnProcessor.cs │ ├── StatementProcessor.cs │ ├── StructProcessor.cs │ ├── UnaryProcessor.cs │ └── VariableProcessor.cs ├── Properties │ └── AssemblyInfo.cs ├── ScopeInfo.cs ├── ScopeSettings.cs ├── ShaderResource.cs ├── ShaderTranslationContext.cs ├── ShaderType.cs ├── SharpShader.csproj ├── SharpShader.nuspec ├── SourceSegment.cs ├── ThreadSafeList.cs ├── TranslationArgs.cs ├── TranslationContext.ReflectionInfo.cs ├── TranslationContext.cs ├── TranslationFlags.cs ├── TranslationRunner.cs ├── Translator.cs ├── app.config ├── logo.png └── packages.config └── SharpShaderSample ├── App.config ├── FunctionalityTestShader.cs ├── MoltenSpriteShader.cs ├── Program.cs ├── Properties └── AssemblyInfo.cs ├── SampleShader.cs ├── SampleTextureShader.cs └── SharpShaderSample.csproj /.github/funding.yml: -------------------------------------------------------------------------------- 1 | github: [syncaidius] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 James Yarwood 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /RES/logo.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Syncaidius/SharpShader/1f0625e5d40550e1566c1f649afd5a24c95b6ffb/RES/logo.psd -------------------------------------------------------------------------------- /RES/logo_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Syncaidius/SharpShader/1f0625e5d40550e1566c1f649afd5a24c95b6ffb/RES/logo_small.png -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/ColumnMajorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// Flags a matrix field as column-major. 11 | /// 12 | [AttributeUsage(AttributeTargets.Field)] 13 | public class ColumnMajorAttribute : SharpShaderAttribute 14 | { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/ComputeGroupSharedAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// Mark a variable for thread-group-shared memory for compute shaders. 11 | /// In D3D10 the maximum total size of all variables with the groupshared storage class is 16kb, in D3D11 the maximum size is 32kb. See examples. 12 | /// 13 | [AttributeUsage(AttributeTargets.Field)] 14 | public class ComputeGroupSharedAttribute : SharpShaderAttribute 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/ComputeShaderAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [AttributeUsage(AttributeTargets.Method)] 10 | public class ComputeShaderAttribute : EntryPointAttribute 11 | { 12 | public ComputeShaderAttribute(int threadsX, int threadsY, int threadsZ) 13 | { 14 | ThreadsX = threadsX; 15 | ThreadsY = threadsY; 16 | ThreadsZ = threadsZ; 17 | } 18 | 19 | public override EntryPointType EntryType => EntryPointType.ComputeShader; 20 | 21 | public int ThreadsX { get; } 22 | 23 | public int ThreadsY { get; } 24 | 25 | public int ThreadsZ { get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/ConstantBufferAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [AttributeUsage(AttributeTargets.Struct)] 10 | public class ConstantBufferAttribute : SharpShaderAttribute 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/DomainShaderAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [AttributeUsage(AttributeTargets.Method)] 10 | public class DomainShaderAttribute : EntryPointAttribute 11 | { 12 | /// 13 | /// Creates a new instance of 14 | /// 15 | /// The patch type. 16 | public DomainShaderAttribute(PatchType pType) 17 | { 18 | PatchType = pType; 19 | } 20 | 21 | /// 22 | /// Gets the patch type. 23 | /// 24 | public PatchType PatchType { get; } 25 | 26 | public override EntryPointType EntryType => EntryPointType.DomainShader; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/EntryPointAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | public abstract class EntryPointAttribute : SharpShaderAttribute 10 | { 11 | public abstract EntryPointType EntryType { get; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/FragmentShaderAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [AttributeUsage(AttributeTargets.Method)] 10 | public class FragmentShaderAttribute : EntryPointAttribute 11 | { 12 | public override EntryPointType EntryType => EntryPointType.FragmentShader; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/GeometryShaderAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [AttributeUsage(AttributeTargets.Method)] 10 | public class GeometryShaderAttribute : EntryPointAttribute 11 | { 12 | /// 13 | /// 14 | /// 15 | /// 16 | /// The maximum number of output vertices. 17 | public GeometryShaderAttribute(GeometryInputType inType, uint maxVertexOutCount) 18 | { 19 | InputType = inType; 20 | MaxVertexOutCount = maxVertexOutCount; 21 | } 22 | 23 | public GeometryInputType InputType { get; } 24 | 25 | public uint MaxVertexOutCount { get; } 26 | 27 | public override EntryPointType EntryType => EntryPointType.GeometryShader; 28 | } 29 | 30 | public enum GeometryInputType 31 | { 32 | /// 33 | /// Point list. One input vertex required. 34 | /// 35 | Point = 0, 36 | 37 | /// 38 | /// Triangle list or triangle strip. Three input vertices required. 39 | /// 40 | Triangle = 1, 41 | 42 | /// 43 | /// Line list or line strip 44 | /// 45 | Line = 2, 46 | 47 | /// 48 | /// Line list with adjacency or line strip with adjacency. Adjacency lines have two ends; therefore, require four vertices. 49 | /// 50 | LineWithAdjacency = 3, 51 | 52 | /// 53 | /// Triangle list with adjacency or triangle strip with adjacency. Adjacency triangles border with three more triangles; therefore, they requires six input vertices. 54 | /// 55 | TriangleWithAdjacency = 4, 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/GloballyCoherentAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// Flags a read-write buffer as globally coherent, which causes memory barriers and syncs to flush data across the entire GPU such that other groups can see writes. 11 | /// Without this specifier, a memory barrier or sync will flush a UAV only within the current group. 12 | /// 13 | [AttributeUsage(AttributeTargets.Field)] 14 | public class GloballyCoherentAttribute : SharpShaderAttribute 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/HullShaderAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [AttributeUsage(AttributeTargets.Method)] 10 | public class HullShaderAttribute : EntryPointAttribute 11 | { 12 | /// 13 | /// Creates a new instance of 14 | /// 15 | /// The patch type. 16 | /// The tesselation partitioning scheme to be used in the hull shader 17 | /// The expected output topology. 18 | /// The number of output control points. 19 | /// The name of the method used for calculating patch-constant data. 20 | public HullShaderAttribute(PatchType pType, HullPartitioning partition, HullOutputTopology topology, int outputControlPoints, string patchConstantMethodName) 21 | { 22 | PatchType = pType; 23 | Partitioning = partition; 24 | Topology = topology; 25 | OutputControlPoints = outputControlPoints; 26 | PatchConstantCallback = patchConstantMethodName; 27 | } 28 | 29 | /// 30 | /// Gets the patch type. 31 | /// 32 | public PatchType PatchType { get; } 33 | 34 | /// 35 | /// Gets gets the tesselation partitioning scheme to be used in the hull shader. 36 | /// 37 | public HullPartitioning Partitioning { get; } 38 | 39 | /// 40 | /// Gets the expected output topology. 41 | /// 42 | public HullOutputTopology Topology { get; } 43 | 44 | /// 45 | /// Gets the number of output control points. 46 | /// 47 | public int OutputControlPoints { get; } 48 | 49 | /// 50 | /// Gets the callback used for calculating patch-constant data. 51 | /// 52 | public string PatchConstantCallback { get; } 53 | 54 | public override EntryPointType EntryType => EntryPointType.HullShader; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/InputPatchAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | public class InputPatchAttribute : SharpShaderAttribute 10 | { 11 | /// 12 | /// Gets the size. 13 | /// 14 | public uint Size { get; } 15 | 16 | public InputPatchAttribute(uint size) 17 | { 18 | Size = size; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/Interpolation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [AttributeUsage(AttributeTargets.Field)] 10 | public class InterpolationAttribute : SharpShaderAttribute 11 | { 12 | public static readonly InterpolationMode[] ModeValues; 13 | 14 | static InterpolationAttribute() 15 | { 16 | ModeValues = (InterpolationMode[])Enum.GetValues(typeof(InterpolationMode)); 17 | } 18 | 19 | public InterpolationAttribute(InterpolationMode mode = InterpolationMode.Linear) 20 | { 21 | Flags = mode; 22 | } 23 | 24 | public InterpolationMode Flags { get; } 25 | } 26 | 27 | [Flags] 28 | public enum InterpolationMode 29 | { 30 | None = 0, 31 | 32 | Linear = 1, 33 | 34 | Centroid = 2, 35 | 36 | NoInterpolation = 4, 37 | 38 | NoPerspective = 8, 39 | 40 | Sample = 16, 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/IntrinsicVersionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] 10 | public class IntrinsicVersionAttribute : SharpShaderAttribute 11 | { 12 | public IntrinsicPipelineType Piepline { get; } 13 | public float MinVersion { get; } 14 | public float MaxVersion { get; } 15 | 16 | public IntrinsicVersionAttribute(IntrinsicPipelineType pipeline, float minVersion = float.MinValue, float maxVersion = float.MaxValue) 17 | { 18 | Piepline = pipeline; 19 | MinVersion = minVersion; 20 | MaxVersion = maxVersion; 21 | } 22 | } 23 | 24 | public enum IntrinsicPipelineType 25 | { 26 | Vertex = 0, 27 | 28 | Geometry = 1, 29 | 30 | Hull = 2, 31 | 32 | Domain = 3, 33 | 34 | Fragment = 4, 35 | 36 | Compute = 5, 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/OutputPatchAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | public class OutputPatchAttribute : SharpShaderAttribute 10 | { 11 | /// 12 | /// Gets the size. 13 | /// 14 | public uint Size { get; } 15 | 16 | public OutputPatchAttribute(uint size) 17 | { 18 | Size = size; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/PackOffsetAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [AttributeUsage(AttributeTargets.Field)] 10 | public class PackOffsetAttribute : SharpShaderAttribute 11 | { 12 | public PackOffsetComponent OffsetComponent { get; } 13 | 14 | public int OffsetRegister { get; } 15 | 16 | public PackOffsetAttribute(int offsetRegister, PackOffsetComponent offsetComponent = PackOffsetComponent.X) 17 | { 18 | OffsetRegister = offsetRegister; 19 | OffsetComponent = offsetComponent; 20 | } 21 | } 22 | 23 | public enum PackOffsetComponent 24 | { 25 | /// 26 | /// The field will be offset from the start of the register by 0 bytes. 27 | /// 28 | X = 0, 29 | 30 | /// 31 | /// The field will be offset from the start of the register by 4 bytes. 32 | /// 33 | Y = 1, 34 | 35 | /// 36 | /// The field will be offset from the start of the register by 8 bytes. 37 | /// 38 | Z = 2, 39 | 40 | /// 41 | /// The field will be offset from the start of the register by 12 bytes. 42 | /// 43 | W = 3, 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/RegisterAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// Specifies the register or slot ID for a field or constant buffer structure. 11 | /// Multiple register attributes can be used to specify different slots for different stages of the shader pipeline, on the same object. 12 | /// 13 | [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Field, AllowMultiple = true)] 14 | public class RegisterAttribute : SharpShaderAttribute 15 | { 16 | /// 17 | /// Gets the register or slot ID. 18 | /// 19 | public uint Slot { get; } 20 | 21 | /// 22 | /// The shader model to use if is set to a value greater than . The default value is . 23 | /// 24 | public ShaderModel Model { get; } 25 | 26 | /// 27 | /// The shader profile/stage that the register binding applies to. 28 | /// 29 | public EntryPointType ApplicableEntryPoint { get; } 30 | 31 | /// 32 | /// Creates a new instance of . 33 | /// 34 | /// 35 | /// The target shader profile of the register. 36 | /// The target shader model of the register. 37 | public RegisterAttribute(uint slot, EntryPointType entryPoint = EntryPointType.AnyOrNone, ShaderModel model = ShaderModel.SM_5_0) 38 | { 39 | Slot = slot; 40 | Model = ShaderModel.SM_5_0; 41 | ApplicableEntryPoint = EntryPointType.AnyOrNone; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/RegisteredTypeAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// Used for tagging types as compatible with . 11 | /// 12 | [AttributeUsage(AttributeTargets.Interface, Inherited = true)] 13 | internal class RegisteredTypeAttribute : SharpShaderAttribute { } 14 | } 15 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/RowMajorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// Flags a matrix field as row-major. 11 | /// 12 | [AttributeUsage(AttributeTargets.Field)] 13 | public class RowMajorAttribute : SharpShaderAttribute 14 | { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/SemanticAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Method)] 10 | public class SemanticAttribute : SharpShaderAttribute 11 | { 12 | public SemanticType Semantic { get; } 13 | public int Slot { get; } 14 | 15 | public SemanticAttribute(SemanticType semantic, int slot = -1) 16 | { 17 | Semantic = semantic; 18 | Slot = slot; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/ShaderIntrinsicAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] 10 | public class ShaderIntrinsicAttribute : SharpShaderAttribute 11 | { 12 | /// 13 | /// 14 | /// 15 | /// The shader language that the intrinsic belongs to. 16 | /// The name of the intrinsic in it's native shader language. 17 | internal ShaderIntrinsicAttribute(OutputLanguage language, string name) 18 | { 19 | Language = language; 20 | NativeName = name; 21 | } 22 | 23 | /// 24 | /// Gets the shader language that the intrinsic is part of. 25 | /// 26 | public OutputLanguage Language { get; } 27 | 28 | /// 29 | /// Gets the name of the intrinsic function in it's native shader language. 30 | /// 31 | public string NativeName { get; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/SharpShaderAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | public abstract class SharpShaderAttribute : Attribute 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/UnorderedAccessTypeAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [AttributeUsage(AttributeTargets.Interface)] 10 | internal class UnorderedAccessTypeAttribute : SharpShaderAttribute 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /SharpShader.Core/Attributes/VertexShaderAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [AttributeUsage(AttributeTargets.Method)] 10 | public class VertexShaderAttribute : EntryPointAttribute 11 | { 12 | public override EntryPointType EntryType => EntryPointType.VertexShader; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /SharpShader.Core/EntryPointType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | public enum EntryPointType 10 | { 11 | AnyOrNone = 0, 12 | 13 | VertexShader = 1, 14 | 15 | FragmentShader = 2, 16 | 17 | GeometryShader = 3, 18 | 19 | HullShader = 4, 20 | 21 | DomainShader = 5, 22 | 23 | ComputeShader = 6, 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /SharpShader.Core/IIntrinsicValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | public interface IIntrinsicValue { } 10 | 11 | public interface IIntrinsicValue : IIntrinsicValue 12 | where T : struct { } 13 | 14 | public interface UniformDimensions { } 15 | 16 | public interface IVector : IIntrinsicValue { } 17 | 18 | public interface IVector : IVector, IIntrinsicValue 19 | where T : struct { } 20 | 21 | public interface IMatrix : IIntrinsicValue { } 22 | 23 | public interface IMatrix : IMatrix, IIntrinsicValue 24 | where T : struct { } 25 | } 26 | -------------------------------------------------------------------------------- /SharpShader.Core/IShaderResource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | public interface IShaderResource { } 10 | } 11 | -------------------------------------------------------------------------------- /SharpShader.Core/OutputLanguage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// Represents the shader languages which SharpShader supports when translating from C# shader source. 11 | /// 12 | public enum OutputLanguage 13 | { 14 | Invalid = 0, 15 | 16 | /// 17 | /// The input C# code will be output to DirectX high-level shader language (HLSL). 18 | /// 19 | HLSL = 1, 20 | 21 | /// 22 | /// The input C# code will be output to GL shader language (GLSL). 23 | /// 24 | GLSL = 2, 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /SharpShader.Core/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SharpShader.Core")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SharpShader.Core")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("4648b160-6149-4308-aa40-a229c7b9c1ce")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("0.0.6.0")] 36 | [assembly: AssemblyFileVersion("0.0.6.0")] 37 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/AppendStructuredBuffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// A read-only buffer that indexes in bytes. 11 | /// 12 | /// The type of data to store in the buffer. 13 | [RegisteredType] 14 | [UnorderedAccessType] 15 | public interface AppendStructuredBuffer : IShaderResource 16 | { 17 | /// 18 | /// Gets the length of the buffer. 19 | /// 20 | /// The number of structures. 21 | /// The number of bytes in each element. 22 | void GetDimensions(out uint numStructs, out uint stride); 23 | 24 | /// 25 | /// 26 | /// 27 | /// 28 | void Append(T value); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/Buffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// A read-only buffer. 11 | /// 12 | /// The type of data to store in the buffer. 13 | [RegisteredType] 14 | [UnorderedAccessType] 15 | public interface Buffer : IShaderResource where T : struct 16 | { 17 | /// 18 | /// Gets the length of the buffer. 19 | /// 20 | /// An output for the dimensions. 21 | void GetDimensions(out uint dim); 22 | 23 | /// 24 | /// Reads buffer data and returns status of the operation 25 | /// 26 | /// The location (index) in the buffer. 27 | /// An output for the status result. 28 | /// 29 | T Load(int location, out uint status); 30 | 31 | /// 32 | /// Reads buffer data. 33 | /// 34 | /// The location (index) in the buffer. 35 | /// 36 | T Load(int location); 37 | 38 | /// 39 | /// Gets the value at the specified index. 40 | /// 41 | /// The element index. 42 | /// 43 | T this[uint index] { get; } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/IRWTextureBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | public interface IRWTextureBase : IShaderResource 10 | { 11 | /// 12 | /// Reads texture data from a RWTexture2D. 13 | /// 14 | /// The texel to load. Contains the XY coordinate and mip map level (0 being the highest resolution mip-map). 15 | /// 16 | T Load(LOC location); 17 | 18 | /// 19 | /// Reads texture data from a RWTexture2D. 20 | /// 21 | /// The texel to load. Contains the XY coordinate and mip map level (0 being the highest resolution mip-map). 22 | /// 23 | T Load(LOC location, out uint status); 24 | 25 | /// 26 | /// The index position. Contains the (x, y, z) coordinates. 27 | /// 28 | T this[INDEXER pos] { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/RWBuffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// A read/write buffer. 11 | /// 12 | /// The type of data to store in the buffer. 13 | [RegisteredType] 14 | [UnorderedAccessType] 15 | public interface RWBuffer : IShaderResource where T : struct 16 | { 17 | /// 18 | /// Gets the length of the buffer. 19 | /// 20 | /// An output for the dimensions. 21 | void GetDimensions(out uint dim); 22 | 23 | /// 24 | /// Reads buffer data and returns status of the operation 25 | /// 26 | /// The location (index) in the buffer. 27 | /// An output for the status result. 28 | /// 29 | T Load(int location, out uint status); 30 | 31 | /// 32 | /// Reads buffer data. 33 | /// 34 | /// The location (index) in the buffer. 35 | /// 36 | T Load(int location); 37 | 38 | /// 39 | /// Gets or sets the value at the specified index. 40 | /// 41 | /// The element index. 42 | /// 43 | T this[uint index] { get; set; } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/RWTexture1D.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// A read/write (RW) Texture2D object. 11 | /// Based on HLSL syntax: https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/sm5-object-rwtexture1d 12 | /// 13 | [RegisteredType] 14 | [UnorderedAccessType] 15 | public interface RWTexture1D : IRWTextureBase 16 | where T : struct 17 | { 18 | void GetDimensions(out uint width); 19 | 20 | void GetDimensions(out float width); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/RWTexture1DArray.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// A read/write (RW) Texture2D array. 11 | /// Based on HLSL syntax: https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/sm5-object-rwtexture1darray 12 | /// 13 | [RegisteredType] 14 | [UnorderedAccessType] 15 | public interface RWTexture1DArray : IRWTextureBase 16 | where T : struct 17 | { 18 | void GetDimensions(out uint width, out uint height, out uint elements); 19 | 20 | void GetDimensions(out float width, out float height, out float elements); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/RWTexture2D.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// A read/write (RW) Texture2D object. 11 | /// Based on HLSL syntax: https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/sm5-object-rwtexture2d 12 | /// 13 | [RegisteredType] 14 | [UnorderedAccessType] 15 | public interface RWTexture2D : IRWTextureBase 16 | where T : struct 17 | { 18 | void GetDimensions(out uint width, out uint height); 19 | 20 | void GetDimensions(out float width, out float height); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/RWTexture2DArray.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// A read/write (RW) Texture2D array. 11 | /// Based on HLSL syntax: https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/sm5-object-rwtexture2darray 12 | /// 13 | [RegisteredType] 14 | [UnorderedAccessType] 15 | public interface RWTexture2DArray : IRWTextureBase 16 | where T : struct 17 | { 18 | void GetDimensions(out uint width, out uint height, out uint elements); 19 | 20 | void GetDimensions(out float width, out float height, out float elements); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/RWTexture3D.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// A read/write (RW) Texture2D object. 11 | /// Based on HLSL syntax: https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/sm5-object-rwtexture2d 12 | /// 13 | [RegisteredType] 14 | [UnorderedAccessType] 15 | public interface RWTexture3D : IRWTextureBase 16 | where T : struct 17 | { 18 | void GetDimensions(out uint width, out uint height, out uint depth); 19 | 20 | void GetDimensions(out float width, out float height, out float depth); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/StructuredBuffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// A read-only structured buffer. 11 | /// 12 | /// The type of data to store in the buffer. 13 | public interface StructuredBuffer : IShaderResource where T : struct 14 | { 15 | /// 16 | /// Gets the value at the specified index. 17 | /// 18 | /// The element index. 19 | /// 20 | T this[uint index] { get; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/Texture1D.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | public interface Texture1D : Texture1D{} 10 | 11 | public interface Texture1D : ITexture1DBase 12 | where T : struct 13 | { 14 | void GetDimensions(out uint mipMapLevel, out uint width, out uint numberOfLevels); 15 | 16 | void GetDimensions(out uint width); 17 | 18 | void GetDimensions(out float mipMapLevel, out float width, out float numberOfLevels); 19 | 20 | void GetDimensions(out float width); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/Texture1DArray.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | public interface Texture1DArray : Texture1DArray { } 10 | 11 | public interface Texture1DArray : ITexture1DBase 12 | where T : struct 13 | { 14 | void GetDimensions(out uint mipMapLevel, out uint width, out uint elements, out uint numberOfLevels); 15 | 16 | void GetDimensions(out uint width, out uint elements); 17 | 18 | void GetDimensions(out float mipMapLevel, out float width, out float elements, out float numberOfLevels); 19 | 20 | void GetDimensions(out float width, out float elements); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/Texture2D.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [RegisteredType] 10 | public interface Texture2D : Texture2D { } 11 | 12 | /// 13 | /// An untyped texture object for backwards compatibility. 14 | /// Based on HLSL syntax: https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/sm5-object-texture2d 15 | /// 16 | [RegisteredType] 17 | public interface Texture2D : ITexture2DBase 18 | where T : struct 19 | { 20 | /// 21 | /// Gets the dimensions of a mipmap. 22 | /// 23 | /// The mip-map level to retrieve dimensions from. 24 | /// 25 | /// 26 | /// The number of mipmap levels (requires mipLevel also). 27 | void GetDimensions(uint mipLevel, out uint width, out uint height, out uint numberOfLevels); 28 | 29 | /// 30 | /// Gets the dimensions of the texture's first mipmap (usually the highest-resolution mipmap). 31 | /// 32 | /// 33 | /// 34 | void GetDimensions(out uint width, out uint height); 35 | 36 | /// 37 | /// Gets the dimensions of a mipmap. 38 | /// 39 | /// The mip-map level to retrieve dimensions from. 40 | /// 41 | /// 42 | /// The number of mipmap levels (requires mipLevel also). 43 | void GetDimensions(uint mipLevel, out float width, out float height, out float numberOfLevels); 44 | 45 | /// 46 | /// Gets the dimensions of the texture's first mipmap (usually the highest-resolution mipmap). 47 | /// 48 | /// 49 | /// 50 | void GetDimensions(out float width, out float height); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/Texture3D.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [RegisteredType] 10 | public interface Texture3D : Texture3D { } 11 | 12 | [RegisteredType] 13 | public interface Texture3D : ITextureBaseSampled 14 | where T : struct 15 | { 16 | /// 17 | /// Samples a texture, using a comparison value to reject samples. 18 | /// 19 | /// 20 | /// 21 | /// 22 | /// 23 | T SampleCmp(TextureSampler sampler, Vector3 location, float compareValue); 24 | 25 | /// 26 | /// Samples a texture, using a comparison value to reject samples. 27 | /// 28 | /// 29 | /// 30 | /// 31 | /// 32 | /// 33 | T SampleCmp(TextureSampler sampler, Vector3 location, float compareValue, Int3 offset); 34 | 35 | /// 36 | /// Samples a texture, using a comparison value to reject samples. 37 | /// 38 | /// 39 | /// 40 | /// 41 | /// 42 | /// 43 | /// 44 | T SampleCmp(TextureSampler sampler, Vector3 location, float compareValue, Int3 offset, float clamp); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/TextureComparisonSampler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [RegisteredType] 10 | public interface TextureComparisonSampler : TextureSampler { } 11 | } 12 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/TextureCube.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [RegisteredType] 10 | public interface TextureCube : Texture2D { } 11 | 12 | /// 13 | /// An untyped texture object for backwards compatibility. 14 | /// Based on HLSL syntax: https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/sm5-object-texture2d 15 | /// 16 | [RegisteredType] 17 | public interface TextureCube : ITextureCubeBase 18 | where T : struct 19 | { 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/TextureCubeArray.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [RegisteredType] 10 | public interface TextureCubeArray : Texture2D { } 11 | 12 | /// 13 | /// An untyped texture object for backwards compatibility. 14 | /// Based on HLSL syntax: https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/sm5-object-texture2d 15 | /// 16 | [RegisteredType] 17 | public interface TextureCubeArray : ITextureCubeBase 18 | where T : struct 19 | { 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SharpShader.Core/Resources/TextureSampler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [RegisteredType] 10 | public interface TextureSampler : IShaderResource { } 11 | } 12 | -------------------------------------------------------------------------------- /SharpShader.Core/Result/BindPointInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// Contains metadata for a shader resource bind point, also known as a resource slot. 11 | /// 12 | [Serializable] 13 | public readonly struct BindPointInfo 14 | { 15 | /// 16 | /// Gets the shader model with which the bind point should be used. 17 | /// 18 | public readonly ShaderModel Model; 19 | 20 | /// 21 | /// Gets the entry-point for which the bind point should be used. 22 | /// 23 | public readonly EntryPointType EntryPoint; 24 | 25 | /// 26 | /// Gets the bind point value. 27 | /// 28 | public readonly int BindPoint; 29 | 30 | public BindPointInfo(ShaderModel model, EntryPointType epType, int bindPoint) 31 | { 32 | Model = model; 33 | EntryPoint = epType; 34 | BindPoint = bindPoint; 35 | } 36 | 37 | public override int GetHashCode() 38 | { 39 | return BindPoint | ((int)EntryPoint << 16) | ((int)Model << 24); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /SharpShader.Core/Result/ConstantBufferInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SharpShader 9 | { 10 | public class ConstantBufferInfo : ShaderResourceInfo 11 | { 12 | /// 13 | /// Gets the total size of the constant buffer, in bytes. 14 | /// 15 | public int SizeOf { get; } 16 | 17 | /// 18 | /// Gets a list containing all of the variables held in the constant buffer. 19 | /// 20 | public IReadOnlyList Variables { get; } 21 | 22 | public ConstantBufferInfo(string name, List variables, HashSet bindPoints) : 23 | base(name, ShaderResourceType.ConstantBuffer, bindPoints) 24 | { 25 | Variables = variables.AsReadOnly(); 26 | SizeOf = 0; 27 | 28 | foreach(ShaderMember m in variables) 29 | SizeOf += m.SizeOf; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /SharpShader.Core/Result/ShaderElementInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// Represents an element within a shader. 11 | /// 12 | public class ShaderElementInfo 13 | { 14 | /// 15 | /// Gets the total size of the element. 16 | /// 17 | public int SizeOf { get; } 18 | 19 | /// 20 | /// Gets the number of sub-elements within the current element. 21 | /// 22 | public int SubElementCount { get; } 23 | 24 | /// 25 | /// Gets the size of an individual sub-element, in bytes. 26 | /// 27 | public int SubElementSizeOf { get; } 28 | 29 | /// 30 | /// Gets a read-only list containing the dimensions of the element. 31 | /// For vectors, this contains only the number of components. 32 | /// For matrices, this contains the number of rows followed by the number of columns. 33 | /// For arrays, this contains the length of each dimension in the order they were originally declared. 34 | /// 35 | public IReadOnlyList Dimensions { get; } 36 | 37 | /// 38 | /// Gets the primitive data type of the current . 39 | /// 40 | public ShaderDataType DataType { get; } 41 | 42 | /// 43 | /// Gets the structure of the element. e.g. A scalar, vector, matrix, etc. 44 | /// 45 | public ShaderStructureType StructureType { get; } 46 | 47 | public ShaderElementInfo(ShaderDataType dataType, List dimensions, int size, int subElementCount, int subElementSize, ShaderStructureType strucType) 48 | { 49 | DataType = dataType; 50 | Dimensions = dimensions.AsReadOnly(); 51 | SizeOf = size; 52 | SubElementCount = subElementCount; 53 | SubElementSizeOf = subElementSize; 54 | StructureType = strucType; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /SharpShader.Core/Result/ShaderResourceInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// Respresents a resource binding within a shader. 11 | /// 12 | public class ShaderResourceInfo 13 | { 14 | /// 15 | /// Gets the expected resource type. 16 | /// 17 | public ShaderResourceType ResourceType { get; } 18 | 19 | /// 20 | /// Gets the model-specific bind points (slots) for the constant buffer. 21 | /// 22 | public IReadOnlyList BindPoints { get; } 23 | 24 | /// 25 | /// Gets the name of the resource variable. 26 | /// 27 | public string Name { get; } 28 | 29 | internal ShaderResourceInfo(string name, ShaderResourceType type, HashSet bindPoints) 30 | { 31 | ResourceType = type; 32 | Name = name; 33 | 34 | var bSlots = new List(bindPoints); 35 | BindPoints = bSlots.AsReadOnly(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /SharpShader.Core/Result/TranslationResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Collections.ObjectModel; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SharpShader 10 | { 11 | /// 12 | /// A container for the results of shader translations. 13 | /// 14 | public class TranslationResult : IEnumerable> 15 | { 16 | /// 17 | /// Creates a new instance of . 18 | /// 19 | /// The messages to be associated with the current . 20 | /// The translation output to be associated with the current . 21 | public TranslationResult(List messages, Dictionary output) 22 | { 23 | Messages = messages.AsReadOnly(); 24 | Output = new ReadOnlyDictionary(output); 25 | } 26 | 27 | /// 28 | /// Gets a dictionary containing the translation results for each shader, with their name as a key. 29 | /// 30 | public ReadOnlyDictionary Output { get; } 31 | 32 | /// 33 | /// Gets a list of messages that occurred during translation. 34 | /// 35 | public IReadOnlyList Messages { get; } 36 | 37 | /// 38 | /// Gets an enumerator for the current instance. 39 | /// 40 | /// An enumerator. 41 | public IEnumerator> GetEnumerator() 42 | { 43 | return Output.GetEnumerator(); 44 | } 45 | 46 | /// 47 | /// Gets an enumerator for the current instance. 48 | /// 49 | /// An enumerator. 50 | IEnumerator IEnumerable.GetEnumerator() 51 | { 52 | return Output.GetEnumerator(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /SharpShader.Core/Shader.Geometry.Streams.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | public abstract class GeometryShaderOutStream where T : struct 10 | { 11 | /// 12 | /// Appends geometry-shader-output data to an existing stream. 13 | /// 14 | /// 15 | public void Append(T value) { } 16 | 17 | public void RestartStrip() { } 18 | } 19 | /// 20 | /// Represents a geometry shader line data output stream. 21 | /// 22 | public class LineStream : GeometryShaderOutStream where T : struct { } 23 | 24 | /// 25 | /// Represents a geometry shader triangle data output stream. 26 | /// 27 | public class TriangleStream : GeometryShaderOutStream where T : struct { } 28 | 29 | /// 30 | /// Represents a geometry shader point data output stream. 31 | /// 32 | public class PointStream : GeometryShaderOutStream where T : struct { } 33 | } 34 | -------------------------------------------------------------------------------- /SharpShader.Core/Shader.HullDomain.Enums.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// The patch type of a hull or domain shader. 11 | /// 12 | public enum PatchType 13 | { 14 | Triangle = 0, 15 | 16 | Quad = 1, 17 | 18 | Isoline = 2, 19 | } 20 | 21 | /// 22 | /// The partitioning of a hull shader. 23 | /// 24 | public enum HullPartitioning 25 | { 26 | Integer = 0, 27 | 28 | FractionalEven = 1, 29 | 30 | FractionalOdd = 2, 31 | 32 | PowerOfTwo = 3, 33 | } 34 | 35 | public enum HullOutputTopology 36 | { 37 | Point = 0, 38 | 39 | Line = 1, 40 | 41 | /// 42 | /// Clockwise triangle. 43 | /// 44 | TriangleCW = 2, 45 | 46 | /// 47 | /// Counter-clockwise triangle. 48 | /// 49 | TriangleCCW = 3, 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /SharpShader.Core/ShaderDataType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | /// 10 | /// An element's primitive data type. 11 | /// 12 | public enum ShaderDataType 13 | { 14 | /// 15 | /// The data type is unknown. 16 | /// 17 | Unknown = 0, 18 | 19 | /// 20 | /// A boolean value, usually equivilent to 1 byte in size. 21 | /// 22 | Boolean = 1, 23 | 24 | /// 25 | /// A signed byte. 8-bit value. 26 | /// 27 | Int8 = 7, 28 | 29 | /// 30 | /// An unsigned byte. 8-bit value. 31 | /// 32 | UInt8 = 8, 33 | 34 | /// 35 | /// A signed 16-bit integer. 36 | /// 37 | Int16 = 9, 38 | 39 | /// 40 | /// An unsigned 16-bit integer. 41 | /// 42 | UInt16 = 10, 43 | 44 | /// 45 | /// A signed 32-bit integer. 46 | /// 47 | Int32 = 11, 48 | 49 | /// 50 | /// An unsigned 32-bit integer. 51 | /// 52 | UInt32 = 12, 53 | 54 | /// 55 | /// A signed, 64-bit integer. 56 | /// 57 | Int64 = 13, 58 | 59 | /// 60 | /// An unsigned 64-bit integer. 61 | /// 62 | UInt64 = 14, 63 | 64 | /// 65 | /// A 32-bit signed floating-point value. 66 | /// 67 | Float = 15, 68 | 69 | /// 70 | /// A 64-bit signed floating-point value. 71 | /// 72 | Double = 16, 73 | 74 | /// 75 | /// A 128-bit signed floating-point value. 76 | /// 77 | Decimal = 17, 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /SharpShader.Core/ShaderModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | public enum ShaderModel 10 | { 11 | Default = 0, 12 | 13 | SM_4_0 = 1, 14 | 15 | SM_4_1 = 2, 16 | 17 | SM_5_0 = 3, 18 | 19 | SM_5_1 = 4, 20 | 21 | SM_6_0 = 5, 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SharpShader.Core/ShaderResourceBaseType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | public enum ShaderResourceBaseType 10 | { 11 | Unknown = 0, 12 | 13 | Texture = 1, 14 | 15 | RWTexture = 2, 16 | 17 | Buffer = 3, 18 | 19 | RWBuffer = 4, 20 | 21 | Sampler = 5, 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SharpShader.Core/ShaderStructureType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | public enum ShaderStructureType 10 | { 11 | Unknown = 0, 12 | 13 | Scalar = 1, 14 | 15 | Vector = 2, 16 | 17 | MatrixRowMajor = 3, 18 | 19 | MatrixColumnMajor = 4, 20 | 21 | /// 22 | /// Uses the default matrix major layout. Both HLSL and GLSL uses column-major by default, but that can be inverted via '#pragmapack_matrix row_major' in HLSL. 23 | /// 24 | MatrixDefaultMajor = 5, 25 | 26 | Class = 6, 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /SharpShader.Core/SharpShader.Core.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SharpShader.Core 5 | 0.0.6-alpha 6 | James Yarwood 7 | James Yarwood 8 | https://github.com/Syncaidius/SharpShader/blob/master/LICENSE 9 | https://github.com/Syncaidius/SharpShader 10 | https://github.com/Syncaidius/SharpShader/blob/master/SharpShader/logo.png?raw=true 11 | true 12 | All of the core types for SharpShader. 13 | 14 | Contains everything you need to read SharpShader translation results, without requiring all of the extra dependencies. 15 | Moved all shader-related types from SharpShader to SharpShader.Core. 16 | Copyright © 2019 James Yarwood 17 | Shaders HLSL GLSL Translator Source Game Shader C# CSharp Intermediate Converter 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /SharpShader.Core/TranslationMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [Serializable] 10 | public struct TranslationMessage 11 | { 12 | /// 13 | /// The error message. 14 | /// 15 | public string Text { get; set; } 16 | 17 | /// 18 | /// The line number of the error. 19 | /// 20 | public int LineNumber { get; set; } 21 | 22 | /// 23 | /// The character position along the at which the error is located. 24 | /// 25 | public int LinePosition { get; set; } 26 | 27 | public TranslationMessageType MessageType { get; set; } 28 | } 29 | 30 | public enum TranslationMessageType 31 | { 32 | Message = 0, 33 | 34 | Error = 1, 35 | 36 | Warning = 2, 37 | 38 | Status = 3, 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /SharpShader.Core/TypeHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader.Core 8 | { 9 | public static class TypeHelper 10 | { 11 | public static bool IsRegisteredType(Type t) 12 | { 13 | object[] attributes = t.GetCustomAttributes(typeof(RegisteredTypeAttribute), false); 14 | return attributes.Length > 0; 15 | } 16 | 17 | public static bool IsUnorderedAccessType(Type t) 18 | { 19 | object[] attributes = t.GetCustomAttributes(typeof(UnorderedAccessTypeAttribute), false); 20 | return attributes.Length > 0; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Bool1x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Bool1x1 : IMatrix, UniformDimensions 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(bool); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(bool); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public bool M11; 42 | 43 | /// 44 | /// Creates a new instance of . 45 | /// 46 | public Bool1x1(bool m11) 47 | { 48 | M11 = m11; 49 | } 50 | 51 | /// 52 | /// Gets or sets a component at the specified index for the current . 53 | /// 54 | public bool[] this[int index] 55 | { 56 | get => null; 57 | set {} 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Bool1x2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 2 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Bool1x2 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 2; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(bool); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(bool); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public bool M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public bool M12; 47 | 48 | /// 49 | /// Creates a new instance of . 50 | /// 51 | public Bool1x2(bool m11, bool m12) 52 | { 53 | M11 = m11; 54 | M12 = m12; 55 | } 56 | 57 | /// 58 | /// Gets or sets a component at the specified index for the current . 59 | /// 60 | public bool[] this[int index] 61 | { 62 | get => null; 63 | set {} 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Bool1x3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 3 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Bool1x3 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 3; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(bool); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(bool); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public bool M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public bool M12; 47 | 48 | /// 49 | /// The value at row 1, column 3 of the matrix. 50 | /// 51 | public bool M13; 52 | 53 | /// 54 | /// Creates a new instance of . 55 | /// 56 | public Bool1x3(bool m11, bool m12, bool m13) 57 | { 58 | M11 = m11; 59 | M12 = m12; 60 | M13 = m13; 61 | } 62 | 63 | /// 64 | /// Gets or sets a component at the specified index for the current . 65 | /// 66 | public bool[] this[int index] 67 | { 68 | get => null; 69 | set {} 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Bool1x4.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 4 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Bool1x4 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 4; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(bool); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(bool); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public bool M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public bool M12; 47 | 48 | /// 49 | /// The value at row 1, column 3 of the matrix. 50 | /// 51 | public bool M13; 52 | 53 | /// 54 | /// The value at row 1, column 4 of the matrix. 55 | /// 56 | public bool M14; 57 | 58 | /// 59 | /// Creates a new instance of . 60 | /// 61 | public Bool1x4(bool m11, bool m12, bool m13, bool m14) 62 | { 63 | M11 = m11; 64 | M12 = m12; 65 | M13 = m13; 66 | M14 = m14; 67 | } 68 | 69 | /// 70 | /// Gets or sets a component at the specified index for the current . 71 | /// 72 | public bool[] this[int index] 73 | { 74 | get => null; 75 | set {} 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Bool2x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 2 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Bool2x1 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 2; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(bool); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(bool); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public bool M11; 42 | 43 | /// 44 | /// The value at row 2, column 1 of the matrix. 45 | /// 46 | public bool M21; 47 | 48 | /// 49 | /// Creates a new instance of . 50 | /// 51 | public Bool2x1(bool m11, bool m21) 52 | { 53 | M11 = m11; 54 | M21 = m21; 55 | } 56 | 57 | /// 58 | /// Gets or sets a component at the specified index for the current . 59 | /// 60 | public bool[] this[int index] 61 | { 62 | get => null; 63 | set {} 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Bool2x2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 2 row, 2 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Bool2x2 : IMatrix, UniformDimensions 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 2; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 2; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(bool); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(bool); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public bool M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public bool M12; 47 | 48 | /// 49 | /// The value at row 2, column 1 of the matrix. 50 | /// 51 | public bool M21; 52 | 53 | /// 54 | /// The value at row 2, column 2 of the matrix. 55 | /// 56 | public bool M22; 57 | 58 | /// 59 | /// Creates a new instance of . 60 | /// 61 | public Bool2x2(bool m11, bool m21, bool m12, bool m22) 62 | { 63 | M11 = m11; 64 | M12 = m12; 65 | M21 = m21; 66 | M22 = m22; 67 | } 68 | 69 | /// 70 | /// Gets or sets a component at the specified index for the current . 71 | /// 72 | public bool[] this[int index] 73 | { 74 | get => null; 75 | set {} 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Bool2x3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 2 row, 3 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Bool2x3 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 2; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 3; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(bool); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(bool); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public bool M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public bool M12; 47 | 48 | /// 49 | /// The value at row 1, column 3 of the matrix. 50 | /// 51 | public bool M13; 52 | 53 | /// 54 | /// The value at row 2, column 1 of the matrix. 55 | /// 56 | public bool M21; 57 | 58 | /// 59 | /// The value at row 2, column 2 of the matrix. 60 | /// 61 | public bool M22; 62 | 63 | /// 64 | /// The value at row 2, column 3 of the matrix. 65 | /// 66 | public bool M23; 67 | 68 | /// 69 | /// Creates a new instance of . 70 | /// 71 | public Bool2x3(bool m11, bool m21, bool m12, bool m22, bool m13, bool m23) 72 | { 73 | M11 = m11; 74 | M12 = m12; 75 | M13 = m13; 76 | M21 = m21; 77 | M22 = m22; 78 | M23 = m23; 79 | } 80 | 81 | /// 82 | /// Gets or sets a component at the specified index for the current . 83 | /// 84 | public bool[] this[int index] 85 | { 86 | get => null; 87 | set {} 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Bool3x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 3 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Bool3x1 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 3; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(bool); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(bool); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public bool M11; 42 | 43 | /// 44 | /// The value at row 2, column 1 of the matrix. 45 | /// 46 | public bool M21; 47 | 48 | /// 49 | /// The value at row 3, column 1 of the matrix. 50 | /// 51 | public bool M31; 52 | 53 | /// 54 | /// Creates a new instance of . 55 | /// 56 | public Bool3x1(bool m11, bool m21, bool m31) 57 | { 58 | M11 = m11; 59 | M21 = m21; 60 | M31 = m31; 61 | } 62 | 63 | /// 64 | /// Gets or sets a component at the specified index for the current . 65 | /// 66 | public bool[] this[int index] 67 | { 68 | get => null; 69 | set {} 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Bool3x2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 3 row, 2 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Bool3x2 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 3; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 2; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(bool); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(bool); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public bool M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public bool M12; 47 | 48 | /// 49 | /// The value at row 2, column 1 of the matrix. 50 | /// 51 | public bool M21; 52 | 53 | /// 54 | /// The value at row 2, column 2 of the matrix. 55 | /// 56 | public bool M22; 57 | 58 | /// 59 | /// The value at row 3, column 1 of the matrix. 60 | /// 61 | public bool M31; 62 | 63 | /// 64 | /// The value at row 3, column 2 of the matrix. 65 | /// 66 | public bool M32; 67 | 68 | /// 69 | /// Creates a new instance of . 70 | /// 71 | public Bool3x2(bool m11, bool m21, bool m31, bool m12, bool m22, bool m32) 72 | { 73 | M11 = m11; 74 | M12 = m12; 75 | M21 = m21; 76 | M22 = m22; 77 | M31 = m31; 78 | M32 = m32; 79 | } 80 | 81 | /// 82 | /// Gets or sets a component at the specified index for the current . 83 | /// 84 | public bool[] this[int index] 85 | { 86 | get => null; 87 | set {} 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Bool4x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 4 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Bool4x1 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 4; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(bool); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(bool); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public bool M11; 42 | 43 | /// 44 | /// The value at row 2, column 1 of the matrix. 45 | /// 46 | public bool M21; 47 | 48 | /// 49 | /// The value at row 3, column 1 of the matrix. 50 | /// 51 | public bool M31; 52 | 53 | /// 54 | /// The value at row 4, column 1 of the matrix. 55 | /// 56 | public bool M41; 57 | 58 | /// 59 | /// Creates a new instance of . 60 | /// 61 | public Bool4x1(bool m11, bool m21, bool m31, bool m41) 62 | { 63 | M11 = m11; 64 | M21 = m21; 65 | M31 = m31; 66 | M41 = m41; 67 | } 68 | 69 | /// 70 | /// Gets or sets a component at the specified index for the current . 71 | /// 72 | public bool[] this[int index] 73 | { 74 | get => null; 75 | set {} 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Double1x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Double1x1 : IMatrix, UniformDimensions 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(double); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(double); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public double M11; 42 | 43 | /// 44 | /// Creates a new instance of . 45 | /// 46 | public Double1x1(double m11) 47 | { 48 | M11 = m11; 49 | } 50 | 51 | /// 52 | /// Gets or sets a component at the specified index for the current . 53 | /// 54 | public double[] this[int index] 55 | { 56 | get => null; 57 | set {} 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Double1x2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 2 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Double1x2 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 2; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(double); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(double); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public double M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public double M12; 47 | 48 | /// 49 | /// Creates a new instance of . 50 | /// 51 | public Double1x2(double m11, double m12) 52 | { 53 | M11 = m11; 54 | M12 = m12; 55 | } 56 | 57 | /// 58 | /// Gets or sets a component at the specified index for the current . 59 | /// 60 | public double[] this[int index] 61 | { 62 | get => null; 63 | set {} 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Double1x3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 3 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Double1x3 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 3; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(double); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(double); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public double M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public double M12; 47 | 48 | /// 49 | /// The value at row 1, column 3 of the matrix. 50 | /// 51 | public double M13; 52 | 53 | /// 54 | /// Creates a new instance of . 55 | /// 56 | public Double1x3(double m11, double m12, double m13) 57 | { 58 | M11 = m11; 59 | M12 = m12; 60 | M13 = m13; 61 | } 62 | 63 | /// 64 | /// Gets or sets a component at the specified index for the current . 65 | /// 66 | public double[] this[int index] 67 | { 68 | get => null; 69 | set {} 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Double1x4.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 4 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Double1x4 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 4; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(double); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(double); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public double M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public double M12; 47 | 48 | /// 49 | /// The value at row 1, column 3 of the matrix. 50 | /// 51 | public double M13; 52 | 53 | /// 54 | /// The value at row 1, column 4 of the matrix. 55 | /// 56 | public double M14; 57 | 58 | /// 59 | /// Creates a new instance of . 60 | /// 61 | public Double1x4(double m11, double m12, double m13, double m14) 62 | { 63 | M11 = m11; 64 | M12 = m12; 65 | M13 = m13; 66 | M14 = m14; 67 | } 68 | 69 | /// 70 | /// Gets or sets a component at the specified index for the current . 71 | /// 72 | public double[] this[int index] 73 | { 74 | get => null; 75 | set {} 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Double2x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 2 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Double2x1 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 2; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(double); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(double); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public double M11; 42 | 43 | /// 44 | /// The value at row 2, column 1 of the matrix. 45 | /// 46 | public double M21; 47 | 48 | /// 49 | /// Creates a new instance of . 50 | /// 51 | public Double2x1(double m11, double m21) 52 | { 53 | M11 = m11; 54 | M21 = m21; 55 | } 56 | 57 | /// 58 | /// Gets or sets a component at the specified index for the current . 59 | /// 60 | public double[] this[int index] 61 | { 62 | get => null; 63 | set {} 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Double2x2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 2 row, 2 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Double2x2 : IMatrix, UniformDimensions 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 2; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 2; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(double); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(double); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public double M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public double M12; 47 | 48 | /// 49 | /// The value at row 2, column 1 of the matrix. 50 | /// 51 | public double M21; 52 | 53 | /// 54 | /// The value at row 2, column 2 of the matrix. 55 | /// 56 | public double M22; 57 | 58 | /// 59 | /// Creates a new instance of . 60 | /// 61 | public Double2x2(double m11, double m21, double m12, double m22) 62 | { 63 | M11 = m11; 64 | M12 = m12; 65 | M21 = m21; 66 | M22 = m22; 67 | } 68 | 69 | /// 70 | /// Gets or sets a component at the specified index for the current . 71 | /// 72 | public double[] this[int index] 73 | { 74 | get => null; 75 | set {} 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Double3x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 3 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Double3x1 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 3; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(double); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(double); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public double M11; 42 | 43 | /// 44 | /// The value at row 2, column 1 of the matrix. 45 | /// 46 | public double M21; 47 | 48 | /// 49 | /// The value at row 3, column 1 of the matrix. 50 | /// 51 | public double M31; 52 | 53 | /// 54 | /// Creates a new instance of . 55 | /// 56 | public Double3x1(double m11, double m21, double m31) 57 | { 58 | M11 = m11; 59 | M21 = m21; 60 | M31 = m31; 61 | } 62 | 63 | /// 64 | /// Gets or sets a component at the specified index for the current . 65 | /// 66 | public double[] this[int index] 67 | { 68 | get => null; 69 | set {} 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Double4x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 4 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Double4x1 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 4; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(double); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(double); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public double M11; 42 | 43 | /// 44 | /// The value at row 2, column 1 of the matrix. 45 | /// 46 | public double M21; 47 | 48 | /// 49 | /// The value at row 3, column 1 of the matrix. 50 | /// 51 | public double M31; 52 | 53 | /// 54 | /// The value at row 4, column 1 of the matrix. 55 | /// 56 | public double M41; 57 | 58 | /// 59 | /// Creates a new instance of . 60 | /// 61 | public Double4x1(double m11, double m21, double m31, double m41) 62 | { 63 | M11 = m11; 64 | M21 = m21; 65 | M31 = m31; 66 | M41 = m41; 67 | } 68 | 69 | /// 70 | /// Gets or sets a component at the specified index for the current . 71 | /// 72 | public double[] this[int index] 73 | { 74 | get => null; 75 | set {} 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Int1x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Int1x1 : IMatrix, IIntrinsicValue, UniformDimensions 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(int); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(int); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public int M11; 42 | 43 | /// 44 | /// Creates a new instance of . 45 | /// 46 | public Int1x1(int m11) 47 | { 48 | M11 = m11; 49 | } 50 | 51 | /// 52 | /// Gets or sets a component at the specified index for the current . 53 | /// 54 | public int[] this[int index] 55 | { 56 | get => null; 57 | set {} 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Int1x2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 2 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Int1x2 : IMatrix, IIntrinsicValue 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 2; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(int); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(int); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public int M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public int M12; 47 | 48 | /// 49 | /// Creates a new instance of . 50 | /// 51 | public Int1x2(int m11, int m12) 52 | { 53 | M11 = m11; 54 | M12 = m12; 55 | } 56 | 57 | /// 58 | /// Gets or sets a component at the specified index for the current . 59 | /// 60 | public int[] this[int index] 61 | { 62 | get => null; 63 | set {} 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Int1x3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 3 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Int1x3 : IMatrix, IIntrinsicValue 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 3; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(int); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(int); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public int M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public int M12; 47 | 48 | /// 49 | /// The value at row 1, column 3 of the matrix. 50 | /// 51 | public int M13; 52 | 53 | /// 54 | /// Creates a new instance of . 55 | /// 56 | public Int1x3(int m11, int m12, int m13) 57 | { 58 | M11 = m11; 59 | M12 = m12; 60 | M13 = m13; 61 | } 62 | 63 | /// 64 | /// Gets or sets a component at the specified index for the current . 65 | /// 66 | public int[] this[int index] 67 | { 68 | get => null; 69 | set {} 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Int1x4.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 4 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Int1x4 : IMatrix, IIntrinsicValue 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 4; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(int); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(int); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public int M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public int M12; 47 | 48 | /// 49 | /// The value at row 1, column 3 of the matrix. 50 | /// 51 | public int M13; 52 | 53 | /// 54 | /// The value at row 1, column 4 of the matrix. 55 | /// 56 | public int M14; 57 | 58 | /// 59 | /// Creates a new instance of . 60 | /// 61 | public Int1x4(int m11, int m12, int m13, int m14) 62 | { 63 | M11 = m11; 64 | M12 = m12; 65 | M13 = m13; 66 | M14 = m14; 67 | } 68 | 69 | /// 70 | /// Gets or sets a component at the specified index for the current . 71 | /// 72 | public int[] this[int index] 73 | { 74 | get => null; 75 | set {} 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Int2x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 2 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Int2x1 : IMatrix, IIntrinsicValue 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 2; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(int); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(int); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public int M11; 42 | 43 | /// 44 | /// The value at row 2, column 1 of the matrix. 45 | /// 46 | public int M21; 47 | 48 | /// 49 | /// Creates a new instance of . 50 | /// 51 | public Int2x1(int m11, int m21) 52 | { 53 | M11 = m11; 54 | M21 = m21; 55 | } 56 | 57 | /// 58 | /// Gets or sets a component at the specified index for the current . 59 | /// 60 | public int[] this[int index] 61 | { 62 | get => null; 63 | set {} 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Int2x2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 2 row, 2 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Int2x2 : IMatrix, IIntrinsicValue, UniformDimensions 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 2; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 2; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(int); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(int); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public int M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public int M12; 47 | 48 | /// 49 | /// The value at row 2, column 1 of the matrix. 50 | /// 51 | public int M21; 52 | 53 | /// 54 | /// The value at row 2, column 2 of the matrix. 55 | /// 56 | public int M22; 57 | 58 | /// 59 | /// Creates a new instance of . 60 | /// 61 | public Int2x2(int m11, int m21, int m12, int m22) 62 | { 63 | M11 = m11; 64 | M12 = m12; 65 | M21 = m21; 66 | M22 = m22; 67 | } 68 | 69 | /// 70 | /// Gets or sets a component at the specified index for the current . 71 | /// 72 | public int[] this[int index] 73 | { 74 | get => null; 75 | set {} 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Int2x3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 2 row, 3 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Int2x3 : IMatrix, IIntrinsicValue 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 2; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 3; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(int); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(int); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public int M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public int M12; 47 | 48 | /// 49 | /// The value at row 1, column 3 of the matrix. 50 | /// 51 | public int M13; 52 | 53 | /// 54 | /// The value at row 2, column 1 of the matrix. 55 | /// 56 | public int M21; 57 | 58 | /// 59 | /// The value at row 2, column 2 of the matrix. 60 | /// 61 | public int M22; 62 | 63 | /// 64 | /// The value at row 2, column 3 of the matrix. 65 | /// 66 | public int M23; 67 | 68 | /// 69 | /// Creates a new instance of . 70 | /// 71 | public Int2x3(int m11, int m21, int m12, int m22, int m13, int m23) 72 | { 73 | M11 = m11; 74 | M12 = m12; 75 | M13 = m13; 76 | M21 = m21; 77 | M22 = m22; 78 | M23 = m23; 79 | } 80 | 81 | /// 82 | /// Gets or sets a component at the specified index for the current . 83 | /// 84 | public int[] this[int index] 85 | { 86 | get => null; 87 | set {} 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Int3x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 3 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Int3x1 : IMatrix, IIntrinsicValue 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 3; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(int); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(int); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public int M11; 42 | 43 | /// 44 | /// The value at row 2, column 1 of the matrix. 45 | /// 46 | public int M21; 47 | 48 | /// 49 | /// The value at row 3, column 1 of the matrix. 50 | /// 51 | public int M31; 52 | 53 | /// 54 | /// Creates a new instance of . 55 | /// 56 | public Int3x1(int m11, int m21, int m31) 57 | { 58 | M11 = m11; 59 | M21 = m21; 60 | M31 = m31; 61 | } 62 | 63 | /// 64 | /// Gets or sets a component at the specified index for the current . 65 | /// 66 | public int[] this[int index] 67 | { 68 | get => null; 69 | set {} 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Int3x2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 3 row, 2 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Int3x2 : IMatrix, IIntrinsicValue 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 3; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 2; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(int); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(int); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public int M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public int M12; 47 | 48 | /// 49 | /// The value at row 2, column 1 of the matrix. 50 | /// 51 | public int M21; 52 | 53 | /// 54 | /// The value at row 2, column 2 of the matrix. 55 | /// 56 | public int M22; 57 | 58 | /// 59 | /// The value at row 3, column 1 of the matrix. 60 | /// 61 | public int M31; 62 | 63 | /// 64 | /// The value at row 3, column 2 of the matrix. 65 | /// 66 | public int M32; 67 | 68 | /// 69 | /// Creates a new instance of . 70 | /// 71 | public Int3x2(int m11, int m21, int m31, int m12, int m22, int m32) 72 | { 73 | M11 = m11; 74 | M12 = m12; 75 | M21 = m21; 76 | M22 = m22; 77 | M31 = m31; 78 | M32 = m32; 79 | } 80 | 81 | /// 82 | /// Gets or sets a component at the specified index for the current . 83 | /// 84 | public int[] this[int index] 85 | { 86 | get => null; 87 | set {} 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Int4x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 4 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Int4x1 : IMatrix, IIntrinsicValue 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 4; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(int); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(int); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public int M11; 42 | 43 | /// 44 | /// The value at row 2, column 1 of the matrix. 45 | /// 46 | public int M21; 47 | 48 | /// 49 | /// The value at row 3, column 1 of the matrix. 50 | /// 51 | public int M31; 52 | 53 | /// 54 | /// The value at row 4, column 1 of the matrix. 55 | /// 56 | public int M41; 57 | 58 | /// 59 | /// Creates a new instance of . 60 | /// 61 | public Int4x1(int m11, int m21, int m31, int m41) 62 | { 63 | M11 = m11; 64 | M21 = m21; 65 | M31 = m31; 66 | M41 = m41; 67 | } 68 | 69 | /// 70 | /// Gets or sets a component at the specified index for the current . 71 | /// 72 | public int[] this[int index] 73 | { 74 | get => null; 75 | set {} 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Matrices.cs: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /SharpShader.Core/Types/Matrices1.cs: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /SharpShader.Core/Types/Matrix1x1.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace SharpShader 7 | { 8 | /// 9 | /// A 1 row, 1 column matrix. 10 | /// 11 | [StructLayout(LayoutKind.Sequential)] 12 | [Serializable] 13 | public struct Matrix1x1 : IMatrix, IIntrinsicValue, UniformDimensions 14 | { 15 | /// 16 | /// The number of rows in a . 17 | /// 18 | public const int ROW_COUNT = 1; 19 | 20 | /// 21 | /// The number of columns in a . 22 | /// 23 | public const int COLUMN_COUNT = 1; 24 | 25 | /// 26 | /// The size of a , in bytes. 27 | /// 28 | public const int ELEMENT_SIZE = sizeof(float); 29 | 30 | /// 31 | /// The size of a single element within a , in bytes. 32 | /// 33 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 34 | 35 | /// 36 | /// Gets the of each element in a . 37 | /// 38 | public static readonly Type ElementType = typeof(float); 39 | 40 | /// 41 | /// The value at row 1, column 1 of the matrix. 42 | /// 43 | public float M11; 44 | 45 | /// 46 | /// Creates a new instance of . 47 | /// 48 | public Matrix1x1(float m11) 49 | { 50 | M11 = m11; 51 | } 52 | 53 | /// 54 | /// Gets or sets a component at the specified index for the current . 55 | /// 56 | public float[] this[int index] 57 | { 58 | get => null; 59 | set {} 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Matrix1x2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 2 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Matrix1x2 : IMatrix, IIntrinsicValue 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 2; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(float); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(float); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public float M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public float M12; 47 | 48 | /// 49 | /// Creates a new instance of . 50 | /// 51 | public Matrix1x2(float m11, float m12) 52 | { 53 | M11 = m11; 54 | M12 = m12; 55 | } 56 | 57 | /// 58 | /// Gets or sets a component at the specified index for the current . 59 | /// 60 | public float[] this[int index] 61 | { 62 | get => null; 63 | set {} 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Matrix1x3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 3 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Matrix1x3 : IMatrix, IIntrinsicValue 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 3; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(float); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(float); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public float M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public float M12; 47 | 48 | /// 49 | /// The value at row 1, column 3 of the matrix. 50 | /// 51 | public float M13; 52 | 53 | /// 54 | /// Creates a new instance of . 55 | /// 56 | public Matrix1x3(float m11, float m12, float m13) 57 | { 58 | M11 = m11; 59 | M12 = m12; 60 | M13 = m13; 61 | } 62 | 63 | /// 64 | /// Gets or sets a component at the specified index for the current . 65 | /// 66 | public float[] this[int index] 67 | { 68 | get => null; 69 | set {} 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Matrix1x4.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 4 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Matrix1x4 : IMatrix, IIntrinsicValue 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 4; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(float); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(float); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public float M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public float M12; 47 | 48 | /// 49 | /// The value at row 1, column 3 of the matrix. 50 | /// 51 | public float M13; 52 | 53 | /// 54 | /// The value at row 1, column 4 of the matrix. 55 | /// 56 | public float M14; 57 | 58 | /// 59 | /// Creates a new instance of . 60 | /// 61 | public Matrix1x4(float m11, float m12, float m13, float m14) 62 | { 63 | M11 = m11; 64 | M12 = m12; 65 | M13 = m13; 66 | M14 = m14; 67 | } 68 | 69 | /// 70 | /// Gets or sets a component at the specified index for the current . 71 | /// 72 | public float[] this[int index] 73 | { 74 | get => null; 75 | set {} 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Matrix2x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 2 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Matrix2x1 : IMatrix, IIntrinsicValue 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 2; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(float); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(float); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public float M11; 42 | 43 | /// 44 | /// The value at row 2, column 1 of the matrix. 45 | /// 46 | public float M21; 47 | 48 | /// 49 | /// Creates a new instance of . 50 | /// 51 | public Matrix2x1(float m11, float m21) 52 | { 53 | M11 = m11; 54 | M21 = m21; 55 | } 56 | 57 | /// 58 | /// Gets or sets a component at the specified index for the current . 59 | /// 60 | public float[] this[int index] 61 | { 62 | get => null; 63 | set {} 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Matrix2x2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 2 row, 2 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Matrix2x2 : IMatrix, IIntrinsicValue, UniformDimensions 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 2; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 2; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(float); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(float); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public float M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public float M12; 47 | 48 | /// 49 | /// The value at row 2, column 1 of the matrix. 50 | /// 51 | public float M21; 52 | 53 | /// 54 | /// The value at row 2, column 2 of the matrix. 55 | /// 56 | public float M22; 57 | 58 | /// 59 | /// Creates a new instance of . 60 | /// 61 | public Matrix2x2(float m11, float m21, float m12, float m22) 62 | { 63 | M11 = m11; 64 | M12 = m12; 65 | M21 = m21; 66 | M22 = m22; 67 | } 68 | 69 | /// 70 | /// Gets or sets a component at the specified index for the current . 71 | /// 72 | public float[] this[int index] 73 | { 74 | get => null; 75 | set {} 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Matrix3x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 3 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Matrix3x1 : IMatrix, IIntrinsicValue 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 3; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(float); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(float); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public float M11; 42 | 43 | /// 44 | /// The value at row 2, column 1 of the matrix. 45 | /// 46 | public float M21; 47 | 48 | /// 49 | /// The value at row 3, column 1 of the matrix. 50 | /// 51 | public float M31; 52 | 53 | /// 54 | /// Creates a new instance of . 55 | /// 56 | public Matrix3x1(float m11, float m21, float m31) 57 | { 58 | M11 = m11; 59 | M21 = m21; 60 | M31 = m31; 61 | } 62 | 63 | /// 64 | /// Gets or sets a component at the specified index for the current . 65 | /// 66 | public float[] this[int index] 67 | { 68 | get => null; 69 | set {} 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Matrix4x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 4 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct Matrix4x1 : IMatrix, IIntrinsicValue 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 4; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(float); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(float); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public float M11; 42 | 43 | /// 44 | /// The value at row 2, column 1 of the matrix. 45 | /// 46 | public float M21; 47 | 48 | /// 49 | /// The value at row 3, column 1 of the matrix. 50 | /// 51 | public float M31; 52 | 53 | /// 54 | /// The value at row 4, column 1 of the matrix. 55 | /// 56 | public float M41; 57 | 58 | /// 59 | /// Creates a new instance of . 60 | /// 61 | public Matrix4x1(float m11, float m21, float m31, float m41) 62 | { 63 | M11 = m11; 64 | M21 = m21; 65 | M31 = m31; 66 | M41 = m41; 67 | } 68 | 69 | /// 70 | /// Gets or sets a component at the specified index for the current . 71 | /// 72 | public float[] this[int index] 73 | { 74 | get => null; 75 | set {} 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/MultipleOutput.cs: -------------------------------------------------------------------------------- 1 |  2 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/MultipleOutput.tt: -------------------------------------------------------------------------------- 1 | <#@ template debug="false" hostspecific="true" language="C#" #> 2 | <#@ import namespace="System.IO" #> 3 | <#@ import namespace="Microsoft.VisualStudio.TextTemplating" #> 4 | 5 | <# 6 | void SaveOutput(string outputFileName) 7 | { 8 | string templateDirectory = Path.GetDirectoryName(this.Host.TemplateFile); 9 | string outputFilePath = Path.Combine(templateDirectory, outputFileName); 10 | File.WriteAllText(outputFilePath, this.GenerationEnvironment.ToString()); 11 | 12 | this.GenerationEnvironment.Remove(0, this.GenerationEnvironment.Length); 13 | } 14 | #> -------------------------------------------------------------------------------- /SharpShader.Core/Types/UInt1x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct UInt1x1 : IMatrix, UniformDimensions 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(uint); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(uint); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public uint M11; 42 | 43 | /// 44 | /// Creates a new instance of . 45 | /// 46 | public UInt1x1(uint m11) 47 | { 48 | M11 = m11; 49 | } 50 | 51 | /// 52 | /// Gets or sets a component at the specified index for the current . 53 | /// 54 | public uint[] this[int index] 55 | { 56 | get => null; 57 | set {} 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/UInt1x2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 2 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct UInt1x2 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 2; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(uint); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(uint); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public uint M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public uint M12; 47 | 48 | /// 49 | /// Creates a new instance of . 50 | /// 51 | public UInt1x2(uint m11, uint m12) 52 | { 53 | M11 = m11; 54 | M12 = m12; 55 | } 56 | 57 | /// 58 | /// Gets or sets a component at the specified index for the current . 59 | /// 60 | public uint[] this[int index] 61 | { 62 | get => null; 63 | set {} 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/UInt1x3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 3 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct UInt1x3 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 3; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(uint); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(uint); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public uint M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public uint M12; 47 | 48 | /// 49 | /// The value at row 1, column 3 of the matrix. 50 | /// 51 | public uint M13; 52 | 53 | /// 54 | /// Creates a new instance of . 55 | /// 56 | public UInt1x3(uint m11, uint m12, uint m13) 57 | { 58 | M11 = m11; 59 | M12 = m12; 60 | M13 = m13; 61 | } 62 | 63 | /// 64 | /// Gets or sets a component at the specified index for the current . 65 | /// 66 | public uint[] this[int index] 67 | { 68 | get => null; 69 | set {} 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/UInt1x4.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 1 row, 4 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct UInt1x4 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 1; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 4; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(uint); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(uint); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public uint M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public uint M12; 47 | 48 | /// 49 | /// The value at row 1, column 3 of the matrix. 50 | /// 51 | public uint M13; 52 | 53 | /// 54 | /// The value at row 1, column 4 of the matrix. 55 | /// 56 | public uint M14; 57 | 58 | /// 59 | /// Creates a new instance of . 60 | /// 61 | public UInt1x4(uint m11, uint m12, uint m13, uint m14) 62 | { 63 | M11 = m11; 64 | M12 = m12; 65 | M13 = m13; 66 | M14 = m14; 67 | } 68 | 69 | /// 70 | /// Gets or sets a component at the specified index for the current . 71 | /// 72 | public uint[] this[int index] 73 | { 74 | get => null; 75 | set {} 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/UInt2x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 2 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct UInt2x1 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 2; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(uint); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(uint); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public uint M11; 42 | 43 | /// 44 | /// The value at row 2, column 1 of the matrix. 45 | /// 46 | public uint M21; 47 | 48 | /// 49 | /// Creates a new instance of . 50 | /// 51 | public UInt2x1(uint m11, uint m21) 52 | { 53 | M11 = m11; 54 | M21 = m21; 55 | } 56 | 57 | /// 58 | /// Gets or sets a component at the specified index for the current . 59 | /// 60 | public uint[] this[int index] 61 | { 62 | get => null; 63 | set {} 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/UInt2x2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 2 row, 2 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct UInt2x2 : IMatrix, UniformDimensions 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 2; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 2; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(uint); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(uint); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public uint M11; 42 | 43 | /// 44 | /// The value at row 1, column 2 of the matrix. 45 | /// 46 | public uint M12; 47 | 48 | /// 49 | /// The value at row 2, column 1 of the matrix. 50 | /// 51 | public uint M21; 52 | 53 | /// 54 | /// The value at row 2, column 2 of the matrix. 55 | /// 56 | public uint M22; 57 | 58 | /// 59 | /// Creates a new instance of . 60 | /// 61 | public UInt2x2(uint m11, uint m21, uint m12, uint m22) 62 | { 63 | M11 = m11; 64 | M12 = m12; 65 | M21 = m21; 66 | M22 = m22; 67 | } 68 | 69 | /// 70 | /// Gets or sets a component at the specified index for the current . 71 | /// 72 | public uint[] this[int index] 73 | { 74 | get => null; 75 | set {} 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/UInt3x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 3 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct UInt3x1 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 3; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(uint); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(uint); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public uint M11; 42 | 43 | /// 44 | /// The value at row 2, column 1 of the matrix. 45 | /// 46 | public uint M21; 47 | 48 | /// 49 | /// The value at row 3, column 1 of the matrix. 50 | /// 51 | public uint M31; 52 | 53 | /// 54 | /// Creates a new instance of . 55 | /// 56 | public UInt3x1(uint m11, uint m21, uint m31) 57 | { 58 | M11 = m11; 59 | M21 = m21; 60 | M31 = m31; 61 | } 62 | 63 | /// 64 | /// Gets or sets a component at the specified index for the current . 65 | /// 66 | public uint[] this[int index] 67 | { 68 | get => null; 69 | set {} 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/UInt4x1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpShader 5 | { 6 | /// 7 | /// A 4 row, 1 column matrix. 8 | /// 9 | [StructLayout(LayoutKind.Sequential)] 10 | [Serializable] 11 | public struct UInt4x1 : IMatrix 12 | { 13 | /// 14 | /// The number of rows in a . 15 | /// 16 | public const int ROW_COUNT = 4; 17 | 18 | /// 19 | /// The number of columns in a . 20 | /// 21 | public const int COLUMN_COUNT = 1; 22 | 23 | /// 24 | /// The size of a , in bytes. 25 | /// 26 | public const int ELEMENT_SIZE = sizeof(uint); 27 | 28 | /// 29 | /// The size of a single element within a , in bytes. 30 | /// 31 | public const int SIZE_OF = (ROW_COUNT * COLUMN_COUNT) * ELEMENT_SIZE; 32 | 33 | /// 34 | /// Gets the of each element in a . 35 | /// 36 | public static readonly Type ElementType = typeof(uint); 37 | 38 | /// 39 | /// The value at row 1, column 1 of the matrix. 40 | /// 41 | public uint M11; 42 | 43 | /// 44 | /// The value at row 2, column 1 of the matrix. 45 | /// 46 | public uint M21; 47 | 48 | /// 49 | /// The value at row 3, column 1 of the matrix. 50 | /// 51 | public uint M31; 52 | 53 | /// 54 | /// The value at row 4, column 1 of the matrix. 55 | /// 56 | public uint M41; 57 | 58 | /// 59 | /// Creates a new instance of . 60 | /// 61 | public UInt4x1(uint m11, uint m21, uint m31, uint m41) 62 | { 63 | M11 = m11; 64 | M21 = m21; 65 | M31 = m31; 66 | M41 = m41; 67 | } 68 | 69 | /// 70 | /// Gets or sets a component at the specified index for the current . 71 | /// 72 | public uint[] this[int index] 73 | { 74 | get => null; 75 | set {} 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /SharpShader.Core/Types/Vectors.cs: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /SharpShader/AnalysisInfo.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SharpShader 9 | { 10 | internal class AnalysisInfo 11 | { 12 | internal List Trees; 13 | 14 | internal bool HasError; 15 | } 16 | } -------------------------------------------------------------------------------- /SharpShader/EmbeddedResource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | 8 | namespace SharpShader 9 | { 10 | internal static class EmbeddedResource 11 | { 12 | /// Reads a resource file embedded into the assembly. 13 | /// The name of the resource to load. 14 | /// 15 | internal static string ReadResource(string name) 16 | { 17 | var assembly = Assembly.GetExecutingAssembly(); 18 | 19 | string result = ""; 20 | 21 | using (Stream stream = assembly.GetManifestResourceStream(name)) 22 | { 23 | using (StreamReader reader = new StreamReader(stream)) 24 | { 25 | result = reader.ReadToEnd(); 26 | } 27 | } 28 | return result; 29 | } 30 | 31 | internal static Stream GetStream(string name, Assembly assembly = null) 32 | { 33 | if (assembly == null) 34 | assembly = Assembly.GetExecutingAssembly(); 35 | 36 | Stream stream = null; 37 | try 38 | { 39 | stream = assembly.GetManifestResourceStream(name); 40 | } 41 | finally { } 42 | 43 | return stream; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /SharpShader/Exceptions/ScopeException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.Serialization; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SharpShader 9 | { 10 | [Serializable] 11 | public class ScopeException : Exception 12 | { 13 | internal ScopeException(string msg) : base(msg) { } 14 | 15 | protected ScopeException(SerializationInfo info, StreamingContext context) : base(info, context) 16 | { 17 | 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /SharpShader/Interlocker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace SharpShader 9 | { 10 | /// 11 | /// A locking helper built on top of the class. 12 | /// 13 | public class InterlockHelper 14 | { 15 | Thread _thread; 16 | int _blockingVal; 17 | 18 | /// 19 | /// Takes the lock by internally using . Skips lock checks if the current thread already holds the lock. 20 | /// 21 | /// 22 | public void Lock(Action callback) 23 | { 24 | if (_thread != Thread.CurrentThread) 25 | { 26 | SpinWait spin = new SpinWait(); 27 | while (0 != Interlocked.Exchange(ref _blockingVal, 1)) 28 | spin.SpinOnce(); 29 | 30 | _thread = Thread.CurrentThread; 31 | callback(); 32 | _thread = null; 33 | Interlocked.Exchange(ref _blockingVal, 0); 34 | } 35 | else 36 | { 37 | callback(); 38 | } 39 | } 40 | 41 | /// 42 | /// Releases the lock then throws an exception. 43 | /// 44 | /// The type of exception. Note: The exception type must have a constructor which accepts only a string for the message. 45 | /// The message to attach to the exception. 46 | public void Throw(string message) where T : Exception 47 | { 48 | T ex = Activator.CreateInstance(typeof(T), message) as T; 49 | _thread = null; 50 | Interlocked.Exchange(ref _blockingVal, 0); 51 | throw ex; 52 | } 53 | 54 | /// 55 | /// Releases the lock then throws an exception. 56 | /// 57 | /// The exception to be thrown. 58 | public void Throw(Exception exception) 59 | { 60 | _thread = null; 61 | Interlocked.Exchange(ref _blockingVal, 0); 62 | throw exception; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /SharpShader/Languages/GLSL/GlslLanguage.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | using Microsoft.CodeAnalysis.CSharp.Syntax; 3 | using SharpShader.Languages; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Reflection; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace SharpShader 12 | { 13 | internal class GlslFoundation : ShaderLanguage 14 | { 15 | internal override bool InstancedConstantBuffers => true; 16 | 17 | internal GlslFoundation(OutputLanguage language) : base(language) { } 18 | 19 | internal override string TranslateNumber(ShaderTranslationContext context, string number) 20 | { 21 | throw new NotImplementedException(); 22 | } 23 | 24 | internal override IEntryPointTranslator GetEntryPoinTranslator(EntryPointType type) 25 | { 26 | throw new NotImplementedException(); 27 | } 28 | 29 | internal override void TranslateForLoopPrefix(ShaderTranslationContext sc, ForStatementSyntax syntax) 30 | { 31 | throw new NotImplementedException(); 32 | } 33 | 34 | internal override void TranslateConstBufferHeader(ShaderTranslationContext sc, StructDeclarationSyntax syntax, MappedConstantBuffer cBufferMap, IEnumerable attributes) 35 | { 36 | throw new NotImplementedException(); 37 | } 38 | 39 | internal override void TranslateFieldPrefix(ShaderTranslationContext sc, VariableDeclaratorSyntax syntax, MappedField field, int fieldIndex, MappedConstantBuffer cBufferMap) 40 | { 41 | throw new NotImplementedException(); 42 | } 43 | 44 | internal override void TranslateFieldPostfix(ShaderTranslationContext sc, VariableDeclaratorSyntax syntax, MappedField field, int fieldIndex, MappedConstantBuffer cBufferMap) 45 | { 46 | throw new NotImplementedException(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /SharpShader/Languages/HLSL/Translators/ComputeTranslator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Languages.HLSL.Translators 10 | { 11 | internal class ComputeTranslator : DefaultEntryPointTranslator 12 | { 13 | public override void TranslatePrefix(ShaderTranslationContext sc, MethodInfo info, MethodDeclarationSyntax syntax, MappedEntryPoint ep) 14 | { 15 | ComputeShaderAttribute attCompute = ep.Attribute as ComputeShaderAttribute; 16 | sc.Source.Append($"[numthreads({attCompute.ThreadsX}, {attCompute.ThreadsY}, {attCompute.ThreadsZ})]"); 17 | sc.Source.AppendLineBreak(); 18 | 19 | base.TranslatePrefix(sc, info, syntax, ep); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SharpShader/Languages/HLSL/Translators/DomainTranslator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Languages.HLSL.Translators 10 | { 11 | internal class DomainTranslator : DefaultEntryPointTranslator 12 | { 13 | public override void TranslatePrefix(ShaderTranslationContext sc, MethodInfo info, MethodDeclarationSyntax syntax, MappedEntryPoint ep) 14 | { 15 | DomainShaderAttribute attHull = ep.Attribute as DomainShaderAttribute; 16 | string patchType = attHull.PatchType.ToString().ToLower(); 17 | sc.Source.Append($"[domain(\"{patchType}\")]"); 18 | sc.Source.AppendLineBreak(); 19 | 20 | base.TranslatePrefix(sc, info, syntax, ep); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SharpShader/Languages/HLSL/Translators/HullTranslator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Languages.HLSL.Translators 10 | { 11 | internal class HullTranslator : DefaultEntryPointTranslator 12 | { 13 | static readonly Dictionary _partitionNames = new Dictionary() 14 | { 15 | [HullPartitioning.Integer] = "integer", 16 | [HullPartitioning.FractionalEven] = "fractional_even", 17 | [HullPartitioning.FractionalOdd] = "fractional_odd", 18 | [HullPartitioning.PowerOfTwo] = "pow2", 19 | }; 20 | 21 | static readonly Dictionary _topologyNames = new Dictionary() 22 | { 23 | [HullOutputTopology.Line] = "line", 24 | [HullOutputTopology.Point] = "point", 25 | [HullOutputTopology.TriangleCCW] = "triangle_ccw", 26 | [HullOutputTopology.TriangleCW] = "triangle_cw", 27 | }; 28 | 29 | public override void TranslatePrefix(ShaderTranslationContext sc, MethodInfo info, MethodDeclarationSyntax syntax, MappedEntryPoint ep) 30 | { 31 | HullShaderAttribute attHull = ep.Attribute as HullShaderAttribute; 32 | string patchType = attHull.PatchType.ToString().ToLower(); 33 | sc.Source.Append($"[domain(\"{patchType}\")]"); 34 | sc.Source.AppendLineBreak(); 35 | 36 | string partType = _partitionNames[attHull.Partitioning]; 37 | sc.Source.Append($"[partitioning(\"{partType}\")]"); 38 | sc.Source.AppendLineBreak(); 39 | 40 | string topology = _topologyNames[attHull.Topology]; 41 | sc.Source.Append($"[outputtopology(\"{topology}\")]"); 42 | sc.Source.AppendLineBreak(); 43 | 44 | sc.Source.Append($"[outputcontrolpoints({attHull.OutputControlPoints})]"); 45 | sc.Source.AppendLineBreak(); 46 | 47 | sc.Source.Append($"[patchconstantfunc(\"{attHull.PatchConstantCallback}\")]"); 48 | sc.Source.AppendLineBreak(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /SharpShader/Languages/IEntryPointTranslator.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis.CSharp.Syntax; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SharpShader.Languages 10 | { 11 | internal interface IEntryPointTranslator 12 | { 13 | void TranslatePrefix(ShaderTranslationContext sc, MethodInfo info, MethodDeclarationSyntax syntax, MappedEntryPoint ep); 14 | 15 | void TranslatePostfix(ShaderTranslationContext sc, MethodInfo info, MethodDeclarationSyntax syntax, MappedEntryPoint ep); 16 | 17 | void TranslateParameterPrefix(ShaderTranslationContext sc, ParameterSyntax syntax, MappedEntryPoint ep, ParameterInfo pInfo, IEnumerable attributes, int parameterIndex); 18 | 19 | void TranslateParameterPostfix(ShaderTranslationContext sc, ParameterSyntax syntax, MappedEntryPoint ep, ParameterInfo pInfo, IEnumerable attributes, int parameterIndex); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SharpShader/Languages/ShaderLanguage.Modifier.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SharpShader 9 | { 10 | internal abstract partial class ShaderLanguage 11 | { 12 | internal class Modifier 13 | { 14 | /// 15 | /// A list containing the C# modifiers required for this native translation to be accepted. 16 | /// 17 | internal List Requirements = new List(); 18 | 19 | /// 20 | /// The modifier in it's native language (e.g. const static). 21 | /// 22 | internal string NativeText; 23 | 24 | internal bool IsMatch(SyntaxTokenList csharpModifiers) 25 | { 26 | if (csharpModifiers.Count != Requirements.Count) 27 | return false; 28 | 29 | // The syntax token list must contain each of the requirements. 30 | // If one is not found, we return false. 31 | foreach (string s in Requirements) 32 | { 33 | bool found = false; 34 | foreach (SyntaxToken t in csharpModifiers) 35 | { 36 | if (t.ToString() == s) 37 | { 38 | found = true; 39 | break; 40 | } 41 | } 42 | 43 | if (!found) 44 | return false; 45 | } 46 | 47 | return true; 48 | } 49 | 50 | public override string ToString() 51 | { 52 | return NativeText; 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /SharpShader/Languages/ShaderLanguage.Translation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | internal abstract partial class ShaderLanguage 10 | { 11 | internal class Translation 12 | { 13 | /// 14 | /// If true, uniform, multi-dimensional type names will be translated to single-dimension names. For example, Matrix4x4 will translate into Matrix4, Mat4 or Float4. 15 | /// 16 | public bool UniformSizeIsSingular; 17 | 18 | /// 19 | /// The word in it's native language. 20 | /// 21 | public string NativeText; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /SharpShader/MappedConstantBuffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [Serializable] 10 | internal class MappedConstantBuffer : IPoolable 11 | { 12 | /// 13 | /// A list of mapped variables contained within the constant buffer. 14 | /// 15 | internal readonly List Variables = new List(); 16 | 17 | /// 18 | /// Bind spots organised by shader model. 19 | /// 20 | internal readonly HashSet BindSlots = new HashSet(); 21 | 22 | /// 23 | /// The type of the constant buffer. 24 | /// 25 | [NonSerialized] 26 | internal Type TypeInfo; 27 | 28 | internal int SizeOf { get; private set; } 29 | 30 | internal void AddField(MappedField field) 31 | { 32 | int size = field.GetTotalSizeOf(); 33 | 34 | if (field.PackOffsetBytes.HasValue) 35 | { 36 | int minSize = field.PackOffsetBytes.Value + size; 37 | SizeOf = Math.Max(minSize, SizeOf); 38 | } 39 | else 40 | { 41 | field.PackOffsetBytes = SizeOf; 42 | SizeOf += size; 43 | } 44 | 45 | Variables.Add(field); 46 | } 47 | 48 | void IPoolable.Clear() 49 | { 50 | foreach (MappedField mField in Variables) 51 | Pooling.MappedFields.Put(mField); 52 | 53 | Variables.Clear(); 54 | BindSlots.Clear(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /SharpShader/MethodBucket.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis.CSharp.Syntax; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SharpShader 10 | { 11 | internal class MethodBucket : IPoolable 12 | { 13 | Dictionary _methods = new Dictionary(); 14 | 15 | internal void Add(MethodInfo info) 16 | { 17 | _methods.Add(info, info.GetParameters()); 18 | } 19 | 20 | internal (ParameterInfo info, int index) GetParameterInfo(MethodInfo method, string parameterName) 21 | { 22 | if(_methods.TryGetValue(method, out ParameterInfo[] parameters)) 23 | { 24 | for(int i = 0; i < parameters.Length; i++) 25 | { 26 | if (parameters[i].Name == parameterName) 27 | return (parameters[i], i); 28 | } 29 | } 30 | 31 | return (null, 0); 32 | } 33 | 34 | internal MethodInfo Find(ShaderTranslationContext sc, MethodDeclarationSyntax syntax) 35 | { 36 | foreach(KeyValuePair p in _methods) 37 | { 38 | if (p.Value.Length != syntax.ParameterList.Parameters.Count) 39 | continue; 40 | 41 | bool success = true; 42 | for (int i = 0; i < p.Value.Length; i++) 43 | { 44 | ParameterSyntax ps = syntax.ParameterList.Parameters[i]; 45 | Type pType = ShaderType.Resolve(sc, ps.Type.ToString(), ps.Modifiers); 46 | if(pType != p.Value[i].ParameterType || ps.Identifier.ValueText != p.Value[i].Name) 47 | { 48 | success = false; 49 | break; 50 | } 51 | } 52 | 53 | if (success) 54 | return p.Key; 55 | } 56 | 57 | return null; 58 | } 59 | 60 | public void Clear() 61 | { 62 | _methods.Clear(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /SharpShader/ObjectPool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SharpShader 9 | { 10 | /// 11 | /// A thread-safe object pool which allows existing instances of a type to be recycled for later reuse. 12 | /// 13 | /// 14 | internal class ObjectPool where T : IPoolable, new() 15 | { 16 | ConcurrentBag _pool; 17 | 18 | /// 19 | /// 20 | /// 21 | /// The callback to invoke when a new instance of is required. 22 | internal ObjectPool() 23 | { 24 | _pool = new ConcurrentBag(); 25 | } 26 | 27 | public T Get() 28 | { 29 | T result; 30 | if (!_pool.TryTake(out result)) 31 | result = new T(); 32 | 33 | return result; 34 | } 35 | 36 | public void Put(T item) 37 | { 38 | item.Clear(); 39 | _pool.Add(item); 40 | } 41 | } 42 | 43 | internal interface IPoolable 44 | { 45 | void Clear(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /SharpShader/Pooling.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | internal static class Pooling 10 | { 11 | internal static readonly ObjectPool Contexts = new ObjectPool(); 12 | 13 | internal static readonly ObjectPool ShaderContexts = new ObjectPool(); 14 | 15 | internal static readonly ObjectPool Scopes = new ObjectPool(); 16 | 17 | internal static ObjectPool MappedFields = new ObjectPool(); 18 | 19 | internal static ObjectPool MappedConstBuffers = new ObjectPool(); 20 | 21 | internal static ObjectPool MethodBuckets = new ObjectPool(); 22 | 23 | internal static ObjectPool SourceSegments = new ObjectPool(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /SharpShader/Processors/ArgumentProcessor.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis.CSharp.Syntax; 2 | 3 | namespace SharpShader.Processors 4 | { 5 | internal class ArgumentListProcessor : NodeProcessor 6 | { 7 | protected override void OnTranslate(ShaderTranslationContext sc, ArgumentListSyntax syntax, ScopeInfo scope) 8 | { 9 | ScopeInfo pScope = sc.Source.OpenScope(ScopeType.Parentheses); 10 | pScope.Items = syntax.Arguments; 11 | } 12 | } 13 | 14 | internal class BracketedArgumentListProcessor : NodeProcessor 15 | { 16 | protected override void OnTranslate(ShaderTranslationContext sc, BracketedArgumentListSyntax syntax, ScopeInfo scope) 17 | { 18 | sc.Source.OpenScope(ScopeType.Indexer); 19 | } 20 | } 21 | 22 | internal class ArgumentProcessor : NodeProcessor 23 | { 24 | protected override void OnTranslate(ShaderTranslationContext sc, ArgumentSyntax syntax, ScopeInfo scope) 25 | { 26 | if (scope.Type == ScopeType.Parentheses) 27 | { 28 | if (scope.Items.Last() != syntax) 29 | sc.Source.OpenScope(ScopeType.ParenthesesItem); 30 | } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /SharpShader/Processors/ArrayRankProcessor.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | using Microsoft.CodeAnalysis.CSharp.Syntax; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace SharpShader.Processors 7 | { 8 | internal class ArrayRankProcessor : NodeProcessor 9 | { 10 | protected override void OnTranslate(ShaderTranslationContext sc, ArrayRankSpecifierSyntax syntax, ScopeInfo scope) 11 | { 12 | sc.Source.OpenScope(ScopeType.Indexer); 13 | } 14 | } 15 | 16 | internal class OmittedArraySizeProcessor : NodeProcessor 17 | { 18 | protected override void OnTranslate(ShaderTranslationContext sc, OmittedArraySizeExpressionSyntax syntax, ScopeInfo scope) 19 | { 20 | ArrayCreationExpressionSyntax arrayCreationSyntax = syntax.FirstAncestorOrSelf(); 21 | if (arrayCreationSyntax != null) 22 | { 23 | if (arrayCreationSyntax.Initializer != null) 24 | { 25 | IEnumerable initChildren = arrayCreationSyntax.Initializer.ChildNodes(); 26 | int arraySize = initChildren.Count(); 27 | sc.Source.Append(arraySize.ToString()); 28 | } 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /SharpShader/Processors/ArrayTypeProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class ArrayTypeProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, ArrayTypeSyntax syntax, ScopeInfo scope) 14 | { 15 | sc.Complete(syntax.ElementType); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /SharpShader/Processors/ArrowExpressionProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class ArrowExpressionProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, ArrowExpressionClauseSyntax syntax, ScopeInfo scope) 14 | { 15 | if(scope.Type == ScopeType.Method) 16 | { 17 | sc.Source.OpenScope(ScopeType.Block); 18 | if (scope.Method.ReturnType != typeof(void)) 19 | sc.Source.Append("return "); 20 | 21 | sc.Source.OpenScope(ScopeType.Variable); 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /SharpShader/Processors/AssignmentProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class AssignmentProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, AssignmentExpressionSyntax syntax, ScopeInfo scope) 14 | { 15 | if(scope.Type == ScopeType.ExpandedInitializer) 16 | { 17 | sc.Source.Append($"{scope.Identifier}."); 18 | sc.Source.OpenScope(ScopeType.Variable); 19 | } 20 | 21 | // TODO check if the assignment uses a valid operator. Does the language support operand assignments (e.g *= += or /=) 22 | sc.Runner.Translate(sc, syntax.Left); 23 | if (sc.IsCompleted(syntax.Right)) // Property translation may have replaced the assignment with a set-method call. 24 | return; 25 | 26 | sc.Source.Append($" {syntax.OperatorToken} "); 27 | sc.Runner.Translate(sc, syntax.Right); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /SharpShader/Processors/BinaryExpressionProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class BinaryExpressionProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, BinaryExpressionSyntax syntax, ScopeInfo scope) 14 | { 15 | sc.Runner.Translate(sc, syntax.Left); 16 | sc.Source.Append($" {syntax.OperatorToken} "); 17 | sc.Runner.Translate(sc, syntax.Right); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /SharpShader/Processors/BlockProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class BlockProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, BlockSyntax syntax, ScopeInfo scope) 14 | { 15 | if (syntax.Parent is UnsafeStatementSyntax || scope == sc.Source.RootScope) 16 | return; 17 | 18 | bool declarative = scope.Parent.Type == ScopeType.Method; 19 | sc.Source.OpenScope(ScopeType.Block); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SharpShader/Processors/ClassProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class ClassProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, ClassDeclarationSyntax syntax, ScopeInfo scope) 14 | { 15 | if ($"{sc.ShaderType.Namespace}.{syntax.Identifier.ValueText}" != sc.Name) 16 | { 17 | // TODO does the shader language support classes? 18 | // If not, we need a system to translate the class into another form of usable output source. 19 | Type t = sc.Parent.Reflection.Assembly.GetType($"{scope.Namespace}+{syntax.Identifier.ValueText}"); 20 | ScopeInfo cScope = sc.Source.OpenScope(ScopeType.Class, t); 21 | } 22 | else 23 | { 24 | sc.Complete(syntax.BaseList); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /SharpShader/Processors/EqualsValueClauseProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class EqualsValueClauseProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext context, EqualsValueClauseSyntax syntax, ScopeInfo scope) 14 | { 15 | context.Source.Append($" {syntax.EqualsToken} "); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /SharpShader/Processors/FieldProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class FieldProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, FieldDeclarationSyntax syntax, ScopeInfo scope) 14 | { 15 | // Does the language allow instanced constant buffers and does the field use a constant buffer struct type? 16 | if (sc.ConstantBuffers.ContainsKey(syntax.Declaration.Type.ToString())) 17 | { 18 | if (!sc.Language.InstancedConstantBuffers) 19 | sc.CompleteSelfAndChildren(syntax); 20 | } 21 | else 22 | { 23 | sc.CompleteSelfAndChildren(syntax.AttributeLists); 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /SharpShader/Processors/GenericWhereProcessor.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis.CSharp.Syntax; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SharpShader.Processors 9 | { 10 | internal class GenericWhereProcessor : NodeProcessor 11 | { 12 | protected override void OnTranslate(ShaderTranslationContext sc, TypeParameterConstraintClauseSyntax syntax, ScopeInfo scope) 13 | { 14 | sc.CompleteSelfAndChildren(syntax); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /SharpShader/Processors/IfStatementProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class IfStatementProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, IfStatementSyntax syntax, ScopeInfo scope) 14 | { 15 | sc.Source.Append("if("); 16 | sc.Runner.Translate(sc, syntax.Condition); 17 | sc.Source.Append(")"); 18 | if (!(syntax.Statement is BlockSyntax)) 19 | sc.Source.OpenScope(ScopeType.Block); 20 | } 21 | } 22 | 23 | internal class ElseStatementProcessor : NodeProcessor 24 | { 25 | protected override void OnTranslate(ShaderTranslationContext sc, ElseClauseSyntax syntax, ScopeInfo scope) 26 | { 27 | sc.Source.Append("else "); 28 | if (!(syntax.Statement is BlockSyntax || syntax.Statement is IfStatementSyntax)) 29 | sc.Source.OpenScope(ScopeType.Block); 30 | } 31 | } 32 | 33 | /// 34 | /// A processor for inline if statements. 35 | /// 36 | internal class CondtionalProcessor : NodeProcessor 37 | { 38 | protected override void OnTranslate(ShaderTranslationContext sc, ConditionalExpressionSyntax syntax, ScopeInfo scope) 39 | { 40 | sc.Runner.Translate(sc, syntax.Condition); 41 | sc.Source.Append(" ? "); 42 | sc.Runner.Translate(sc, syntax.WhenTrue); 43 | sc.Source.Append(" : "); 44 | sc.Runner.Translate(sc, syntax.WhenFalse); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /SharpShader/Processors/InitializerProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class InitializerProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, InitializerExpressionSyntax syntax, ScopeInfo scope) 14 | { 15 | if (syntax.Parent is ArrayCreationExpressionSyntax arrayCreationSyntax || syntax.Parent is EqualsValueClauseSyntax equalsAssignmentSyntax) 16 | { 17 | ScopeInfo iScope = sc.Source.OpenScope(ScopeType.ArrayInitializer); 18 | iScope.Items = syntax.Expressions; 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SharpShader/Processors/LiteralExpressionProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class LiteralExpressionProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, LiteralExpressionSyntax syntax, ScopeInfo scope) 14 | { 15 | sc.Source.Append(syntax.Token); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /SharpShader/Processors/LoopProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class ForLoopProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, ForStatementSyntax syntax, ScopeInfo scope) 14 | { 15 | sc.Language.TranslateForLoopPrefix(sc, syntax); 16 | sc.Source.AppendLineBreak(); 17 | sc.Source.Append("for("); 18 | 19 | if (syntax.Declaration != null) 20 | sc.Runner.Translate(sc, syntax.Declaration); 21 | 22 | TranslateList(sc, syntax.Initializers); 23 | sc.Source.Append("; "); 24 | sc.Runner.Translate(sc, syntax.Condition); 25 | sc.Source.Append("; "); 26 | TranslateList(sc, syntax.Incrementors); 27 | sc.Source.Append(")"); 28 | } 29 | 30 | private void TranslateList(ShaderTranslationContext sc, SeparatedSyntaxList list) where T : SyntaxNode 31 | { 32 | T firstIncrementor = list.FirstOrDefault(); 33 | foreach (T es in list) 34 | { 35 | Type test = es.GetType(); 36 | if (es != firstIncrementor) 37 | sc.Source.Append(", "); 38 | 39 | sc.Runner.Translate(sc, es); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /SharpShader/Processors/MethodDeclarationProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Microsoft.CodeAnalysis; 8 | using Microsoft.CodeAnalysis.CSharp.Syntax; 9 | 10 | namespace SharpShader.Processors 11 | { 12 | internal class MethodDeclarationProcessor : NodeProcessor 13 | { 14 | protected override void OnTranslate(ShaderTranslationContext sc, MethodDeclarationSyntax syntax, ScopeInfo scope) 15 | { 16 | MethodInfo info = sc.GetMethodInfo(syntax); 17 | if (info != null) 18 | { 19 | MappedEntryPoint ep = null; 20 | sc.EntryPointsByMethod.TryGetValue(info, out ep); 21 | 22 | sc.Source.AppendLineBreak(); 23 | ScopeInfo mScope = sc.Source.OpenScope(ScopeType.Method, null, ep); 24 | mScope.Method = info; 25 | 26 | ShaderType returnType = ShaderType.TranslateType(sc, syntax.ReturnType.ToString()); 27 | 28 | ep?.Translator?.TranslatePrefix(sc, info, syntax, ep); 29 | sc.Source.Append($"{returnType.Translation} {syntax.Identifier.ValueText}"); 30 | 31 | sc.Complete(syntax.ReturnType); 32 | sc.Complete(syntax.ConstraintClauses); 33 | sc.Complete(syntax.AttributeLists); 34 | 35 | if (syntax.TypeParameterList != null) 36 | sc.CompleteSelfAndChildren(syntax.TypeParameterList); 37 | 38 | // Translate parameters before method body. 39 | sc.Runner.Translate(sc, syntax.ParameterList, 0); 40 | ep?.Translator?.TranslatePostfix(sc, info, syntax, ep); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /SharpShader/Processors/NodeProcessor.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | using Microsoft.CodeAnalysis.CSharp; 3 | using Microsoft.CodeAnalysis.CSharp.Syntax; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Text.RegularExpressions; 9 | using System.Threading.Tasks; 10 | 11 | namespace SharpShader 12 | { 13 | internal abstract class NodeProcessor 14 | { 15 | /// 16 | /// Returns true 17 | /// 18 | /// The . 19 | /// The to be translated. 20 | internal abstract void Translate(ShaderTranslationContext sc, SyntaxNode syntax, ScopeInfo scope); 21 | 22 | internal abstract Type ParsedType { get; } 23 | } 24 | 25 | internal abstract class NodeProcessor : NodeProcessor 26 | where T : SyntaxNode 27 | { 28 | internal override sealed Type ParsedType => typeof(T); 29 | 30 | internal override sealed void Translate(ShaderTranslationContext sc, SyntaxNode node, ScopeInfo scope) 31 | { 32 | OnTranslate(sc, node as T, scope); 33 | } 34 | 35 | protected abstract void OnTranslate(ShaderTranslationContext sc, T syntax, ScopeInfo scope); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /SharpShader/Processors/ParenthesizedExpressionProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class ParenthesizedExpressionProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, ParenthesizedExpressionSyntax syntax, ScopeInfo scope) 14 | { 15 | ScopeInfo pScope = sc.Source.OpenScope(ScopeType.Parentheses); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /SharpShader/Processors/PredefinedTypeProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class PredefinedTypeProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, PredefinedTypeSyntax syntax, ScopeInfo scope) 14 | { 15 | string typeName = syntax.Keyword.ToString(); 16 | ShaderType type = ShaderType.TranslateType(sc, typeName); 17 | sc.Source.Append(type.Translation); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /SharpShader/Processors/PropertyProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Microsoft.CodeAnalysis; 8 | using Microsoft.CodeAnalysis.CSharp.Syntax; 9 | 10 | namespace SharpShader.Processors 11 | { 12 | internal class PropertyProcessor : NodeProcessor 13 | { 14 | protected override void OnTranslate(ShaderTranslationContext sc, PropertyDeclarationSyntax syntax, ScopeInfo scope) 15 | { 16 | ScopeInfo classScope = scope.FindOfType(ScopeType.Class); 17 | ScopeInfo pScope = sc.Source.OpenScope(ScopeType.Property); 18 | pScope.Identifier = syntax.Identifier.ValueText; 19 | 20 | sc.Complete(syntax.Type); 21 | 22 | pScope.TypeInfo = ShaderType.TranslateType(sc, syntax.Type.ToString()); 23 | } 24 | } 25 | 26 | internal class AccessorProcessor : NodeProcessor 27 | { 28 | protected override void OnTranslate(ShaderTranslationContext sc, AccessorDeclarationSyntax syntax, ScopeInfo scope) 29 | { 30 | if(scope.Type == ScopeType.Property) 31 | { 32 | switch (syntax.Keyword.ValueText) 33 | { 34 | case "get": 35 | sc.Source.Append($"{scope.TypeInfo.Translation} get{scope.Identifier}()"); 36 | break; 37 | 38 | case "set": 39 | sc.Source.Append($"void set{scope.Identifier}({scope.TypeInfo.Translation} value)"); 40 | break; 41 | } 42 | 43 | ScopeInfo mScope = sc.Source.OpenScope(ScopeType.Method); 44 | ScopeInfo classScope = scope.FindOfType(ScopeType.Class); 45 | mScope.Method = classScope.TypeInfo.OriginalType.GetMethod($"{syntax.Keyword.ValueText}_{scope.Identifier}"); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /SharpShader/Processors/ReturnProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class ReturnProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, ReturnStatementSyntax syntax, ScopeInfo scope) 14 | { 15 | sc.Source.Append("return "); 16 | sc.Source.OpenScope(ScopeType.Variable); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /SharpShader/Processors/StatementProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class StatementProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, ExpressionStatementSyntax syntax, ScopeInfo scope) 14 | { 15 | sc.Source.OpenScope(ScopeType.Variable); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /SharpShader/Processors/StructProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class StructProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, StructDeclarationSyntax syntax, ScopeInfo scope) 14 | { 15 | string typeName = syntax.Identifier.ToString(); 16 | string headerTranslation = ""; 17 | StructScopeType scopeType = StructScopeType.Struct; 18 | Type sType = null; 19 | 20 | if (sc.ConstantBuffers.TryGetValue(typeName, out MappedConstantBuffer cMap)) 21 | { 22 | sType = cMap.TypeInfo; 23 | IEnumerable cBufferAttributes = sType.GetCustomAttributes(false).Cast(); 24 | sc.Language.TranslateConstBufferHeader(sc, syntax, cMap, cBufferAttributes); 25 | scopeType = StructScopeType.ConstantBuffer; 26 | } 27 | else if (sc.Structures.TryGetValue(typeName, out sType)) 28 | { 29 | //IEnumerable cBufferAttributes = structInfo.GetCustomAttributes(false).Cast(); 30 | // TODO Add translation of struct attributes (e.g. [InputStructure] or [OutputStructure]). 31 | 32 | sc.Source.AppendLineBreak(); 33 | sc.Source.Append($"struct {syntax.Identifier}"); 34 | scopeType = StructScopeType.Struct; 35 | } 36 | 37 | sc.Source.Append(headerTranslation); 38 | ScopeInfo structScope = sc.Source.OpenScope(ScopeType.Struct, sType); 39 | structScope.StructType = scopeType; 40 | 41 | sc.CompleteSelfAndChildren(syntax.AttributeLists); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /SharpShader/Processors/UnaryProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | 9 | namespace SharpShader.Processors 10 | { 11 | internal class UnaryPrefixProcessor : NodeProcessor 12 | { 13 | protected override void OnTranslate(ShaderTranslationContext sc, PrefixUnaryExpressionSyntax syntax, ScopeInfo scope) 14 | { 15 | sc.Source.Append(syntax.OperatorToken); 16 | sc.Runner.Translate(sc, syntax.Operand); 17 | } 18 | } 19 | 20 | internal class UnaryPostfixProcessor : NodeProcessor 21 | { 22 | protected override void OnTranslate(ShaderTranslationContext sc, PostfixUnaryExpressionSyntax syntax, ScopeInfo scope) 23 | { 24 | sc.Runner.Translate(sc, syntax.Operand); 25 | sc.Source.Append(syntax.OperatorToken); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /SharpShader/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SharpShader")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SharpShader")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("50309a0e-f5e6-4bb4-bf59-e66cb9c90d2f")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("0.0.6.0")] 36 | [assembly: AssemblyFileVersion("0.0.6.0")] 37 | -------------------------------------------------------------------------------- /SharpShader/SharpShader.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SharpShader 5 | 0.0.6-alpha 6 | James Yarwood 7 | James Yarwood 8 | https://github.com/Syncaidius/SharpShader/blob/master/LICENSE 9 | https://github.com/Syncaidius/SharpShader 10 | https://github.com/Syncaidius/SharpShader/blob/master/SharpShader/logo.png?raw=true 11 | true 12 | Write your cross-platform shaders in C#. 13 | ShaderTranslationResult now provides basic entry-point information. 14 | 15 | Note: SharpShader currently supports HLSL only. GLSL support will come soon. 16 | Copyright © 2019 James Yarwood 17 | Shaders HLSL GLSL Translator Source Game Shader C# CSharp Intermediate Converter 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /SharpShader/SourceSegment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | internal class SourceSegment : IPoolable 10 | { 11 | internal string Value { get; set; } 12 | 13 | internal SourceSegment Previous { get; set; } 14 | 15 | internal SourceSegment Next { get; set; } 16 | 17 | /// 18 | /// Gets or sets the which was used in conjunction with the current to represent the start and end of a scope. 19 | /// 20 | internal SourceSegment ScopePartner { get; set; } 21 | 22 | /// 23 | /// An optional tracker for tracing the start and end index of the current , once it is applied to the final result. 24 | /// 25 | internal ISegmentTracker Tracker { get; set; } 26 | 27 | internal IndentMode Indentation { get; set; } 28 | 29 | internal ScopeMode Scope { get; set; } 30 | 31 | public void Clear() 32 | { 33 | Next = null; 34 | Previous = null; 35 | Value = null; 36 | Tracker = null; 37 | ScopePartner = null; 38 | Indentation = IndentMode.None; 39 | } 40 | } 41 | 42 | internal interface ISegmentTracker 43 | { 44 | int StartIndex { get; set; } 45 | 46 | int EndIndex { get; set; } 47 | } 48 | 49 | internal enum ScopeMode 50 | { 51 | None = 0, 52 | 53 | Opening = 1, 54 | 55 | Closing = 2, 56 | } 57 | 58 | internal enum IndentMode 59 | { 60 | None = 0, 61 | 62 | Increment = 1, 63 | 64 | Decrement = 2, 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /SharpShader/TranslationArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | internal class TranslationArgs : MarshalByRefObject 10 | { 11 | /// 12 | /// C# source strings, indexed by friendly name or file name. 13 | /// 14 | public Dictionary CSharpSources; 15 | 16 | public List PreprocessorSymbols; 17 | 18 | /// 19 | /// The output language. 20 | /// 21 | public OutputLanguage Language; 22 | 23 | /// 24 | /// The flags to apply to the conversion. 25 | /// 26 | public TranslationFlags Flags; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /SharpShader/TranslationContext.ReflectionInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SharpShader 9 | { 10 | internal partial class TranslationContext : MarshalByRefObject 11 | { 12 | internal class ReflectionInfo 13 | { 14 | internal List ShaderTypes { get; private set; } 15 | 16 | Assembly _assembly; 17 | 18 | internal Assembly Assembly 19 | { 20 | get => _assembly; 21 | set 22 | { 23 | if (_assembly != value) 24 | { 25 | _assembly = value; 26 | ShaderTypes = FindOfType().ToList(); 27 | } 28 | } 29 | } 30 | 31 | internal bool IsShaderType(Type t) 32 | { 33 | return ShaderTypes.IndexOf(t) > -1; 34 | } 35 | 36 | /// 37 | /// Finds all types which are a sub-class of the specified type and not abstract, in the current . 38 | /// 39 | /// The type of which to find sub-classes. 40 | /// 41 | internal IEnumerable FindOfType() where T : class 42 | { 43 | Type pType = typeof(T); 44 | IEnumerable test = _assembly.GetTypes(); 45 | return _assembly.GetTypes().Where(t => t.IsSubclassOf(pType) && !t.IsAbstract); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /SharpShader/TranslationFlags.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SharpShader 8 | { 9 | [Flags] 10 | public enum TranslationFlags 11 | { 12 | /// 13 | /// No flags. 14 | /// 15 | None = 0, 16 | 17 | /// 18 | /// Avoids adding whitespace for formatting, to the translated shader code. 19 | /// 20 | NoWhitespace = 1, 21 | 22 | /// 23 | /// Strips code comments and summaries from the translated shader code. 24 | /// 25 | StripComments = 4, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /SharpShader/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Syncaidius/SharpShader/1f0625e5d40550e1566c1f649afd5a24c95b6ffb/SharpShader/logo.png -------------------------------------------------------------------------------- /SharpShaderSample/Program.cs: -------------------------------------------------------------------------------- 1 | using SharpShader; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SharpShaderSample 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | string[] samples = { 16 | "FunctionalityTestShader.cs", 17 | //"SampleShader.cs", 18 | //"SampleTextureShader.cs", 19 | //"MoltenSpriteShader.cs" 20 | }; 21 | 22 | Translator translator = new Translator(); 23 | TranslationResult output = null; 24 | OutputLanguage language = OutputLanguage.HLSL; 25 | 26 | // Load all of the sources into a dictionary, 27 | // so that all of them can be translated in a single converter.Convert() call. 28 | Dictionary sources = new Dictionary(); 29 | foreach (string fn in samples) 30 | { 31 | Console.WriteLine($"Reading {fn}"); 32 | 33 | FileInfo fInfo = new FileInfo(fn); 34 | string strInput = File.ReadAllText(fn); 35 | sources.Add(fn, strInput); 36 | } 37 | 38 | output = translator.Translate(sources, language); 39 | 40 | // Store the output to file so we can take a look at it ourselves. 41 | if (output != null) 42 | { 43 | string langExtension = $"{language.ToString().ToLower()}"; 44 | 45 | foreach (KeyValuePair kvp in output) 46 | { 47 | using (FileStream fs = new FileStream($"{kvp.Key}.{langExtension}", FileMode.Create, FileAccess.Write)) 48 | { 49 | using (StreamWriter writer = new StreamWriter(fs)) 50 | { 51 | writer.Write(kvp.Value.SourceCode); 52 | } 53 | } 54 | } 55 | } 56 | 57 | Console.ReadKey(); 58 | translator.Dispose(); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /SharpShaderSample/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SharpShaderSample")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SharpShaderSample")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("3a108bb1-55d8-456c-8431-1be3053f7aa1")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /SharpShaderSample/SampleTextureShader.cs: -------------------------------------------------------------------------------- 1 | using SharpShader; 2 | 3 | namespace SharpShaderSample 4 | { 5 | class SampleTextureShader : CSharpShader 6 | { 7 | public struct VertexInput 8 | { 9 | [Semantic(SemanticType.Position, 0)] 10 | public Vector4 Position; 11 | 12 | [Semantic(SemanticType.TexCoord, 0)] 13 | public Vector2 UV; 14 | } 15 | 16 | public struct PixelInput 17 | { 18 | [Semantic(SemanticType.SV_Position)] 19 | public Vector4 Position; 20 | 21 | [Semantic(SemanticType.TexCoord)] 22 | public Vector2 UV; 23 | } 24 | 25 | [ConstantBuffer] 26 | [Register(0)] 27 | public struct CommonData 28 | { 29 | [PackOffset(0)] 30 | public Matrix4x4 View; 31 | 32 | [PackOffset(4)] 33 | public Matrix4x4 Projection; 34 | 35 | [PackOffset(8)] 36 | public Matrix4x4 ViewProjection; 37 | 38 | [PackOffset(12)] 39 | public int InvViewProjection; 40 | } 41 | 42 | [ConstantBuffer] 43 | [Register(1)] 44 | public struct ObjectData 45 | { 46 | [PackOffset(0)] 47 | public Matrix4x4 Wvp; 48 | 49 | [PackOffset(4, PackOffsetComponent.Y)] 50 | public Matrix4x4 World; 51 | } 52 | 53 | public ObjectData cbObject; 54 | 55 | [Register(0)] 56 | public Texture2D mapTexture, mapNormals, mapSpecular; 57 | 58 | [Register(0)] 59 | public TextureSampler texSampler; 60 | 61 | [VertexShader] 62 | public PixelInput VertexFunc(VertexInput input) 63 | { 64 | return new PixelInput() 65 | { 66 | Position = Mul(input.Position, cbObject.Wvp), 67 | UV = input.UV, 68 | }; 69 | } 70 | 71 | [FragmentShader, Semantic(SemanticType.SV_Target)] 72 | public Vector4 FragFunc(PixelInput input) 73 | { 74 | return mapTexture.Sample(texSampler, input.UV); 75 | } 76 | } 77 | } 78 | --------------------------------------------------------------------------------