Merge pull request #25 from Sergio0694/feature_improved-hlsl-comments

Improved hlsl comments
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2019-08-17 23:58:21 +02:00
コミット d8939f345a
9ファイル変更
+107 -40

検索条件に一致するファイルはありません

+50
ファイルの表示
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
namespace ComputeSharp.Shaders.Extensions
{
/// <summary>
/// A <see langword="class"/> that provides extension methods for the <see cref="Type"/> type
/// </summary>
internal static class TypeExtensions
{
/// <summary>
/// The mapping of supported known types to display string
/// </summary>
private static readonly IReadOnlyDictionary<Type, string> KnownTypes = new Dictionary<Type, string>
{
[typeof(bool)] = "bool",
[typeof(int)] = "int",
[typeof(uint)] = "uint",
[typeof(float)] = "float",
[typeof(double)] = "double"
};
/// <summary>
/// Gets a friendly display <see langword="string"/> for the input type
/// </summary>
/// <param name="type">The input type to analyze</param>
[Pure]
public static string ToFriendlyString(this Type type)
{
// Array types of arbitrary rank
if (type.IsArray)
{
int rank = type.GetArrayRank();
return $"{type.GetElementType().ToFriendlyString()}[{new string(Enumerable.Repeat(',', rank - 1).ToArray())}]";
}
// Non generic types
string name;
if (type.GetGenericArguments().Length == 0) return KnownTypes.TryGetValue(type, out name) ? name : type.Name;
// Generic types
Type[] genericArguments = type.GetGenericArguments();
string typeDefeninition = KnownTypes.TryGetValue(type, out name) ? name : type.Name;
string polishedName = typeDefeninition.Substring(0, typeDefeninition.IndexOf("`"));
return $"{polishedName}<{string.Join(",", genericArguments.Select(ToFriendlyString))}>";
}
}
}
+6 -3
ファイルの表示
@@ -1,4 +1,6 @@
namespace ComputeSharp.Shaders.Renderer.Models.Fields.Abstract
using System;
namespace ComputeSharp.Shaders.Renderer.Models.Fields.Abstract
{
/// <summary>
/// A <see langword="class"/> that contains info on a shader buffer field
@@ -13,10 +15,11 @@
/// <summary>
/// Creates a new <see cref="HlslBufferInfo"/> instance with the specified parameters
/// </summary>
/// <param name="fieldType">The type of the current field</param>
/// <param name="fieldCsharpType">The type of the current field in the C# source</param>
/// <param name="fieldHlslType">The type of the current field in the HLSL shader</param>
/// <param name="fieldName">The name of the current field</param>
/// <param name="bufferIndex">The index of the current buffer field</param>
protected HlslBufferInfo(string fieldType, string fieldName, int bufferIndex) : base(fieldType, fieldName)
protected HlslBufferInfo(Type fieldCsharpType, string fieldHlslType, string fieldName, int bufferIndex) : base(fieldCsharpType, fieldHlslType, fieldName)
{
BufferIndex = bufferIndex;
}
+19 -9
ファイルの表示
@@ -1,4 +1,7 @@
namespace ComputeSharp.Shaders.Renderer.Models.Fields
using System;
using ComputeSharp.Shaders.Extensions;
namespace ComputeSharp.Shaders.Renderer.Models.Fields
{
/// <summary>
/// A <see langword="class"/> that contains info on a shader field
@@ -6,23 +9,30 @@
internal class CapturedFieldInfo
{
/// <summary>
/// Gets or sets the type of the current field
/// Gets the type of the current field in the C# source
/// </summary>
public string FieldType { get; set; }
public string FieldCsharpType { get; }
/// <summary>
/// Gets or sets the name to use for the current field
/// Gets the type of the current field in the HLSL shader
/// </summary>
public string FieldName { get; set; }
public string FieldHlslType { get; }
/// <summary>
/// Gets the name to use for the current field
/// </summary>
public string FieldName { get; }
/// <summary>
/// Creates a new <see cref="CapturedFieldInfo"/> instance with the specified parameters
/// </summary>
/// <param name="fieldType">The type of the current field</param>
/// <param name="fieldName">The name of the current field</param>
public CapturedFieldInfo(string fieldType, string fieldName)
/// <param name="fieldCsharpType">The type of the current field in the C# source</param>
/// <param name="fieldHlslType">The type of the current field in the HLSL shader</param>
/// <param name="fieldName">The name to use for the current field</param>
public CapturedFieldInfo(Type fieldCsharpType, string fieldHlslType, string fieldName)
{
FieldType = fieldType;
FieldCsharpType = fieldCsharpType.ToFriendlyString();
FieldHlslType = fieldHlslType;
FieldName = fieldName;
}
}
+6 -3
ファイルの表示
@@ -1,4 +1,5 @@
using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
using System;
using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
namespace ComputeSharp.Shaders.Renderer.Models.Fields
{
@@ -15,9 +16,11 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields
/// <summary>
/// Creates a new <see cref="ConstantBufferFieldInfo"/> instance with the specified parameters
/// </summary>
/// <param name="fieldType">The type of the current field</param>
/// <param name="fieldCsharpType">The type of the current field in the C# source</param>
/// <param name="fieldHlslType">The type of the current field in the HLSL shader</param>
/// <param name="fieldName">The name of the current field</param>
/// <param name="bufferIndex">The index of the current constant buffer field</param>
public ConstantBufferFieldInfo(string fieldType, string fieldName, int bufferIndex) : base(fieldType, fieldName, bufferIndex) { }
public ConstantBufferFieldInfo(Type fieldCsharpType, string fieldHlslType, string fieldName, int bufferIndex)
: base(fieldCsharpType, fieldHlslType, fieldName, bufferIndex) { }
}
}
+6 -3
ファイルの表示
@@ -1,4 +1,5 @@
using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
using System;
using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
namespace ComputeSharp.Shaders.Renderer.Models.Fields
{
@@ -15,9 +16,11 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields
/// <summary>
/// Creates a new <see cref="ReadOnlyBufferFieldInfo"/> instance with the specified parameters
/// </summary>
/// <param name="fieldType">The type of the current field</param>
/// <param name="fieldCsharpType">The type of the current field in the C# source</param>
/// <param name="fieldHlslType">The type of the current field in the HLSL shader</param>
/// <param name="fieldName">The name of the current field</param>
/// <param name="bufferIndex">The index of the current readonly buffer field</param>
public ReadOnlyBufferFieldInfo(string fieldType, string fieldName, int bufferIndex) : base(fieldType, fieldName, bufferIndex) { }
public ReadOnlyBufferFieldInfo(Type fieldCsharpType, string fieldHlslType, string fieldName, int bufferIndex)
: base(fieldCsharpType, fieldHlslType, fieldName, bufferIndex) { }
}
}
+6 -3
ファイルの表示
@@ -1,4 +1,5 @@
using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
using System;
using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
namespace ComputeSharp.Shaders.Renderer.Models.Fields
{
@@ -15,9 +16,11 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields
/// <summary>
/// Creates a new <see cref="ReadWriteBufferFieldInfo"/> instance with the specified parameters
/// </summary>
/// <param name="fieldType">The type of the current field</param>
/// <param name="fieldCsharpType">The type of the current field in the C# source</param>
/// <param name="fieldHlslType">The type of the current field in the HLSL shader</param>
/// <param name="fieldName">The name of the current field</param>
/// <param name="bufferIndex">The index of the current read write buffer field</param>
public ReadWriteBufferFieldInfo(string fieldType, string fieldName, int bufferIndex) : base(fieldType, fieldName, bufferIndex) { }
public ReadWriteBufferFieldInfo(Type fieldCsharpType, string fieldHlslType, string fieldName, int bufferIndex)
: base(fieldCsharpType, fieldHlslType, fieldName, bufferIndex) { }
}
}
-5
ファイルの表示
@@ -11,11 +11,6 @@ namespace ComputeSharp.Shaders.Renderer.Models
/// </summary>
internal sealed class ShaderInfo
{
/// <summary>
/// Gets the text indicating a generic type, which can't be escaped in mustache
/// </summary>
public string T { get; } = "<T>";
/// <summary>
/// Gets the list of captured buffers being present in the current shader
/// </summary>
+10 -10
ファイルの表示
@@ -6,37 +6,37 @@
* For info or issues: https://github.com/Sergio0694/ComputeSharp */
{{!Captured variables buffer}}
// Captured scalar/vector variables
cbuffer __Variables__Buffer : register(b0)
// Scalar/vector variables
cbuffer _ : register(b0)
{
uint __x__; // Target X iterations
uint __y__; // Target Y iterations
uint __z__; // Target Z iterations
{{#FieldsList}}
{{&FieldType}} {{FieldName}};
{{&FieldHlslType}} {{FieldName}};
{{/FieldsList}}
}
{{#BuffersList}}
{{#IsConstantBuffer}}
{{!Constant buffer}}
// Captured ConstantBuffer{{&T}} buffer "{{FieldName}}"
cbuffer {{FieldName}}Buffer : register(b{{BufferIndex}})
// {{&FieldCsharpType}} buffer "{{FieldName}}"
cbuffer _{{FieldName}} : register(b{{BufferIndex}})
{
{{&FieldType}} {{FieldName}}[2];
{{&FieldHlslType}} {{FieldName}}[2];
}
{{/IsConstantBuffer}}
{{#IsReadOnlyBuffer}}
{{!Readonly buffer}}
// Captured ReadOnlyBuffer{{&T}} buffer "{{FieldName}}"
{{&FieldType}} {{FieldName}} : register(t{{BufferIndex}});
// {{&FieldCsharpType}} buffer "{{FieldName}}"
{{&FieldHlslType}} {{FieldName}} : register(t{{BufferIndex}});
{{/IsReadOnlyBuffer}}
{{#IsReadWriteBuffer}}
{{!Read write buffer}}
// Captured ReadWriteBuffer{{&T}} buffer "{{FieldName}}"
{{&FieldType}} {{FieldName}} : SV_DispatchThreadId : register(u{{BufferIndex}});
// {{&FieldCsharpType}} buffer "{{FieldName}}"
{{&FieldHlslType}} {{FieldName}} : SV_DispatchThreadId : register(u{{BufferIndex}});
{{/IsReadWriteBuffer}}
{{/BuffersList}}
+4 -4
ファイルの表示
@@ -139,7 +139,7 @@ namespace ComputeSharp.Shaders.Translation
_BufferFields.Add(fieldInfo);
string typeName = HlslKnownTypes.GetMappedName(fieldType.GenericTypeArguments[0]);
_BuffersList.Add(new ConstantBufferFieldInfo(typeName, fieldName, constantBuffersCount++));
_BuffersList.Add(new ConstantBufferFieldInfo(fieldType, typeName, fieldName, constantBuffersCount++));
}
else if (HlslKnownTypes.IsReadOnlyBufferType(fieldType))
{
@@ -150,7 +150,7 @@ namespace ComputeSharp.Shaders.Translation
_BufferFields.Add(fieldInfo);
string typeName = HlslKnownTypes.GetMappedName(fieldType);
_BuffersList.Add(new ReadOnlyBufferFieldInfo(typeName, fieldName, readOnlyBuffersCount++));
_BuffersList.Add(new ReadOnlyBufferFieldInfo(fieldType, typeName, fieldName, readOnlyBuffersCount++));
}
else if (HlslKnownTypes.IsReadWriteBufferType(fieldType))
{
@@ -161,14 +161,14 @@ namespace ComputeSharp.Shaders.Translation
_BufferFields.Add(fieldInfo);
string typeName = HlslKnownTypes.GetMappedName(fieldType);
_BuffersList.Add(new ReadWriteBufferFieldInfo(typeName, fieldName, readWriteBuffersCount++));
_BuffersList.Add(new ReadWriteBufferFieldInfo(fieldType, typeName, fieldName, readWriteBuffersCount++));
}
else if (HlslKnownTypes.IsKnownScalarType(fieldType) || HlslKnownTypes.IsKnownVectorType(fieldType))
{
// Register the captured field
_VariableFields.Add(fieldInfo);
string typeName = HlslKnownTypes.GetMappedName(fieldType);
_FieldsList.Add(new CapturedFieldInfo(typeName, fieldName));
_FieldsList.Add(new CapturedFieldInfo(fieldType, typeName, fieldName));
}
else throw new NotSupportedException($"Unsupported field of type {fieldType.FullName}");
}