Code refactoring in the field info models

このコミットが含まれているのは:
Sergio Pedri committed 2019-08-15 18:38:26 +02:00
1 親 98e5fe86d2
コミット a2e8eef126
9ファイル変更
+48 -45

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

@@ -3,7 +3,7 @@
/// <summary>
/// A <see langword="class"/> that contains info on a shader field
/// </summary>
internal abstract class FieldInfoBase
internal abstract class FieldInfo
{
/// <summary>
/// Gets or sets the type of the current field
@@ -16,11 +16,11 @@
public string FieldName { get; set; }
/// <summary>
/// Creates a new <see cref="FieldInfoBase"/> instance with the specified parameters
/// Creates a new <see cref="FieldInfo"/> 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>
protected FieldInfoBase(string fieldType, string fieldName)
protected FieldInfo(string fieldType, string fieldName)
{
FieldType = fieldType;
FieldName = fieldName;
+24
ファイルの表示
@@ -0,0 +1,24 @@
namespace ComputeSharp.Shaders.Renderer.Models.Fields.Abstract
{
/// <summary>
/// A <see langword="class"/> that contains info on a shader buffer field
/// </summary>
internal abstract class HlslBufferInfo : FieldInfo
{
/// <summary>
/// Gets or sets the index of the current buffer, relative to its own type
/// </summary>
public int BufferIndex { get; set; }
/// <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="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)
{
BufferIndex = bufferIndex;
}
}
}
+3 -9
ファイルの表示
@@ -5,10 +5,10 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields
/// <summary>
/// A <see langword="class"/> that contains info on a constant buffer field
/// </summary>
internal sealed class ConstantBufferFieldInfo : FieldInfoBase
internal sealed class ConstantBufferFieldInfo : HlslBufferInfo
{
/// <summary>
/// Gets whether or not the current <see cref="FieldInfoBase"/> instance represents a constant buffer (always <see langword="true"/>)
/// Gets whether or not the current <see cref="FieldInfo"/> instance represents a constant buffer (always <see langword="true"/>)
/// </summary>
public bool IsConstantBuffer { get; } = true;
@@ -17,11 +17,6 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields
/// </summary>
public bool IsSingleValue { get; }
/// <summary>
/// Gets the index of the current constant buffer field
/// </summary>
public int ConstantBufferIndex { get; }
/// <summary>
/// Creates a new <see cref="ConstantBufferFieldInfo"/> instance with the specified parameters
/// </summary>
@@ -29,9 +24,8 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields
/// <param name="fieldName">The name of the current field</param>
/// <param name="bufferIndex">The index of the current constant buffer field</param>
/// <param name="singleValue">Whether or not this constant buffer actually contains a single, explicit variable</param>
public ConstantBufferFieldInfo(string fieldType, string fieldName, int bufferIndex, bool singleValue) : base(fieldType, fieldName)
public ConstantBufferFieldInfo(string fieldType, string fieldName, int bufferIndex, bool singleValue) : base(fieldType, fieldName, bufferIndex)
{
ConstantBufferIndex = bufferIndex;
IsSingleValue = singleValue;
}
}
+3 -11
ファイルの表示
@@ -5,27 +5,19 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields
/// <summary>
/// A <see langword="class"/> that contains info on a readonly buffer field
/// </summary>
internal sealed class ReadOnlyBufferFieldInfo : FieldInfoBase
internal sealed class ReadOnlyBufferFieldInfo : HlslBufferInfo
{
/// <summary>
/// Gets whether or not the current <see cref="FieldInfoBase"/> instance represents a readonly buffer (always <see langword="true"/>)
/// Gets whether or not the current <see cref="FieldInfo"/> instance represents a readonly buffer (always <see langword="true"/>)
/// </summary>
public bool IsReadOnlyBuffer { get; } = true;
/// <summary>
/// Gets the index of the current constant buffer field
/// </summary>
public int ReadOnlyBufferIndex { get; }
/// <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="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)
{
ReadOnlyBufferIndex = bufferIndex;
}
public ReadOnlyBufferFieldInfo(string fieldType, string fieldName, int bufferIndex) : base(fieldType, fieldName, bufferIndex) { }
}
}
+3 -11
ファイルの表示
@@ -5,27 +5,19 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields
/// <summary>
/// A <see langword="class"/> that contains info on a read write buffer field
/// </summary>
internal sealed class ReadWriteBufferFieldInfo : FieldInfoBase
internal sealed class ReadWriteBufferFieldInfo : HlslBufferInfo
{
/// <summary>
/// Gets whether or not the current <see cref="FieldInfoBase"/> instance represents a read write buffer (always <see langword="true"/>)
/// Gets whether or not the current <see cref="FieldInfo"/> instance represents a read write buffer (always <see langword="true"/>)
/// </summary>
public bool IsReadWriteBuffer { get; } = true;
/// <summary>
/// Gets the index of the current read write buffer field
/// </summary>
public int ReadWriteBufferIndex { get; set; }
/// <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="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)
{
ReadWriteBufferIndex = bufferIndex;
}
public ReadWriteBufferFieldInfo(string fieldType, string fieldName, int bufferIndex) : base(fieldType, fieldName, bufferIndex) { }
}
}
+2 -2
ファイルの表示
@@ -5,10 +5,10 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields
/// <summary>
/// A <see langword="class"/> that contains info on a static scalar field
/// </summary>
internal sealed class StaticScalarFieldInfo : FieldInfoBase
internal sealed class StaticScalarFieldInfo : FieldInfo
{
/// <summary>
/// Gets whether or not the current <see cref="FieldInfoBase"/> instance represents a static scalar value (always <see langword="true"/>)
/// Gets whether or not the current <see cref="FieldInfo"/> instance represents a static scalar value (always <see langword="true"/>)
/// </summary>
public bool IsStaticScalarField { get; } = true;
+1 -1
ファイルの表示
@@ -13,7 +13,7 @@ namespace ComputeSharp.Shaders.Renderer.Models
/// <summary>
/// Gets the list of fields being present in the current shader
/// </summary>
public IReadOnlyList<FieldInfoBase> FieldsList { get; set; }
public IReadOnlyList<FieldInfo> FieldsList { get; set; }
/// <summary>
/// Gets or sets the total number of threads to run on the X axis
+2 -2
ファイルの表示
@@ -5,14 +5,14 @@ static {{&FieldType}} {{FieldName}} = {{FieldValue}};
{{/IsStaticScalarField}}
{{!Constant buffer}}
{{#IsConstantBuffer}}
cbuffer {{FieldName}}Buffer : register(b{{ConstantBufferIndex}})
cbuffer {{FieldName}}Buffer : register(b{{BufferIndex}})
{
{{&FieldType}} {{FieldName}}{{^IsSingleValue}}[2]{{/IsSingleValue}};
}
{{/IsConstantBuffer}}
{{!Read write buffer}}
{{#IsReadWriteBuffer}}
{{&FieldType}} {{FieldName}} : SV_DispatchThreadId : register(u{{ReadWriteBufferIndex}});
{{&FieldType}} {{FieldName}} : SV_DispatchThreadId : register(u{{BufferIndex}});
{{/IsReadWriteBuffer}}
{{/FieldsList}}
+7 -6
ファイルの表示
@@ -11,6 +11,7 @@ using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using SharpDX.Direct3D12;
using FieldInfo = ComputeSharp.Shaders.Renderer.Models.Fields.Abstract.FieldInfo;
#pragma warning disable CS8618 // Non-nullable field is uninitialized
@@ -39,7 +40,7 @@ namespace ComputeSharp.Shaders.Translation
/// <summary>
/// The sequence of fields in the targeted closure
/// </summary>
private readonly IReadOnlyList<FieldInfo> ShaderFields;
private readonly IReadOnlyList<System.Reflection.FieldInfo> ShaderFields;
/// <summary>
/// Creates a new <see cref="ShaderLoader"/> with the specified parameters
@@ -68,12 +69,12 @@ namespace ComputeSharp.Shaders.Translation
/// </summary>
public IReadOnlyList<(int Index, object Value)> CapturedConstantBufferValues { get; private set; }
private readonly List<FieldInfoBase> _FieldsInfo = new List<FieldInfoBase>();
private readonly List<FieldInfo> _FieldsInfo = new List<FieldInfo>();
/// <summary>
/// Gets the collection of <see cref="FieldInfoBase"/> items for the shader fields
/// Gets the collection of <see cref="FieldInfo"/> items for the shader fields
/// </summary>
public IReadOnlyList<FieldInfoBase> FieldsInfo => _FieldsInfo;
public IReadOnlyList<FieldInfo> FieldsInfo => _FieldsInfo;
/// <summary>
/// Gets the name of the <see cref="ThreadIds"/> variable used as input for the shader method
@@ -116,12 +117,12 @@ namespace ComputeSharp.Shaders.Translation
int readWriteBuffersCount = 0;
int readOnlyBuffersCount = 0;
foreach (FieldInfo fieldInfo in ShaderFields)
foreach (System.Reflection.FieldInfo fieldInfo in ShaderFields)
{
Type fieldType = fieldInfo.FieldType;
string fieldName = fieldInfo.Name;
object fieldValue = fieldInfo.GetValue(ShaderInstance);
FieldInfoBase processedFieldInfo;
FieldInfo processedFieldInfo;
// Read write buffer
if (HlslKnownTypes.IsReadWriteBufferType(fieldType))