Merge pull request #14 from Sergio0694/feature_readonly-buffers-support

Readonly buffers support
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2019-08-13 22:00:45 +02:00
コミット 170ad9d353
13ファイル変更
+382 -146

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

+9
ファイルの表示
@@ -62,6 +62,15 @@ namespace ComputeSharp.Shaders.Mappings
public static bool IsReadWriteBufferType(Type type) => type.IsGenericType &&
type.GetGenericTypeDefinition() == typeof(ReadWriteBuffer<>);
/// <summary>
/// Checks whether or not the input type is a <see cref="ReadOnlyBuffer{T}"/> value
/// </summary>
/// <param name="type">The input <see cref="Type"/> instance to check</param>
/// <returns>A <see langword="bool"/> indicating whether the input <see cref="Type"/> is in fact a <see cref="ReadOnlyBuffer{T}"/> instance</returns>
[Pure]
public static bool IsReadOnlyBufferType(Type type) => type.IsGenericType &&
type.GetGenericTypeDefinition() == typeof(ReadOnlyBuffer<>);
/// <summary>
/// Checks whether or not a given <see cref="Type"/> is an HLSL known type
/// </summary>
+9 -2
ファイルの表示
@@ -12,10 +12,15 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields
/// </summary>
public bool IsConstantBuffer { get; } = true;
/// <summary>
/// Gets whether or not this constant buffer actually contains a single, explicit variable
/// </summary>
public bool IsSingleValue { get; }
/// <summary>
/// Gets the index of the current constant buffer field
/// </summary>
public int ConstantBufferIndex { get; set; }
public int ConstantBufferIndex { get; }
/// <summary>
/// Creates a new <see cref="ConstantBufferFieldInfo"/> instance with the specified parameters
@@ -23,9 +28,11 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields
/// <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 constant buffer field</param>
public ConstantBufferFieldInfo(string fieldType, string fieldName, int bufferIndex) : base(fieldType, fieldName)
/// <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)
{
ConstantBufferIndex = bufferIndex;
IsSingleValue = singleValue;
}
}
}
+1 -1
ファイルの表示
@@ -7,7 +7,7 @@ static {{&FieldType}} {{FieldName}} = {{FieldValue}};
{{#IsConstantBuffer}}
cbuffer {{FieldName}}Buffer : register(b{{ConstantBufferIndex}})
{
{{&FieldType}} {{FieldName}};
{{&FieldType}} {{FieldName}}{{^IsSingleValue}}[2]{{/IsSingleValue}};
}
{{/IsConstantBuffer}}
{{!Read write buffer}}
+1 -1
ファイルの表示
@@ -65,7 +65,7 @@ namespace ComputeSharp.Shaders
commandList.SetPipelineState(pipelineState);
// Load the captured buffers
foreach (var buffer in shaderLoader.ReadWriteBuffers.Select((r, i) => (Resource: r, Index: i)))
foreach (var buffer in shaderLoader.Buffers.Select((r, i) => (Resource: r, Index: i)))
{
commandList.SetComputeRootDescriptorTable(buffer.Index, buffer.Resource);
}
+18 -5
ファイルの表示
@@ -59,9 +59,9 @@ namespace ComputeSharp.Shaders.Translation
public RootParameter[] RootParameters { get; private set; }
/// <summary>
/// Gets the ordered collection of read write buffers used as fields in the current shader
/// Gets the ordered collection of buffers used as fields in the current shader
/// </summary>
public IReadOnlyList<GraphicsResource> ReadWriteBuffers { get; private set; }
public IReadOnlyList<GraphicsResource> Buffers { get; private set; }
private readonly List<FieldInfoBase> _FieldsInfo = new List<FieldInfoBase>();
@@ -106,8 +106,9 @@ namespace ComputeSharp.Shaders.Translation
if (ShaderFields.Any(fieldInfo => fieldInfo.IsStatic)) throw new InvalidOperationException("Empty shader body");
List<DescriptorRange> descriptorRanges = new List<DescriptorRange>();
List<GraphicsResource> readWriteBuffers = new List<GraphicsResource>();
List<GraphicsResource> buffers = new List<GraphicsResource>();
int readWriteBuffersCount = 0;
int readOnlyBuffersCount = 0;
foreach (FieldInfo fieldInfo in ShaderFields)
{
@@ -124,11 +125,23 @@ namespace ComputeSharp.Shaders.Translation
descriptorRanges.Add(range);
// Reference to the underlying buffer
readWriteBuffers.Add((GraphicsResource)fieldValue);
buffers.Add((GraphicsResource)fieldValue);
string typeName = HlslKnownTypes.GetMappedName(fieldType);
processedFieldInfo = new ReadWriteBufferFieldInfo(typeName, fieldName, readWriteBuffersCount++);
}
else if (HlslKnownTypes.IsReadOnlyBufferType(fieldType))
{
// Read only buffer
DescriptorRange range = new DescriptorRange(DescriptorRangeType.ConstantBufferView, 1, readOnlyBuffersCount);
descriptorRanges.Add(range);
// Reference to the underlying buffer
buffers.Add((GraphicsResource)fieldValue);
string typeName = HlslKnownTypes.GetMappedName(fieldType.GenericTypeArguments[0]);
processedFieldInfo = new ConstantBufferFieldInfo(typeName, fieldName, readOnlyBuffersCount++, false);
}
else if (HlslKnownTypes.IsKnownScalarType(fieldType))
{
// Static scalar field
@@ -141,7 +154,7 @@ namespace ComputeSharp.Shaders.Translation
}
RootParameters = descriptorRanges.Select(range => new RootParameter(ShaderVisibility.All, range)).ToArray();
ReadWriteBuffers = readWriteBuffers;
Buffers = buffers;
}
/// <summary>