From 59df32464d19c873245e261e44022771202a35ea Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 18 Aug 2019 12:50:25 +0200 Subject: [PATCH] Refactored ShaderLoader class to use new ReadableMember type --- .../Translation/ShaderLoader.cs | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs index 65ff18c2..b6ba034a 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs @@ -8,6 +8,7 @@ using ComputeSharp.Graphics.Buffers.Abstract; using ComputeSharp.Shaders.Mappings; using ComputeSharp.Shaders.Renderer.Models.Fields; using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract; +using ComputeSharp.Shaders.Translation.Models; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using SharpDX.Direct3D12; @@ -69,26 +70,26 @@ namespace ComputeSharp.Shaders.Translation public RootParameter[] RootParameters => _RootParameters ??= DescriptorRanges.Select(range => new RootParameter(ShaderVisibility.All, range)).ToArray(); /// - /// The of instances mapping the captured buffers in the current shader + /// The of instances mapping the captured buffers in the current shader /// - private readonly List _BufferFields = new List(); + private readonly List _BufferMembers = new List(); /// /// Gets the ordered collection of buffers used as fields in the current shader /// /// The to use to build the shader - public IEnumerable<(int Index, GraphicsResource Resource)> GetBuffers(Action action) => _BufferFields.Select((field, i) => (i + 1, (GraphicsResource)field.GetValue(action.Target))); + public IEnumerable<(int Index, GraphicsResource Resource)> GetBuffers(Action action) => _BufferMembers.Select((field, i) => (i + 1, (GraphicsResource)field.GetValue(action.Target))); /// - /// The of instances mapping the captured scalar/vector variables in the current shader + /// The of instances mapping the captured scalar/vector variables in the current shader /// - private readonly List _VariableFields = new List(); + private readonly List _VariableMembers = new List(); /// /// Gets the collection of values of the captured fields for the current shader /// /// The to use to build the shader - public IEnumerable GetVariables(Action action) => _VariableFields.Select(field => field.GetValue(action.Target)); + public IEnumerable GetVariables(Action action) => _VariableMembers.Select(field => field.GetValue(action.Target)); private readonly List _BuffersList = new List(); @@ -149,14 +150,14 @@ namespace ComputeSharp.Shaders.Translation } /// - /// Loads a specified and adds it to the shader model + /// Loads a specified and adds it to the shader model /// - /// The target to load + /// The target to load /// The optional explicit name to use for the field - private void LoadFieldInfo(FieldInfo fieldInfo, string? name = null) + private void LoadFieldInfo(ReadableMember memberInfo, string? name = null) { - Type fieldType = fieldInfo.FieldType; - string fieldName = name ?? fieldInfo.Name; + Type fieldType = memberInfo.MemberType; + string fieldName = name ?? memberInfo.Name; // Constant buffer if (HlslKnownTypes.IsConstantBufferType(fieldType)) @@ -164,7 +165,7 @@ namespace ComputeSharp.Shaders.Translation DescriptorRanges.Add(new DescriptorRange(DescriptorRangeType.ConstantBufferView, 1, _ConstantBuffersCount)); // Track the buffer field - _BufferFields.Add(fieldInfo); + _BufferMembers.Add(memberInfo); string typeName = HlslKnownTypes.GetMappedName(fieldType.GenericTypeArguments[0]); _BuffersList.Add(new ConstantBufferFieldInfo(fieldType, typeName, fieldName, _ConstantBuffersCount++)); @@ -175,7 +176,7 @@ namespace ComputeSharp.Shaders.Translation DescriptorRanges.Add(new DescriptorRange(DescriptorRangeType.ShaderResourceView, 1, _ReadOnlyBuffersCount)); // Track the buffer field - _BufferFields.Add(fieldInfo); + _BufferMembers.Add(memberInfo); string typeName = HlslKnownTypes.GetMappedName(fieldType); _BuffersList.Add(new ReadOnlyBufferFieldInfo(fieldType, typeName, fieldName, _ReadOnlyBuffersCount++)); @@ -186,7 +187,7 @@ namespace ComputeSharp.Shaders.Translation DescriptorRanges.Add(new DescriptorRange(DescriptorRangeType.UnorderedAccessView, 1, _ReadWriteBuffersCount)); // Track the buffer field - _BufferFields.Add(fieldInfo); + _BufferMembers.Add(memberInfo); string typeName = HlslKnownTypes.GetMappedName(fieldType); _BuffersList.Add(new ReadWriteBufferFieldInfo(fieldType, typeName, fieldName, _ReadWriteBuffersCount++)); @@ -194,7 +195,7 @@ namespace ComputeSharp.Shaders.Translation else if (HlslKnownTypes.IsKnownScalarType(fieldType) || HlslKnownTypes.IsKnownVectorType(fieldType)) { // Register the captured field - _VariableFields.Add(fieldInfo); + _VariableMembers.Add(memberInfo); string typeName = HlslKnownTypes.GetMappedName(fieldType); _FieldsList.Add(new CapturedFieldInfo(fieldType, typeName, fieldName)); }