Separated captured buffers and variables

このコミットが含まれているのは:
Sergio Pedri committed 2019-08-17 10:29:50 +02:00
1 親 0cc9acb923
コミット 1cf603e2af
3ファイル変更
+25 -20

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

+8 -3
ファイルの表示
@@ -12,14 +12,19 @@ namespace ComputeSharp.Shaders.Renderer.Models
internal sealed class ShaderInfo
{
/// <summary>
/// Gets the list of fields being present in the current shader
/// Gets the list of captured buffers being present in the current shader
/// </summary>
public IReadOnlyList<HlslBufferInfo> BuffersList { get; set; }
/// <summary>
/// Gets the list of captured variables being present in the current shader
/// </summary>
public IReadOnlyList<CapturedFieldInfo> FieldsList { get; set; }
/// <summary>
/// Gets or sets the index for the constant buffer with the info on the target number of iterations on the X, Y and Z axes
/// Gets or sets the index for the constant buffer with the captured scalar and vector variables
/// </summary>
public int ThreadsXYZConstantBufferIndex { get; set; }
public int VariablesConstantBufferIndex { get; set; }
/// <summary>
/// Gets or sets the number of threads in the X group
+3 -3
ファイルの表示
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Buffers;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Buffers.Extensions;
using ComputeSharp.Shaders.Renderer;
@@ -66,8 +65,9 @@ namespace ComputeSharp.Shaders
// Render the loaded shader
ShaderInfo shaderInfo = new ShaderInfo
{
FieldsList = shaderLoader.FieldsInfo,
ThreadsXYZConstantBufferIndex = shaderLoader.ConstantBuffersCount,
BuffersList = shaderLoader.BuffersList,
FieldsList = shaderLoader.FieldsList,
VariablesConstantBufferIndex = shaderLoader.ConstantBuffersCount,
NumThreadsX = threadsX,
NumThreadsY = threadsY,
NumThreadsZ = threadsZ,
+14 -14
ファイルの表示
@@ -6,6 +6,7 @@ using System.Text.RegularExpressions;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Shaders.Mappings;
using ComputeSharp.Shaders.Renderer.Models.Fields;
using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using SharpDX.Direct3D12;
@@ -70,12 +71,19 @@ namespace ComputeSharp.Shaders.Translation
/// </summary>
public IReadOnlyList<(int Index, object Value)> CapturedConstantBufferValues => _CapturedConstantBufferValues;
private readonly List<CapturedFieldInfo> _FieldsInfo = new List<CapturedFieldInfo>();
private readonly List<HlslBufferInfo> _BuffersList = new List<HlslBufferInfo>();
/// <summary>
/// Gets the collection of <see cref="HlslBufferInfo"/> items for the shader fields
/// </summary>
public IReadOnlyList<HlslBufferInfo> BuffersList => _BuffersList;
private readonly List<CapturedFieldInfo> _FieldsList = new List<CapturedFieldInfo>();
/// <summary>
/// Gets the collection of <see cref="CapturedFieldInfo"/> items for the shader fields
/// </summary>
public IReadOnlyList<CapturedFieldInfo> FieldsInfo => _FieldsInfo;
public IReadOnlyList<CapturedFieldInfo> FieldsList => _FieldsList;
/// <summary>
/// gets the number of constant buffers in the current instance
@@ -113,8 +121,6 @@ namespace ComputeSharp.Shaders.Translation
/// </summary>
private void LoadFieldsInfo()
{
if (FieldsInfo.Count > 0) throw new InvalidOperationException("Shader fields already loaded");
if (ShaderFields.Any(fieldInfo => fieldInfo.IsStatic)) throw new InvalidOperationException("Empty shader body");
List<DescriptorRange> descriptorRanges = new List<DescriptorRange>();
@@ -126,7 +132,6 @@ namespace ComputeSharp.Shaders.Translation
Type fieldType = fieldInfo.FieldType;
string fieldName = fieldInfo.Name;
object fieldValue = fieldInfo.GetValue(ShaderInstance);
CapturedFieldInfo processedFieldInfo;
// Constant buffer
if (HlslKnownTypes.IsConstantBufferType(fieldType))
@@ -137,7 +142,7 @@ namespace ComputeSharp.Shaders.Translation
_Buffers.Add((descriptorRanges.Count - 1, (GraphicsResource)fieldValue));
string typeName = HlslKnownTypes.GetMappedName(fieldType.GenericTypeArguments[0]);
processedFieldInfo = new ConstantBufferFieldInfo(typeName, fieldName, ConstantBuffersCount++, false);
_BuffersList.Add(new ConstantBufferFieldInfo(typeName, fieldName, ConstantBuffersCount++, false));
}
else if (HlslKnownTypes.IsReadOnlyBufferType(fieldType))
{
@@ -148,7 +153,7 @@ namespace ComputeSharp.Shaders.Translation
_Buffers.Add((descriptorRanges.Count - 1, (GraphicsResource)fieldValue));
string typeName = HlslKnownTypes.GetMappedName(fieldType);
processedFieldInfo = new ReadOnlyBufferFieldInfo(typeName, fieldName, readOnlyBuffersCount++);
_BuffersList.Add(new ReadOnlyBufferFieldInfo(typeName, fieldName, readOnlyBuffersCount++));
}
else if (HlslKnownTypes.IsReadWriteBufferType(fieldType))
{
@@ -159,7 +164,7 @@ namespace ComputeSharp.Shaders.Translation
_Buffers.Add((descriptorRanges.Count - 1, (GraphicsResource)fieldValue));
string typeName = HlslKnownTypes.GetMappedName(fieldType);
processedFieldInfo = new ReadWriteBufferFieldInfo(typeName, fieldName, readWriteBuffersCount++);
_BuffersList.Add(new ReadWriteBufferFieldInfo(typeName, fieldName, readWriteBuffersCount++));
}
else if (HlslKnownTypes.IsKnownScalarType(fieldType) || HlslKnownTypes.IsKnownVectorType(fieldType))
{
@@ -171,16 +176,11 @@ namespace ComputeSharp.Shaders.Translation
// Constant buffer field
string typeName = HlslKnownTypes.GetMappedName(fieldType);
processedFieldInfo = new ConstantBufferFieldInfo(typeName, fieldName, ConstantBuffersCount++, true);
_FieldsList.Add(new CapturedFieldInfo(typeName, fieldName));
}
else throw new NotSupportedException($"Unsupported field of type {fieldType.FullName}");
_FieldsInfo.Add(processedFieldInfo);
}
// Descriptor for the X, Y and Z target variables
descriptorRanges.Add(new DescriptorRange(DescriptorRangeType.ConstantBufferView, 1, ConstantBuffersCount));
RootParameters = descriptorRanges.Select(range => new RootParameter(ShaderVisibility.All, range)).ToArray();
}