Implemented support for local shader constants

このコミットが含まれているのは:
Sergio Pedri committed 2021-01-10 22:33:13 +01:00
1 親 3daafd3e16
コミット 27438f7a69
7ファイル変更
+123 -24

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

+5
ファイルの表示
@@ -28,6 +28,11 @@ namespace ComputeSharp.Shaders.Translation
/// </summary>
public IReadOnlyCollection<string> MethodsInfo { get; }
/// <summary>
/// Gets the collection of constants to be declared in the shader.
/// </summary>
public IReadOnlyDictionary<string, string> ConstantsInfo { get; }
/// <summary>
/// Gets the collection of declared types for the shader.
/// </summary>
+27 -12
ファイルの表示
@@ -61,6 +61,11 @@ namespace ComputeSharp.Shaders.Translation
/// </summary>
private readonly List<string> methodsInfo = new();
/// <summary>
/// The <see cref="Dictionary{TKey,TValue}"/> with the discovered constants for the shader.
/// </summary>
private readonly Dictionary<string, string> constantsInfo = new();
/// <summary>
/// The <see cref="List{T}"/> with the collected declared types for the shader.
/// </summary>
@@ -93,6 +98,9 @@ namespace ComputeSharp.Shaders.Translation
/// <inheritdoc/>
public IReadOnlyCollection<string> MethodsInfo => this.methodsInfo;
/// <inheritdoc/>
public IReadOnlyDictionary<string, string> ConstantsInfo => this.constantsInfo;
/// <inheritdoc/>
public IReadOnlyCollection<string> DeclaredTypes => this.declaredTypes;
@@ -106,16 +114,34 @@ namespace ComputeSharp.Shaders.Translation
{
ShaderLoader<T> @this = new();
@this.LoadMethodMetadata();
// Reading members through reflection requires an object parameter, so here we're just boxing
// the input shader once to avoid allocating it multiple times while processing the shader.
@this.d3D12DescriptorRanges1 = @this.LoadFieldsInfo(shader);
@this.LoadMethodMetadata();
@this.InitializeDispatchDataLoader();
return @this;
}
/// <summary>
/// Loads the metadata info for the current shader.
/// </summary>
private void LoadMethodMetadata()
{
EntryPoint = Attribute.ExecuteMethod;
this.methodsInfo.AddRange(Attribute.Methods);
foreach (var pair in Attribute.Constants)
{
this.constantsInfo.Add(pair.Key, pair.Value);
}
this.declaredTypes.AddRange(Attribute.Types);
}
/// <summary>
/// Loads the fields info for the current shader being loaded.
/// </summary>
@@ -200,16 +226,5 @@ namespace ComputeSharp.Shaders.Translation
}
else ThrowHelper.ThrowArgumentException("Invalid captured variable");
}
/// <summary>
/// Loads the metadata info for the current shader.
/// </summary>
private void LoadMethodMetadata()
{
EntryPoint = Attribute.ExecuteMethod;
this.methodsInfo.AddRange(Attribute.Methods);
this.declaredTypes.AddRange(Attribute.Types);
}
}
}