diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs
index c1b683f8..cf5d819c 100644
--- a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs
+++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs
@@ -144,53 +144,63 @@ namespace ComputeSharp.Shaders.Translation
// Inspect the captured fields
foreach (FieldInfo fieldInfo in shaderFields)
{
- Type fieldType = fieldInfo.FieldType;
- string fieldName = fieldInfo.Name;
-
- // Constant buffer
- if (HlslKnownTypes.IsConstantBufferType(fieldType))
- {
- DescriptorRanges.Add(new DescriptorRange(DescriptorRangeType.ConstantBufferView, 1, _ConstantBuffersCount));
-
- // Track the buffer field
- _BufferFields.Add(fieldInfo);
-
- string typeName = HlslKnownTypes.GetMappedName(fieldType.GenericTypeArguments[0]);
- _BuffersList.Add(new ConstantBufferFieldInfo(fieldType, typeName, fieldName, _ConstantBuffersCount++));
- }
- else if (HlslKnownTypes.IsReadOnlyBufferType(fieldType))
- {
- // Root parameter for a readonly buffer
- DescriptorRanges.Add(new DescriptorRange(DescriptorRangeType.ShaderResourceView, 1, _ReadOnlyBuffersCount));
-
- // Track the buffer field
- _BufferFields.Add(fieldInfo);
-
- string typeName = HlslKnownTypes.GetMappedName(fieldType);
- _BuffersList.Add(new ReadOnlyBufferFieldInfo(fieldType, typeName, fieldName, _ReadOnlyBuffersCount++));
- }
- else if (HlslKnownTypes.IsReadWriteBufferType(fieldType))
- {
- // Root parameter for a read write buffer
- DescriptorRanges.Add(new DescriptorRange(DescriptorRangeType.UnorderedAccessView, 1, _ReadWriteBuffersCount));
-
- // Track the buffer field
- _BufferFields.Add(fieldInfo);
-
- string typeName = HlslKnownTypes.GetMappedName(fieldType);
- _BuffersList.Add(new ReadWriteBufferFieldInfo(fieldType, typeName, fieldName, _ReadWriteBuffersCount++));
- }
- else if (HlslKnownTypes.IsKnownScalarType(fieldType) || HlslKnownTypes.IsKnownVectorType(fieldType))
- {
- // Register the captured field
- _VariableFields.Add(fieldInfo);
- string typeName = HlslKnownTypes.GetMappedName(fieldType);
- _FieldsList.Add(new CapturedFieldInfo(fieldType, typeName, fieldName));
- }
- else throw new NotSupportedException($"Unsupported field of type {fieldType.FullName}");
+ LoadFieldInfo(fieldInfo);
}
}
+ ///
+ /// Loads a specified and adds it to the shader model
+ ///
+ /// The target to load
+ /// The optional explicit name to use for the field
+ private void LoadFieldInfo(FieldInfo fieldInfo, string? name = null)
+ {
+ Type fieldType = fieldInfo.FieldType;
+ string fieldName = name ?? fieldInfo.Name;
+
+ // Constant buffer
+ if (HlslKnownTypes.IsConstantBufferType(fieldType))
+ {
+ DescriptorRanges.Add(new DescriptorRange(DescriptorRangeType.ConstantBufferView, 1, _ConstantBuffersCount));
+
+ // Track the buffer field
+ _BufferFields.Add(fieldInfo);
+
+ string typeName = HlslKnownTypes.GetMappedName(fieldType.GenericTypeArguments[0]);
+ _BuffersList.Add(new ConstantBufferFieldInfo(fieldType, typeName, fieldName, _ConstantBuffersCount++));
+ }
+ else if (HlslKnownTypes.IsReadOnlyBufferType(fieldType))
+ {
+ // Root parameter for a readonly buffer
+ DescriptorRanges.Add(new DescriptorRange(DescriptorRangeType.ShaderResourceView, 1, _ReadOnlyBuffersCount));
+
+ // Track the buffer field
+ _BufferFields.Add(fieldInfo);
+
+ string typeName = HlslKnownTypes.GetMappedName(fieldType);
+ _BuffersList.Add(new ReadOnlyBufferFieldInfo(fieldType, typeName, fieldName, _ReadOnlyBuffersCount++));
+ }
+ else if (HlslKnownTypes.IsReadWriteBufferType(fieldType))
+ {
+ // Root parameter for a read write buffer
+ DescriptorRanges.Add(new DescriptorRange(DescriptorRangeType.UnorderedAccessView, 1, _ReadWriteBuffersCount));
+
+ // Track the buffer field
+ _BufferFields.Add(fieldInfo);
+
+ string typeName = HlslKnownTypes.GetMappedName(fieldType);
+ _BuffersList.Add(new ReadWriteBufferFieldInfo(fieldType, typeName, fieldName, _ReadWriteBuffersCount++));
+ }
+ else if (HlslKnownTypes.IsKnownScalarType(fieldType) || HlslKnownTypes.IsKnownVectorType(fieldType))
+ {
+ // Register the captured field
+ _VariableFields.Add(fieldInfo);
+ string typeName = HlslKnownTypes.GetMappedName(fieldType);
+ _FieldsList.Add(new CapturedFieldInfo(fieldType, typeName, fieldName));
+ }
+ else throw new NotSupportedException($"Unsupported field of type {fieldType.FullName}");
+ }
+
///
/// Loads the entry method for the current shader being loaded
///