diff --git a/src/ComputeSharp.Shaders/Renderer/Models/Fields/Abstract/HlslBufferInfo.cs b/src/ComputeSharp.Shaders/Renderer/Models/Fields/Abstract/HlslBufferInfo.cs index 165d224d..70a23e65 100644 --- a/src/ComputeSharp.Shaders/Renderer/Models/Fields/Abstract/HlslBufferInfo.cs +++ b/src/ComputeSharp.Shaders/Renderer/Models/Fields/Abstract/HlslBufferInfo.cs @@ -1,6 +1,4 @@ -using System; - -namespace ComputeSharp.Shaders.Renderer.Models.Fields.Abstract +namespace ComputeSharp.Shaders.Renderer.Models.Fields.Abstract { /// /// A that contains info on a shader buffer field. @@ -10,12 +8,11 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields.Abstract /// /// Creates a new instance with the specified parameters. /// - /// The type of the current field in the C# source. - /// The type of the current field in the HLSL shader. + /// The type of the current field in the HLSL shader. /// The name of the current field. /// The index of the current buffer field. - protected HlslBufferInfo(Type fieldCsharpType, string fieldHlslType, string fieldName, int bufferIndex) - : base(fieldCsharpType, fieldHlslType, fieldName) + protected HlslBufferInfo(string fieldType, string fieldName, int bufferIndex) + : base(fieldType, fieldName) { BufferIndex = bufferIndex; } diff --git a/src/ComputeSharp.Shaders/Renderer/Models/Fields/CapturedFieldInfo.cs b/src/ComputeSharp.Shaders/Renderer/Models/Fields/CapturedFieldInfo.cs index 9548826b..10d43563 100644 --- a/src/ComputeSharp.Shaders/Renderer/Models/Fields/CapturedFieldInfo.cs +++ b/src/ComputeSharp.Shaders/Renderer/Models/Fields/CapturedFieldInfo.cs @@ -1,7 +1,4 @@ -using ComputeSharp.Graphics.Extensions; -using System; - -namespace ComputeSharp.Shaders.Renderer.Models.Fields +namespace ComputeSharp.Shaders.Renderer.Models.Fields { /// /// A that contains info on a shader field. @@ -11,25 +8,18 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields /// /// Creates a new instance with the specified parameters. /// - /// The type of the current field in the C# source. - /// The type of the current field in the HLSL shader. + /// The type of the current field in the HLSL shader. /// The name to use for the current field. - public CapturedFieldInfo(Type fieldCsharpType, string fieldHlslType, string fieldName) + public CapturedFieldInfo(string fieldType, string fieldName) { - FieldCsharpType = fieldCsharpType.ToFriendlyString(); - FieldHlslType = fieldHlslType; + FieldType = fieldType; FieldName = fieldName; } - /// - /// Gets the type of the current field in the C# source. - /// - public string FieldCsharpType { get; } - /// /// Gets the type of the current field in the HLSL shader. /// - public string FieldHlslType { get; } + public string FieldType { get; } /// /// Gets the name to use for the current field. diff --git a/src/ComputeSharp.Shaders/Renderer/Models/Fields/ConstantBufferFieldInfo.cs b/src/ComputeSharp.Shaders/Renderer/Models/Fields/ConstantBufferFieldInfo.cs index bd9e87c9..87098ed1 100644 --- a/src/ComputeSharp.Shaders/Renderer/Models/Fields/ConstantBufferFieldInfo.cs +++ b/src/ComputeSharp.Shaders/Renderer/Models/Fields/ConstantBufferFieldInfo.cs @@ -1,5 +1,4 @@ -using System; -using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract; +using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract; namespace ComputeSharp.Shaders.Renderer.Models.Fields { @@ -11,12 +10,11 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields /// /// Creates a new instance with the specified parameters. /// - /// The type of the current field in the C# source. /// The type of the current field in the HLSL shader. /// The name of the current field. /// The index of the current constant buffer field. - public ConstantBufferFieldInfo(Type fieldCsharpType, string fieldHlslType, string fieldName, int bufferIndex) - : base(fieldCsharpType, fieldHlslType, fieldName, bufferIndex) + public ConstantBufferFieldInfo(string fieldHlslType, string fieldName, int bufferIndex) + : base(fieldHlslType, fieldName, bufferIndex) { } diff --git a/src/ComputeSharp.Shaders/Renderer/Models/Fields/ReadOnlyBufferFieldInfo.cs b/src/ComputeSharp.Shaders/Renderer/Models/Fields/ReadOnlyBufferFieldInfo.cs index 3323a8d6..c8725c91 100644 --- a/src/ComputeSharp.Shaders/Renderer/Models/Fields/ReadOnlyBufferFieldInfo.cs +++ b/src/ComputeSharp.Shaders/Renderer/Models/Fields/ReadOnlyBufferFieldInfo.cs @@ -1,5 +1,4 @@ -using System; -using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract; +using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract; namespace ComputeSharp.Shaders.Renderer.Models.Fields { @@ -11,12 +10,11 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields /// /// Creates a new instance with the specified parameters. /// - /// The type of the current field in the C# source. /// The type of the current field in the HLSL shader. /// The name of the current field. /// The index of the current readonly buffer field. - public ReadOnlyBufferFieldInfo(Type fieldCsharpType, string fieldHlslType, string fieldName, int bufferIndex) - : base(fieldCsharpType, fieldHlslType, fieldName, bufferIndex) + public ReadOnlyBufferFieldInfo(string fieldHlslType, string fieldName, int bufferIndex) + : base(fieldHlslType, fieldName, bufferIndex) { } diff --git a/src/ComputeSharp.Shaders/Renderer/Models/Fields/ReadWriteBufferFieldInfo.cs b/src/ComputeSharp.Shaders/Renderer/Models/Fields/ReadWriteBufferFieldInfo.cs index 955b17b1..f555cd9d 100644 --- a/src/ComputeSharp.Shaders/Renderer/Models/Fields/ReadWriteBufferFieldInfo.cs +++ b/src/ComputeSharp.Shaders/Renderer/Models/Fields/ReadWriteBufferFieldInfo.cs @@ -1,5 +1,4 @@ -using System; -using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract; +using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract; namespace ComputeSharp.Shaders.Renderer.Models.Fields { @@ -11,12 +10,11 @@ namespace ComputeSharp.Shaders.Renderer.Models.Fields /// /// Creates a new instance with the specified parameters. /// - /// The type of the current field in the C# source. /// The type of the current field in the HLSL shader. /// The name of the current field. /// The index of the current read write buffer field. - public ReadWriteBufferFieldInfo(Type fieldCsharpType, string fieldHlslType, string fieldName, int bufferIndex) - : base(fieldCsharpType, fieldHlslType, fieldName, bufferIndex) + public ReadWriteBufferFieldInfo(string fieldHlslType, string fieldName, int bufferIndex) + : base(fieldHlslType, fieldName, bufferIndex) { } diff --git a/src/ComputeSharp.Shaders/Renderer/Templates/ShaderTemplate.mustache b/src/ComputeSharp.Shaders/Renderer/Templates/ShaderTemplate.mustache index 62515497..5c2c9822 100644 --- a/src/ComputeSharp.Shaders/Renderer/Templates/ShaderTemplate.mustache +++ b/src/ComputeSharp.Shaders/Renderer/Templates/ShaderTemplate.mustache @@ -1,41 +1,37 @@ -/* =============== - * AUTO GENERATED - * =============== - * This shader was created by ComputeSharp. - * For info or issues: https://github.com/Sergio0694/ComputeSharp */ +// ================================================ +// AUTO GENERATED +// ================================================ +// This shader was created by ComputeSharp. +// See: https://github.com/Sergio0694/ComputeSharp. {{!Captured variables buffer}} -// Scalar/vector variables cbuffer _ : register(b0) { - uint __x__; // Target X iterations - uint __y__; // Target Y iterations - uint __z__; // Target Z iterations + uint __x; + uint __y; + uint __z; {{#FieldsList}} - {{&FieldHlslType}} {{FieldName}}; + {{&FieldType}} {{FieldName}}; {{/FieldsList}} } {{#BuffersList}} {{#IsConstantBuffer}} {{!Constant buffer}} -// {{&FieldCsharpType}} buffer "{{FieldName}}" cbuffer _{{FieldName}} : register(b{{BufferIndex}}) { - {{&FieldHlslType}} {{FieldName}}[2]; + {{&FieldType}} {{FieldName}}[2]; } {{/IsConstantBuffer}} {{#IsReadOnlyBuffer}} {{!Readonly buffer}} -// {{&FieldCsharpType}} buffer "{{FieldName}}" -{{&FieldHlslType}} {{FieldName}} : register(t{{BufferIndex}}); +{{&FieldType}} {{FieldName}} : register(t{{BufferIndex}}); {{/IsReadOnlyBuffer}} {{#IsReadWriteBuffer}} {{!Read write buffer}} -// {{&FieldCsharpType}} buffer "{{FieldName}}" -{{&FieldHlslType}} {{FieldName}} : register(u{{BufferIndex}}); +{{&FieldType}} {{FieldName}} : register(u{{BufferIndex}}); {{/IsReadWriteBuffer}} {{/BuffersList}} {{#FunctionsList}} @@ -53,13 +49,11 @@ cbuffer _{{FieldName}} : register(b{{BufferIndex}}) {{/LocalFunctionsList}} {{!Shader entry point}} -// Shader body -[Shader("compute")] [NumThreads({{NumThreadsX}}, {{NumThreadsY}}, {{NumThreadsZ}})] void CSMain(uint3 {{ThreadsIdsVariableName}} : SV_DispatchThreadId) { - if ({{ThreadsIdsVariableName}}.x < __x__ && - {{ThreadsIdsVariableName}}.y < __y__ && - {{ThreadsIdsVariableName}}.z < __z__) // Automatic bounds check + if ({{ThreadsIdsVariableName}}.x < __x && + {{ThreadsIdsVariableName}}.y < __y && + {{ThreadsIdsVariableName}}.z < __z) {{&ShaderBody}} } diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs index b44dd89f..1a55b48c 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs @@ -184,7 +184,7 @@ namespace ComputeSharp.Shaders.Translation string typeName = HlslKnownTypes.GetMappedName(fieldType.GenericTypeArguments[0]); - this.hlslBuffersInfo.Add(new ConstantBufferFieldInfo(fieldType, typeName, fieldName, (int)this.constantBuffersCount++)); + this.hlslBuffersInfo.Add(new ConstantBufferFieldInfo(typeName, fieldName, (int)this.constantBuffersCount++)); } else if (HlslKnownTypes.IsReadOnlyBufferType(fieldType)) { @@ -197,7 +197,7 @@ namespace ComputeSharp.Shaders.Translation string typeName = HlslKnownTypes.GetMappedName(fieldType); - this.hlslBuffersInfo.Add(new ReadOnlyBufferFieldInfo(fieldType, typeName, fieldName, (int)this.readOnlyBuffersCount++)); + this.hlslBuffersInfo.Add(new ReadOnlyBufferFieldInfo(typeName, fieldName, (int)this.readOnlyBuffersCount++)); } else if (HlslKnownTypes.IsReadWriteBufferType(fieldType)) { @@ -210,7 +210,7 @@ namespace ComputeSharp.Shaders.Translation string typeName = HlslKnownTypes.GetMappedName(fieldType); - this.hlslBuffersInfo.Add(new ReadWriteBufferFieldInfo(fieldType, typeName, fieldName, (int)this.readWriteBuffersCount++)); + this.hlslBuffersInfo.Add(new ReadWriteBufferFieldInfo(typeName, fieldName, (int)this.readWriteBuffersCount++)); } else if (HlslKnownTypes.IsKnownScalarType(fieldType) || HlslKnownTypes.IsKnownVectorType(fieldType)) { @@ -218,7 +218,7 @@ namespace ComputeSharp.Shaders.Translation string typeName = HlslKnownTypes.GetMappedName(fieldType); - this.fieldsInfo.Add(new CapturedFieldInfo(fieldType, typeName, fieldName)); + this.fieldsInfo.Add(new CapturedFieldInfo(typeName, fieldName)); } else if (fieldType.IsDelegate() && memberInfo.GetValue(shader) is Delegate func &&