More code refactoring

このコミットが含まれているのは:
Sergio Pedri committed 2020-11-30 00:12:07 +01:00
1 親 f185fadc3d
コミット ea1c2dd37b
4ファイル変更
+55 -53

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

+12 -8
ファイルの表示
@@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using ComputeSharp.Shaders.Renderer.Models;
using ComputeSharp.Shaders.Translation;
namespace ComputeSharp.Shaders.Renderer
{
@@ -15,10 +16,13 @@ namespace ComputeSharp.Shaders.Renderer
/// <summary>
/// Renders a new HLSL shader source with the given parameters
/// </summary>
/// <param name="info">The input <see cref="ShaderInfo"/> instance with the shader information</param>
/// <param name="threadsX">The number of threads in each thread group for the X axis.</param>
/// <param name="threadsY">The number of threads in each thread group for the Y axis.</param>
/// <param name="threadsZ">The number of threads in each thread group for the Z axis.</param>
/// <param name="info">The input <see cref="IShaderLoader"/> instance with the shader information</param>
/// <returns>The source code for the new HLSL shader</returns>
[Pure]
public static ArrayPoolStringBuilder Render(ShaderInfo info)
public static ArrayPoolStringBuilder Render(int threadsX, int threadsY, int threadsZ, IShaderLoader info)
{
var builder = ArrayPoolStringBuilder.Create();
@@ -44,7 +48,7 @@ namespace ComputeSharp.Shaders.Renderer
builder.AppendLine(" uint __y;");
builder.AppendLine(" uint __z;");
foreach (var local in info.FieldsList)
foreach (var local in info.FieldsInfo)
{
builder.Append(" ");
builder.Append(local.FieldType);
@@ -56,7 +60,7 @@ namespace ComputeSharp.Shaders.Renderer
builder.AppendLine('}');
// Buffers
foreach (var buffer in info.BuffersList)
foreach (var buffer in info.HslsBuffersInfo)
{
builder.AppendLine();
@@ -97,7 +101,7 @@ namespace ComputeSharp.Shaders.Renderer
}
// Local functions
foreach (var function in info.LocalFunctionsList)
foreach (var function in info.LocalFunctionsInfo)
{
builder.AppendLine();
builder.AppendLine(function);
@@ -106,11 +110,11 @@ namespace ComputeSharp.Shaders.Renderer
// Entry point
builder.AppendLine();
builder.Append("[NumThreads(");
builder.Append(info.NumThreadsX.ToString());
builder.Append(threadsX.ToString());
builder.Append(", ");
builder.Append(info.NumThreadsY.ToString());
builder.Append(threadsY.ToString());
builder.Append(", ");
builder.Append(info.NumThreadsZ.ToString());
builder.Append(threadsZ.ToString());
builder.AppendLine(")]");
builder.AppendLine(info.EntryPoint);
+1 -13
ファイルの表示
@@ -168,19 +168,7 @@ namespace ComputeSharp.Shaders
ShaderLoader<T> shaderLoader = ShaderLoader<T>.Load(in shader);
// Render the loaded shader
using var shaderSource = HlslShaderRenderer.Render(new ShaderInfo
{
BuffersList = shaderLoader.HslsBuffersInfo,
FieldsList = shaderLoader.FieldsInfo,
NumThreadsX = threadsX,
NumThreadsY = threadsY,
NumThreadsZ = threadsZ,
ThreadsIdsVariableName = shaderLoader.ThreadsIdsVariableName,
EntryPoint = shaderLoader.EntryPoint,
FunctionsList = shaderLoader.FunctionsInfo,
LocalFunctionsList = shaderLoader.LocalFunctionsInfo,
DeclaredTypes = shaderLoader.DeclaredTypes
});
using var shaderSource = HlslShaderRenderer.Render(threadsX, threadsY, threadsZ, shaderLoader);
// Compile the loaded shader to HLSL bytecode
IDxcBlobObject shaderBytecode = new(ShaderCompiler.CompileShader(shaderSource.WrittenSpan));
+36
ファイルの表示
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using ComputeSharp.Shaders.Renderer.Models;
namespace ComputeSharp.Shaders.Translation
{
/// <summary>
/// A <see langword="class"/> responsible for loading and processing shaders of any type.
/// </summary>
internal interface IShaderLoader
{
/// <summary>
/// Gets the generated source code for the method in the current shader.
/// </summary>
public string EntryPoint { get; }
/// <summary>
/// Gets the collection of <see cref="HlslBufferInfo"/> items for the shader fields.
/// </summary>
public IReadOnlyList<HlslBufferInfo> HslsBuffersInfo { get; }
/// <summary>
/// Gets the collection of <see cref="CapturedFieldInfo"/> items for the shader fields.
/// </summary>
public IReadOnlyList<CapturedFieldInfo> FieldsInfo { get; }
/// <summary>
/// Gets the collection of <see cref="LocalFunctionInfo"/> items for the shader.
/// </summary>
public IReadOnlyCollection<string> LocalFunctionsInfo { get; }
/// <summary>
/// Gets the collection of declared types for the shader.
/// </summary>
public IReadOnlyCollection<string> DeclaredTypes { get; }
}
}
+6 -32
ファイルの表示
@@ -6,7 +6,6 @@ using System.Reflection;
using System.Runtime.InteropServices;
using ComputeSharp.Shaders.Mappings;
using ComputeSharp.Shaders.Renderer.Models;
using ComputeSharp.Shaders.Translation.Models;
using Microsoft.Toolkit.Diagnostics;
using TerraFX.Interop;
using static TerraFX.Interop.D3D12_DESCRIPTOR_RANGE_TYPE;
@@ -19,7 +18,7 @@ namespace ComputeSharp.Shaders.Translation
/// A <see langword="class"/> responsible for loading and processing shaders of a given type.
/// </summary>
/// <typeparam name="T">The type of compute shader currently in use.</typeparam>
internal sealed partial class ShaderLoader<T>
internal sealed partial class ShaderLoader<T> : IShaderLoader
where T : struct, IComputeShader
{
/// <summary>
@@ -57,11 +56,6 @@ namespace ComputeSharp.Shaders.Translation
/// </summary>
private readonly List<CapturedFieldInfo> fieldsInfo = new();
/// <summary>
/// The <see cref="List{T}"/> with the <see cref="FunctionInfo"/> items for the shader functions.
/// </summary>
private readonly List<object> functionsInfo = new();
/// <summary>
/// The <see cref="List{T}"/> with the <see cref="FunctionInfo"/> items for the shader local functions.
/// </summary>
@@ -82,39 +76,19 @@ namespace ComputeSharp.Shaders.Translation
get => CollectionsMarshal.AsSpan(this.d3D12DescriptorRanges1);
}
/// <summary>
/// Gets the name of the <see cref="ThreadIds"/> variable used as input for the shader method.
/// </summary>
public string ThreadsIdsVariableName { get; private set; }
/// <summary>
/// Gets the generated source code for the method in the current shader.
/// </summary>
/// <inheritdoc/>
public string EntryPoint { get; private set; }
/// <summary>
/// Gets the collection of <see cref="HlslBufferInfo"/> items for the shader fields.
/// </summary>
/// <inheritdoc/>
public IReadOnlyList<HlslBufferInfo> HslsBuffersInfo => this.hlslBuffersInfo;
/// <summary>
/// Gets the collection of <see cref="CapturedFieldInfo"/> items for the shader fields.
/// </summary>
/// <inheritdoc/>
public IReadOnlyList<CapturedFieldInfo> FieldsInfo => this.fieldsInfo;
/// <summary>
/// Gets the collection of <see cref="FunctionInfo"/> items for the shader.
/// </summary>
public IReadOnlyList<object> FunctionsInfo => this.functionsInfo;
/// <summary>
/// Gets the collection of <see cref="LocalFunctionInfo"/> items for the shader.
/// </summary>
/// <inheritdoc/>
public IReadOnlyCollection<string> LocalFunctionsInfo => this.localFunctionsInfo;
/// <summary>
/// Gets the collection of declared types for the shader.
/// </summary>
/// <inheritdoc/>
public IReadOnlyCollection<string> DeclaredTypes { get; private set; }
/// <summary>