Code refactoring, moved aggregated buffer to top
このコミットが含まれているのは:
1 親
f15112b85f
コミット
e56bce0384
4ファイル変更
+32
-36
検索条件に一致するファイルはありません
@@ -21,11 +21,6 @@ namespace ComputeSharp.Shaders.Renderer.Models
|
||||
/// </summary>
|
||||
public IReadOnlyList<CapturedFieldInfo> FieldsList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the index for the constant buffer with the captured scalar and vector variables
|
||||
/// </summary>
|
||||
public int VariablesConstantBufferIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of threads in the X group
|
||||
/// </summary>
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
{{#BuffersList}}
|
||||
{{!Constant buffer}}
|
||||
{{#IsConstantBuffer}}
|
||||
cbuffer {{FieldName}}Buffer : register(b{{BufferIndex}})
|
||||
{
|
||||
{{&FieldType}} {{FieldName}}[2];
|
||||
}
|
||||
{{/IsConstantBuffer}}
|
||||
{{!Readonly buffer}}
|
||||
{{#IsReadOnlyBuffer}}
|
||||
{{&FieldType}} {{FieldName}} : register(t{{BufferIndex}});
|
||||
{{/IsReadOnlyBuffer}}
|
||||
{{!Read write buffer}}
|
||||
{{#IsReadWriteBuffer}}
|
||||
{{&FieldType}} {{FieldName}} : SV_DispatchThreadId : register(u{{BufferIndex}});
|
||||
{{/IsReadWriteBuffer}}
|
||||
|
||||
{{/BuffersList}}
|
||||
{{!Captured variables buffer}}
|
||||
cbuffer __Variables__Buffer : register(b{{VariablesConstantBufferIndex}})
|
||||
{{!Captured variables buffer}}
|
||||
cbuffer __Variables__Buffer : register(b0)
|
||||
{
|
||||
uint __x__;
|
||||
uint __y__;
|
||||
@@ -26,6 +8,26 @@ cbuffer __Variables__Buffer : register(b{{VariablesConstantBufferIndex}})
|
||||
{{&FieldType}} {{FieldName}};
|
||||
{{/FieldsList}}
|
||||
}
|
||||
{{#BuffersList}}
|
||||
{{#IsConstantBuffer}}
|
||||
|
||||
{{!Constant buffer}}
|
||||
cbuffer {{FieldName}}Buffer : register(b{{BufferIndex}})
|
||||
{
|
||||
{{&FieldType}} {{FieldName}}[2];
|
||||
}
|
||||
{{/IsConstantBuffer}}
|
||||
{{#IsReadOnlyBuffer}}
|
||||
|
||||
{{!Readonly buffer}}
|
||||
{{&FieldType}} {{FieldName}} : register(t{{BufferIndex}});
|
||||
{{/IsReadOnlyBuffer}}
|
||||
{{#IsReadWriteBuffer}}
|
||||
|
||||
{{!Read write buffer}}
|
||||
{{&FieldType}} {{FieldName}} : SV_DispatchThreadId : register(u{{BufferIndex}});
|
||||
{{/IsReadWriteBuffer}}
|
||||
{{/BuffersList}}
|
||||
|
||||
{{!Shader entry point}}
|
||||
[Shader("compute")]
|
||||
|
||||
@@ -68,7 +68,6 @@ namespace ComputeSharp.Shaders
|
||||
{
|
||||
BuffersList = shaderLoader.BuffersList,
|
||||
FieldsList = shaderLoader.FieldsList,
|
||||
VariablesConstantBufferIndex = shaderLoader.ConstantBuffersCount,
|
||||
NumThreadsX = threadsX,
|
||||
NumThreadsY = threadsY,
|
||||
NumThreadsZ = threadsZ,
|
||||
@@ -98,7 +97,7 @@ namespace ComputeSharp.Shaders
|
||||
// Initialize the loop targets
|
||||
IReadOnlyList<object> variables = new object[] { (uint)x, (uint)y, (uint)z }.Concat(shaderLoader.FieldValuesList).ToArray();
|
||||
using GraphicsResource variablesBuffer = device.AllocateConstantBufferFromReflectedValues(variables);
|
||||
commandList.SetComputeRootDescriptorTable(shaderLoader.RootParameters.Length - 1, variablesBuffer);
|
||||
commandList.SetComputeRootDescriptorTable(0, variablesBuffer);
|
||||
|
||||
// Dispatch and wait for completion
|
||||
commandList.Dispatch(groupsX, groupsY, groupsZ);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Shaders.Mappings;
|
||||
@@ -85,11 +86,6 @@ namespace ComputeSharp.Shaders.Translation
|
||||
/// </summary>
|
||||
public IReadOnlyList<object> FieldValuesList => _FieldValuesList;
|
||||
|
||||
/// <summary>
|
||||
/// gets the number of constant buffers in the current instance
|
||||
/// </summary>
|
||||
public int ConstantBuffersCount { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the <see cref="ThreadIds"/> variable used as input for the shader method
|
||||
/// </summary>
|
||||
@@ -124,10 +120,15 @@ namespace ComputeSharp.Shaders.Translation
|
||||
if (ShaderFields.Any(fieldInfo => fieldInfo.IsStatic)) throw new InvalidOperationException("Empty shader body");
|
||||
|
||||
List<DescriptorRange> descriptorRanges = new List<DescriptorRange>();
|
||||
int constantBuffersCount = 0;
|
||||
int readOnlyBuffersCount = 0;
|
||||
int readWriteBuffersCount = 0;
|
||||
|
||||
foreach (System.Reflection.FieldInfo fieldInfo in ShaderFields)
|
||||
// Descriptor for the buffer for captured scalar/vector variables
|
||||
descriptorRanges.Add(new DescriptorRange(DescriptorRangeType.ConstantBufferView, 1, constantBuffersCount++));
|
||||
|
||||
// Inspect the captured fields
|
||||
foreach (FieldInfo fieldInfo in ShaderFields)
|
||||
{
|
||||
Type fieldType = fieldInfo.FieldType;
|
||||
string fieldName = fieldInfo.Name;
|
||||
@@ -136,13 +137,13 @@ namespace ComputeSharp.Shaders.Translation
|
||||
// Constant buffer
|
||||
if (HlslKnownTypes.IsConstantBufferType(fieldType))
|
||||
{
|
||||
descriptorRanges.Add(new DescriptorRange(DescriptorRangeType.ConstantBufferView, 1, ConstantBuffersCount));
|
||||
descriptorRanges.Add(new DescriptorRange(DescriptorRangeType.ConstantBufferView, 1, constantBuffersCount));
|
||||
|
||||
// Reference to the underlying buffer
|
||||
_Buffers.Add((descriptorRanges.Count - 1, (GraphicsResource)fieldValue));
|
||||
|
||||
string typeName = HlslKnownTypes.GetMappedName(fieldType.GenericTypeArguments[0]);
|
||||
_BuffersList.Add(new ConstantBufferFieldInfo(typeName, fieldName, ConstantBuffersCount++));
|
||||
_BuffersList.Add(new ConstantBufferFieldInfo(typeName, fieldName, constantBuffersCount++));
|
||||
}
|
||||
else if (HlslKnownTypes.IsReadOnlyBufferType(fieldType))
|
||||
{
|
||||
@@ -175,7 +176,6 @@ namespace ComputeSharp.Shaders.Translation
|
||||
}
|
||||
else throw new NotSupportedException($"Unsupported field of type {fieldType.FullName}");
|
||||
}
|
||||
|
||||
RootParameters = descriptorRanges.Select(range => new RootParameter(ShaderVisibility.All, range)).ToArray();
|
||||
}
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする