Merged captured variables into single buffer

このコミットが含まれているのは:
Sergio Pedri committed 2019-08-17 10:42:16 +02:00
1 親 c74e0a0a07
コミット a436486dec
3ファイル変更
+19 -35

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

+6 -3
ファイルの表示
@@ -1,4 +1,4 @@
{{#FieldsList}}
{{#BuffersList}}
{{!Constant buffer}}
{{#IsConstantBuffer}}
cbuffer {{FieldName}}Buffer : register(b{{BufferIndex}})
@@ -15,13 +15,16 @@ cbuffer {{FieldName}}Buffer : register(b{{BufferIndex}})
{{&FieldType}} {{FieldName}} : SV_DispatchThreadId : register(u{{BufferIndex}});
{{/IsReadWriteBuffer}}
{{/FieldsList}}
{{/BuffersList}}
{{!Captured variables buffer}}
cbuffer __Variables__Buffer : register(b{{ThreadsXYZConstantBufferIndex}})
cbuffer __Variables__Buffer : register(b{{VariablesConstantBufferIndex}})
{
uint __x__;
uint __y__;
uint __z__;
{{#FieldsList}}
{{&FieldType}} {{FieldName}};
{{/FieldsList}}
}
{{!Shader entry point}}
+4 -18
ファイルの表示
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Buffers.Extensions;
@@ -94,29 +95,14 @@ namespace ComputeSharp.Shaders
commandList.SetComputeRootDescriptorTable(buffer.Index, buffer.Resource);
}
// Load the captured variables
List<GraphicsResource> buffers = new List<GraphicsResource>();
foreach (var variable in shaderLoader.CapturedConstantBufferValues)
{
GraphicsResource resource = device.AllocateConstantBufferFromReflectedSingleValue(variable.Value);
commandList.SetComputeRootDescriptorTable(variable.Index, resource);
buffers.Add(resource);
}
// Initialize the loop targets
var xyzBuffer = device.AllocateConstantBufferFromReflectedValues(new object[] { (uint)x, (uint)y, (uint)z });
commandList.SetComputeRootDescriptorTable(shaderLoader.RootParameters.Length - 1, xyzBuffer);
buffers.Add(xyzBuffer);
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);
// Dispatch and wait for completion
commandList.Dispatch(groupsX, groupsY, groupsZ);
commandList.Flush();
// Free the allocated resources
foreach (GraphicsResource resource in buffers)
{
resource.Dispose();
}
}
}
}
+9 -14
ファイルの表示
@@ -64,13 +64,6 @@ namespace ComputeSharp.Shaders.Translation
/// </summary>
public IReadOnlyList<(int Index, GraphicsResource Resource)> Buffers => _Buffers;
private readonly List<(int, object)> _CapturedConstantBufferValues = new List<(int, object)>();
/// <summary>
/// Gets the ordered collection of captured variables that need to be assigned to constant buffers
/// </summary>
public IReadOnlyList<(int Index, object Value)> CapturedConstantBufferValues => _CapturedConstantBufferValues;
private readonly List<HlslBufferInfo> _BuffersList = new List<HlslBufferInfo>();
/// <summary>
@@ -85,6 +78,13 @@ namespace ComputeSharp.Shaders.Translation
/// </summary>
public IReadOnlyList<CapturedFieldInfo> FieldsList => _FieldsList;
private readonly List<object> _FieldValuesList = new List<object>();
/// <summary>
/// Gets the collection of values of the captured fields for the current shader
/// </summary>
public IReadOnlyList<object> FieldValuesList => _FieldValuesList;
/// <summary>
/// gets the number of constant buffers in the current instance
/// </summary>
@@ -168,13 +168,8 @@ namespace ComputeSharp.Shaders.Translation
}
else if (HlslKnownTypes.IsKnownScalarType(fieldType) || HlslKnownTypes.IsKnownVectorType(fieldType))
{
// Constant buffer
descriptorRanges.Add(new DescriptorRange(DescriptorRangeType.ConstantBufferView, 1, ConstantBuffersCount));
// Register the captured value
_CapturedConstantBufferValues.Add((descriptorRanges.Count - 1, fieldValue));
// Constant buffer field
// Register the captured field
_FieldValuesList.Add(fieldValue);
string typeName = HlslKnownTypes.GetMappedName(fieldType);
_FieldsList.Add(new CapturedFieldInfo(typeName, fieldName));
}