Code refactoring to the rendering models

このコミットが含まれているのは:
Sergio Pedri committed 2020-11-26 01:22:33 +01:00
1 親 9224485334
コミット c3ec5235cc
10ファイル変更
+48 -143

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

+3 -4
ファイルの表示
@@ -3,7 +3,6 @@ using System.Buffers;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using ComputeSharp.Shaders.Renderer.Models;
using ComputeSharp.Shaders.Renderer.Models.Fields;
namespace ComputeSharp.Shaders.Renderer
{
@@ -55,7 +54,7 @@ namespace ComputeSharp.Shaders.Renderer
switch (buffer)
{
// Constant buffer go to cbuffer fields with a dummy local
case ConstantBufferFieldInfo _:
case HlslBufferInfo.Constant _:
builder.Append("cbuffer _");
builder.Append(buffer.FieldName);
builder.Append(" : register(b");
@@ -71,10 +70,10 @@ namespace ComputeSharp.Shaders.Renderer
break;
// Structured buffer have the same syntax but different id
case ReadOnlyBufferFieldInfo _:
case HlslBufferInfo.ReadOnly _:
char registerId = 't';
goto StructuredBuffer;
case ReadWriteBufferFieldInfo _:
case HlslBufferInfo.ReadWrite _:
registerId = 'u';
StructuredBuffer:
builder.Append(buffer.FieldType);
-25
ファイルの表示
@@ -1,25 +0,0 @@
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 : CapturedFieldInfo
{
/// <summary>
/// Creates a new <see cref="HlslBufferInfo"/> instance with the specified parameters.
/// </summary>
/// <param name="fieldType">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)
{
BufferIndex = bufferIndex;
}
/// <summary>
/// Gets or sets the index of the current buffer, relative to its own type.
/// </summary>
public int BufferIndex { get; set; }
}
}
-29
ファイルの表示
@@ -1,29 +0,0 @@
namespace ComputeSharp.Shaders.Renderer.Models.Fields
{
/// <summary>
/// A <see langword="class"/> that contains info on a shader field.
/// </summary>
internal class CapturedFieldInfo
{
/// <summary>
/// Creates a new <see cref="CapturedFieldInfo"/> instance with the specified parameters.
/// </summary>
/// <param name="fieldType">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(string fieldType, string fieldName)
{
FieldType = fieldType;
FieldName = fieldName;
}
/// <summary>
/// Gets the type of the current field in the HLSL shader.
/// </summary>
public string FieldType { get; }
/// <summary>
/// Gets the name to use for the current field.
/// </summary>
public string FieldName { get; }
}
}
-26
ファイルの表示
@@ -1,26 +0,0 @@
using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
namespace ComputeSharp.Shaders.Renderer.Models.Fields
{
/// <summary>
/// A <see langword="class"/> that contains info on a constant buffer field.
/// </summary>
internal sealed class ConstantBufferFieldInfo : HlslBufferInfo
{
/// <summary>
/// Creates a new <see cref="ConstantBufferFieldInfo"/> instance with the specified parameters.
/// </summary>
/// <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 fieldHlslType, string fieldName, int bufferIndex)
: base(fieldHlslType, fieldName, bufferIndex)
{
}
/// <summary>
/// Gets whether or not the current <see cref="CapturedFieldInfo"/> instance represents a constant buffer (always <see langword="true"/>).
/// </summary>
public bool IsConstantBuffer { get; } = true;
}
}
-26
ファイルの表示
@@ -1,26 +0,0 @@
using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
namespace ComputeSharp.Shaders.Renderer.Models.Fields
{
/// <summary>
/// A <see langword="class"/> that contains info on a readonly buffer field.
/// </summary>
internal sealed class ReadOnlyBufferFieldInfo : HlslBufferInfo
{
/// <summary>
/// Creates a new <see cref="ReadOnlyBufferFieldInfo"/> instance with the specified parameters.
/// </summary>
/// <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 fieldHlslType, string fieldName, int bufferIndex)
: base(fieldHlslType, fieldName, bufferIndex)
{
}
/// <summary>
/// Gets whether or not the current <see cref="CapturedFieldInfo"/> instance represents a readonly buffer (always <see langword="true"/>).
/// </summary>
public bool IsReadOnlyBuffer { get; } = true;
}
}
-26
ファイルの表示
@@ -1,26 +0,0 @@
using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
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 : HlslBufferInfo
{
/// <summary>
/// Creates a new <see cref="ReadWriteBufferFieldInfo"/> instance with the specified parameters.
/// </summary>
/// <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 fieldHlslType, string fieldName, int bufferIndex)
: base(fieldHlslType, fieldName, bufferIndex)
{
}
/// <summary>
/// Gets whether or not the current <see cref="CapturedFieldInfo"/> instance represents a read write buffer (always <see langword="true"/>).
/// </summary>
public bool IsReadWriteBuffer { get; } = true;
}
}
+32
ファイルの表示
@@ -0,0 +1,32 @@
namespace ComputeSharp.Shaders.Renderer.Models
{
/// <summary>
/// A model that contains info on a shader buffer field.
/// </summary>
/// <param name="FieldType">The type of the current field in the HLSL shader.</param>
/// <param name="FieldName">The name to use for the current field.</param>
internal abstract record HlslBufferInfo(string FieldType, string FieldName, int BufferIndex)
: CapturedFieldInfo(FieldType, FieldName)
{
/// <inheritdoc/>
/// <summary>
/// A model that represents a captured constant buffer in a shader.
/// </summary>
public sealed record Constant(string FieldType, string FieldName, int BufferIndex)
: HlslBufferInfo(FieldType, FieldName, BufferIndex);
/// <inheritdoc/>
/// <summary>
/// A model that represents a captured readonly buffer in a shader.
/// </summary>
public sealed record ReadOnly(string FieldType, string FieldName, int BufferIndex)
: HlslBufferInfo(FieldType, FieldName, BufferIndex);
/// <inheritdoc/>
/// <summary>
/// A model that represents a captured writeable buffer in a shader.
/// </summary>
public sealed record ReadWrite(string FieldType, string FieldName, int BufferIndex)
: HlslBufferInfo(FieldType, FieldName, BufferIndex);
}
}
+9
ファイルの表示
@@ -0,0 +1,9 @@
namespace ComputeSharp.Shaders.Renderer.Models
{
/// <summary>
/// A model that contains info on a shader field.
/// </summary>
/// <param name="FieldType">The type of the current field in the HLSL shader.</param>
/// <param name="FieldName">The name to use for the current field.</param>
internal record CapturedFieldInfo(string FieldType, string FieldName);
}
-2
ファイルの表示
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using ComputeSharp.Shaders.Renderer.Models.Fields;
using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
#pragma warning disable CS8618
+4 -5
ファイルの表示
@@ -5,8 +5,7 @@ using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using ComputeSharp.Shaders.Mappings;
using ComputeSharp.Shaders.Renderer.Models.Fields;
using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
using ComputeSharp.Shaders.Renderer.Models;
using ComputeSharp.Shaders.Translation.Models;
using Microsoft.Toolkit.Diagnostics;
using TerraFX.Interop;
@@ -185,7 +184,7 @@ namespace ComputeSharp.Shaders.Translation
string typeName = HlslKnownTypes.GetMappedName(fieldType.GenericTypeArguments[0]);
this.hlslBuffersInfo.Add(new ConstantBufferFieldInfo(typeName, fieldName, (int)this.constantBuffersCount++));
this.hlslBuffersInfo.Add(new HlslBufferInfo.Constant(typeName, fieldName, (int)this.constantBuffersCount++));
}
else if (HlslKnownTypes.IsReadOnlyBufferType(fieldType))
{
@@ -198,7 +197,7 @@ namespace ComputeSharp.Shaders.Translation
string typeName = HlslKnownTypes.GetMappedName(fieldType);
this.hlslBuffersInfo.Add(new ReadOnlyBufferFieldInfo(typeName, fieldName, (int)this.readOnlyBuffersCount++));
this.hlslBuffersInfo.Add(new HlslBufferInfo.Constant(typeName, fieldName, (int)this.readOnlyBuffersCount++));
}
else if (HlslKnownTypes.IsReadWriteBufferType(fieldType))
{
@@ -211,7 +210,7 @@ namespace ComputeSharp.Shaders.Translation
string typeName = HlslKnownTypes.GetMappedName(fieldType);
this.hlslBuffersInfo.Add(new ReadWriteBufferFieldInfo(typeName, fieldName, (int)this.readWriteBuffersCount++));
this.hlslBuffersInfo.Add(new HlslBufferInfo.ReadWrite(typeName, fieldName, (int)this.readWriteBuffersCount++));
}
else if (HlslKnownTypes.IsKnownScalarType(fieldType) || HlslKnownTypes.IsKnownVectorType(fieldType))
{