Initial draft support for 2D texture sampling

このコミットが含まれているのは:
Sergio Pedri committed 2021-05-11 01:54:37 +02:00
1 親 5684e68637
コミット 640e612464
14ファイル変更
+194 -52

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

+9 -3
ファイルの表示
@@ -86,7 +86,8 @@ namespace ComputeSharp.SourceGenerators
var implicitTextureField = isComputeShader ? default((string, string)?) : (HlslKnownTypes.GetMappedNameForPixelShaderType(pixelShaderSymbol!), "__outputTexture");
var processedMembers = GetProcessedFields(context, structDeclarationSymbol, discoveredTypes, isComputeShader).ToArray();
var sharedBuffers = GetGroupSharedMembers(context, structDeclarationSymbol, discoveredTypes).ToArray();
var (entryPoint, processedMethods, forwardDeclarations) = GetProcessedMethods(context, structDeclaration, structDeclarationSymbol, semanticModel, discoveredTypes, staticMethods, constantDefinitions, isComputeShader);
var (entryPoint, processedMethods, forwardDeclarations, isSamplerUsed) = GetProcessedMethods(context, structDeclaration, structDeclarationSymbol, semanticModel, discoveredTypes, staticMethods, constantDefinitions, isComputeShader);
var implicitSamplerField = isSamplerUsed ? ("SamplerState", "__sampler") : default((string, string)?);
var processedTypes = GetProcessedTypes(discoveredTypes).ToArray();
var processedConstants = GetProcessedConstants(constantDefinitions);
var staticFields = GetStaticFields(context, semanticModel, structDeclaration, structDeclarationSymbol, discoveredTypes, constantDefinitions);
@@ -100,6 +101,7 @@ namespace ComputeSharp.SourceGenerators
AttributeArgument(TypeOfExpression(IdentifierName(structDeclarationSymbol.ToDisplayString()))),
AttributeArgument(ArrayExpression(processedTypes)),
AttributeArgument(ArrayExpression(implicitTextureField)),
AttributeArgument(ArrayExpression(implicitSamplerField)),
AttributeArgument(NestedArrayExpression(processedMembers)),
AttributeArgument(ArrayExpression(forwardDeclarations)),
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(entryPoint))),
@@ -319,7 +321,7 @@ namespace ComputeSharp.SourceGenerators
/// <param name="isComputeShader">Indicates whether or not <paramref name="structDeclarationSymbol"/> represents a compute shader.</param>
/// <returns>A sequence of processed methods in <paramref name="structDeclaration"/>, and the entry point.</returns>
[Pure]
private static (string EntryPoint, IEnumerable<string> Methods, IEnumerable<string> Declarations) GetProcessedMethods(
private static (string EntryPoint, IEnumerable<string> Methods, IEnumerable<string> Declarations, bool IsSamplerUser) GetProcessedMethods(
GeneratorExecutionContext context,
StructDeclarationSyntax structDeclaration,
INamedTypeSymbol structDeclarationSymbol,
@@ -338,6 +340,7 @@ namespace ComputeSharp.SourceGenerators
string? entryPoint = null;
List<string> methods = new();
List<string> declarations = new();
bool isSamplerUsed = false;
foreach (MethodDeclarationSyntax methodDeclaration in methodDeclarations)
{
@@ -367,6 +370,9 @@ namespace ComputeSharp.SourceGenerators
// Rewrite the method syntax tree
MethodDeclarationSyntax? processedMethod = shaderSourceRewriter.Visit(methodDeclaration)!.WithoutTrivia();
// Track the implicit sampler, if used
isSamplerUsed = isSamplerUsed || shaderSourceRewriter.IsSamplerUsed;
// Emit the extracted local functions first
foreach (var localFunction in shaderSourceRewriter.LocalFunctions)
{
@@ -399,7 +405,7 @@ namespace ComputeSharp.SourceGenerators
declarations.Add(staticMethod.AsDefinition().NormalizeWhitespace().ToFullString());
}
return (entryPoint!, methods, declarations);
return (entryPoint!, methods, declarations, isSamplerUsed);
}
/// <summary>
+23
ファイルの表示
@@ -33,6 +33,17 @@ namespace ComputeSharp.SourceGenerators.Mappings
[$"ComputeSharp.IReadWriteTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3"
};
/// <summary>
/// The mapping of supported known samplers to HLSL resource type names.
/// </summary>
private static readonly IReadOnlyDictionary<string, string?> KnownResourceSamplers = new Dictionary<string, string?>
{
[$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2",
[$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(Float2).FullName}]"] = null,
[$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2",
[$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(Float2).FullName}]"] = null
};
/// <summary>
/// The mapping of supported known size accessors for HLSL resource types.
/// </summary>
@@ -389,6 +400,18 @@ namespace ComputeSharp.SourceGenerators.Mappings
return KnownResourceIndexers.TryGetValue(name, out mapped);
}
/// <summary>
/// Tries to get the mapped HLSL-compatible sampler resource type name for the input indexer name.
/// </summary>
/// <param name="name">The input fully qualified indexer name.</param>
/// <param name="mapped">The mapped type name, if one is found.</param>
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader for the given sampler.</returns>
[Pure]
public static bool TryGetMappedResourceSamplerAccessType(string name, out string? mapped)
{
return KnownResourceSamplers.TryGetValue(name, out mapped);
}
/// <summary>
/// Tries to get the mapped HLSL-compatible indexer vector type name for the input indexer name.
/// </summary>
+50 -19
ファイルの表示
@@ -21,6 +21,26 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
/// </summary>
internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
{
/// <summary>
/// The <see cref="SemanticModelProvider"/> instance with semantic info on the target syntax tree.
/// </summary>
protected readonly SemanticModelProvider SemanticModel;
/// <summary>
/// The collection of discovered custom types.
/// </summary>
protected readonly ICollection<INamedTypeSymbol> DiscoveredTypes;
/// <summary>
/// The collection of discovered constant definitions.
/// </summary>
protected readonly IDictionary<IFieldSymbol, string> ConstantDefinitions;
/// <summary>
/// The current generator context in use.
/// </summary>
protected readonly GeneratorExecutionContext Context;
/// <summary>
/// Creates a new <see cref="HlslSourceRewriter"/> instance with the specified parameters.
/// </summary>
@@ -41,24 +61,9 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
}
/// <summary>
/// The <see cref="SemanticModelProvider"/> instance with semantic info on the target syntax tree.
/// Gets whether or not the shader uses a texture sampler at least once.
/// </summary>
protected readonly SemanticModelProvider SemanticModel;
/// <summary>
/// The collection of discovered custom types.
/// </summary>
protected readonly ICollection<INamedTypeSymbol> DiscoveredTypes;
/// <summary>
/// The collection of discovered constant definitions.
/// </summary>
protected readonly IDictionary<IFieldSymbol, string> ConstantDefinitions;
/// <summary>
/// The current generator context in use.
/// </summary>
protected readonly GeneratorExecutionContext Context;
public bool IsSamplerUsed { get; private set; }
/// <inheritdoc/>
public override SyntaxNode VisitCastExpression(CastExpressionSyntax node)
@@ -201,8 +206,8 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
{
string propertyName = operation.Property.GetFullMetadataName();
// Rewrite texture resource indices taking vectors into individual indices as per HLSL spec.
// For instance: texture[ThreadIds.XY] will be rewritten as texture[ThreadIds.X, ThreadIds.Y].
// Rewrite texture resource indices taking individual indices a vector argument, as per HLSL spec.
// For instance: texture[ThreadIds.X, ThreadIds.Y] will be rewritten as texture[int2(ThreadIds.X, ThreadIds.Y)].
if (HlslKnownMembers.TryGetMappedResourceIndexerTypeName(propertyName, out string? mapping))
{
var index = InvocationExpression(IdentifierName(mapping!), ArgumentList(updatedNode.ArgumentList.Arguments));
@@ -210,6 +215,32 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
return updatedNode.WithArgumentList(BracketedArgumentList(SingletonSeparatedList(Argument(index))));
}
// Rewrite texture resource sampled accesses, if needed
if (HlslKnownMembers.TryGetMappedResourceSamplerAccessType(propertyName, out mapping))
{
IsSamplerUsed = true;
// Get the syntax for the argument syntax transformation as described above
ArgumentSyntax coordinateSyntax = mapping switch
{
not null => Argument(InvocationExpression(IdentifierName(mapping!), ArgumentList(updatedNode.ArgumentList.Arguments))),
null => updatedNode.ArgumentList.Arguments[0]
};
// Transform an indexer syntax into a sampling call with the implicit static linear sampler.
// For instance: texture[uv] will be rewritten as texture.SampleLevel(__sampler, uv, 0).
return
InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
updatedNode.Expression,
IdentifierName("SampleLevel")))
.AddArgumentListArguments(
Argument(IdentifierName("__sampler")),
coordinateSyntax,
Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0))));
}
// If the current property is a swizzled matrix indexer, ensure all the arguments are constants, and rewrite
// the property access to the corresponding HLSL syntax. For instance, m[M11, M12] will become m._m00_m01.
if (HlslKnownMembers.IsKnownMatrixIndexer(propertyName))
+8
ファイルの表示
@@ -23,6 +23,7 @@ namespace ComputeSharp.__Internals
/// <param name="shaderType">The type of the current shader.</param>
/// <param name="types">The collection of custom types.</param>
/// <param name="implicitTextureField">The implicit texture field info, if present.</param>
/// <param name="implicitSamplerFields">The implicit texture sampler field info, if present.</param>
/// <param name="fields">The mapped collection of shader fields.</param>
/// <param name="forwardDeclarations">The forward declarations for static methods.</param>
/// <param name="executeMethod">The source code for the <see cref="IComputeShader.Execute"/> method.</param>
@@ -34,6 +35,7 @@ namespace ComputeSharp.__Internals
Type shaderType,
string[] types,
string[]? implicitTextureField,
string[]? implicitSamplerFields,
object[] fields,
string[] forwardDeclarations,
string executeMethod,
@@ -45,6 +47,7 @@ namespace ComputeSharp.__Internals
ShaderType = shaderType;
Types = types;
ImplicitTextureField = implicitTextureField is null ? null : (implicitTextureField[0], implicitTextureField[1]);
ImplicitSamplerField = implicitSamplerFields is null ? null : (implicitSamplerFields[0], implicitSamplerFields[1]);
Fields = fields.Cast<string[]>().ToDictionary(static arg => arg[0], static arg => (arg[1], arg[2]));
ForwardDeclarations = forwardDeclarations;
ExecuteMethod = executeMethod;
@@ -69,6 +72,11 @@ namespace ComputeSharp.__Internals
/// </summary>
internal (string Name, string Type)? ImplicitTextureField { get; }
/// <summary>
/// Gets the mapping for the implicit sampler field, if necessary.
/// </summary>
internal (string Name, string Type)? ImplicitSamplerField { get; }
/// <summary>
/// Gets the mapping of field names.
/// </summary>
+15
ファイルの表示
@@ -32,5 +32,20 @@
/// <param name="xy">The coordinates of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
TPixel this[Int2 xy] { get; }
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture with linear sampling.
/// </summary>
/// <param name="u">The horizontal normalized offset of the value to get.</param>
/// <param name="v">The vertical normalized offset of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
TPixel this[float u, float v] { get; }
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture with linear sampling.
/// </summary>
/// <param name="uv">The normalized coordinates of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
TPixel this[Float2 uv] { get; }
}
}
+7 -1
ファイルの表示
@@ -39,10 +39,16 @@ namespace ComputeSharp
/// <inheritdoc/>
public TPixel this[Int2 xy] => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture2D<T,TPixel>)}[{typeof(Int2)}]");
/// <inheritdoc/>
public TPixel this[float u, float v] => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture2D<T, TPixel>)}[{typeof(float)}, {typeof(float)}]");
/// <inheritdoc/>
public TPixel this[Float2 uv] => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture2D<T, TPixel>)}[{typeof(Float2)}]");
/// <inheritdoc/>
public override string ToString()
{
return $"ComputeSharp.ReadOnlyTexture2D<{typeof(T)},{typeof(TPixel)}>[{Width}, {Height}]";
return $"ComputeSharp.ReadOnlyTexture2D<{typeof(T)}, {typeof(TPixel)}>[{Width}, {Height}]";
}
}
}
+1 -1
ファイルの表示
@@ -43,7 +43,7 @@ namespace ComputeSharp
/// <inheritdoc/>
public override string ToString()
{
return $"ComputeSharp.ReadOnlyTexture3D<{typeof(T)},{nameof(TPixel)}>[{Width}, {Height}, {Depth}]";
return $"ComputeSharp.ReadOnlyTexture3D<{typeof(T)}, {nameof(TPixel)}>[{Width}, {Height}, {Depth}]";
}
}
}
+1 -1
ファイルの表示
@@ -42,7 +42,7 @@ namespace ComputeSharp
/// <inheritdoc/>
public override string ToString()
{
return $"ComputeSharp.ReadWriteTexture2D<{typeof(T)},{typeof(TPixel)}>[{Width}, {Height}]";
return $"ComputeSharp.ReadWriteTexture2D<{typeof(T)}, {typeof(TPixel)}>[{Width}, {Height}]";
}
}
}
+1 -1
ファイルの表示
@@ -43,7 +43,7 @@ namespace ComputeSharp
/// <inheritdoc/>
public override string ToString()
{
return $"ComputeSharp.ReadWriteTexture3D<{typeof(T)},{nameof(TPixel)}>[{Width}, {Height}, {Depth}]";
return $"ComputeSharp.ReadWriteTexture3D<{typeof(T)}, {nameof(TPixel)}>[{Width}, {Height}, {Depth}]";
}
}
}
+19 -3
ファイルの表示
@@ -17,12 +17,14 @@ namespace ComputeSharp.Shaders.Extensions
/// <param name="d3D12Device">The target <see cref="ID3D12Device"/> to use to create the root signature.</param>
/// <param name="d3D12Root32BitConstantsCount">The number of 32 bit root constants to load.</param>
/// <param name="d3D12DescriptorRanges1">The input descriptor ranges for the signature to create.</param>
/// <param name="isStaticSamplerUsed">Indicates whether or not a static sampler is used.</param>
/// <returns>A pointer to the newly allocated <see cref="ID3D12RootSignature"/> instance.</returns>
/// <exception cref="Exception">Thrown when the creation of the root signature fails.</exception>
public static ComPtr<ID3D12RootSignature> CreateRootSignature(
this ref ID3D12Device d3D12Device,
int d3D12Root32BitConstantsCount,
ReadOnlySpan<D3D12_DESCRIPTOR_RANGE1> d3D12DescriptorRanges1)
ReadOnlySpan<D3D12_DESCRIPTOR_RANGE1> d3D12DescriptorRanges1,
bool isStaticSamplerUsed)
{
using ComPtr<ID3DBlob> d3D3Blob = default;
using ComPtr<ID3DBlob> d3D3BlobError = default;
@@ -42,11 +44,25 @@ namespace ComputeSharp.Shaders.Extensions
D3D12_ROOT_PARAMETER1.InitAsDescriptorTable(out d3D12RootParameters1[i + 1], 1, d3D12DescriptorRange1 + i);
}
D3D12_STATIC_SAMPLER_DESC d3D12SamplerDescription;
// Create the linear static sampler if needed
if (isStaticSamplerUsed)
{
D3D12_STATIC_SAMPLER_DESC.Init(
out d3D12SamplerDescription,
shaderRegister: 0,
filter: D3D12_FILTER.D3D12_FILTER_MIN_MAG_MIP_LINEAR,
comparisonFunc: D3D12_COMPARISON_FUNC.D3D12_COMPARISON_FUNC_NEVER);
}
// Root signature description wrapping the packed collection of root parameters
D3D12_VERSIONED_ROOT_SIGNATURE_DESC.Init_1_1(
out D3D12_VERSIONED_ROOT_SIGNATURE_DESC d3D12VersionedRootSignatureDescription,
(uint)d3D12DescriptorRanges1.Length + 1,
d3D12RootParameters1);
numParameters: (uint)d3D12DescriptorRanges1.Length + 1,
_pParameters: d3D12RootParameters1,
numStaticSamplers: isStaticSamplerUsed ? 1u : 0u,
_pStaticSamplers: isStaticSamplerUsed ? &d3D12SamplerDescription : null);
// Serialize the root signature from the data just computed. When this is done
// we just work with the resulting blobs, so the input data can be unpinned.
+21 -10
ファイルの表示
@@ -102,25 +102,25 @@ namespace ComputeSharp.Shaders.Renderer
builder.AppendLine('}');
// Buffers
foreach (var buffer in info.HlslResourceInfo)
// Resources
foreach (var resource in info.HlslResourceInfo)
{
builder.AppendLine();
switch (buffer)
switch (resource)
{
// Constant buffer go to cbuffer fields with a dummy local
case HlslResourceInfo.Constant _:
builder.Append("cbuffer _");
builder.Append(buffer.FieldName);
builder.Append(resource.FieldName);
builder.Append(" : register(b");
builder.Append(buffer.BufferIndex.ToString());
builder.Append(resource.RegisterIndex.ToString());
builder.AppendLine(')');
builder.AppendLine('{');
builder.Append(" ");
builder.Append(buffer.FieldType);
builder.Append(resource.FieldType);
builder.Append(' ');
builder.Append(buffer.FieldName);
builder.Append(resource.FieldName);
builder.AppendLine("[2];");
builder.AppendLine('}');
break;
@@ -132,12 +132,23 @@ namespace ComputeSharp.Shaders.Renderer
case HlslResourceInfo.ReadWrite _:
registerId = 'u';
StructuredBuffer:
builder.Append(buffer.FieldType);
builder.Append(resource.FieldType);
builder.Append(' ');
builder.Append(buffer.FieldName);
builder.Append(resource.FieldName);
builder.Append(" : register(");
builder.Append(registerId);
builder.Append(buffer.BufferIndex.ToString());
builder.Append(resource.RegisterIndex.ToString());
builder.AppendLine(");");
break;
// Texture samplers
case HlslResourceInfo.Sampler _:
builder.Append(resource.FieldType);
builder.Append(' ');
builder.Append(resource.FieldName);
builder.Append(" : register(");
builder.Append('s');
builder.Append(resource.RegisterIndex.ToString());
builder.AppendLine(");");
break;
}
+18 -12
ファイルの表示
@@ -1,37 +1,43 @@
#pragma warning disable CS1572, CS1573
namespace ComputeSharp.Shaders.Renderer.Models
namespace ComputeSharp.Shaders.Renderer.Models
{
/// <summary>
/// A model that contains info on a shader typed resource field.
/// A model that contains info on a shader resource field.
/// </summary>
/// <param name="FieldType">The type of the current field in the HLSL shader.</param>
/// <param name="FieldName">The name to use for the current field.</param>
/// <param name="BufferIndex">The register index to bind the resource to.</param>
internal abstract record HlslResourceInfo(string FieldType, string FieldName, int BufferIndex)
/// <param name="RegisterIndex">The register index to bind the resource to.</param>
internal abstract record HlslResourceInfo(string FieldType, string FieldName, int RegisterIndex)
: CapturedFieldInfo(FieldType, FieldName)
{
/// <summary>
/// A model that represents a captured constant buffer in a shader.
/// </summary>
/// <inheritdoc/>
public sealed record Constant(string FieldType, string FieldName, int BufferIndex)
: HlslResourceInfo(FieldType, FieldName, BufferIndex);
public sealed record Constant(string FieldType, string FieldName, int RegisterIndex)
: HlslResourceInfo(FieldType, FieldName, RegisterIndex);
/// <summary>
/// A model that represents a captured readonly typed resource in a shader.
/// Maps to either <see cref="ComputeSharp.ReadOnlyBuffer{T}"/> or <see cref="ComputeSharp.ReadOnlyTexture2D{T}"/>.
/// </summary>
/// <inheritdoc/>
public sealed record ReadOnly(string FieldType, string FieldName, int BufferIndex)
: HlslResourceInfo(FieldType, FieldName, BufferIndex);
public sealed record ReadOnly(string FieldType, string FieldName, int RegisterIndex)
: HlslResourceInfo(FieldType, FieldName, RegisterIndex);
/// <summary>
/// A model that represents a captured writeable buffer in a shader.
/// Maps to either <see cref="ComputeSharp.ReadWriteBuffer{T}"/> or <see cref="ComputeSharp.ReadWriteTexture2D{T}"/>.
/// </summary>
/// <inheritdoc/>
public sealed record ReadWrite(string FieldType, string FieldName, int BufferIndex)
: HlslResourceInfo(FieldType, FieldName, BufferIndex);
public sealed record ReadWrite(string FieldType, string FieldName, int RegisterIndex)
: HlslResourceInfo(FieldType, FieldName, RegisterIndex);
/// <summary>
/// A model that represents a captured sampler in a shader.
/// This resource type doesn't have a mapping to a public API.
/// </summary>
/// <inheritdoc/>
public sealed record Sampler(string FieldType, string FieldName, int RegisterIndex)
: HlslResourceInfo(FieldType, FieldName, RegisterIndex);
}
}
+1 -1
ファイルの表示
@@ -287,7 +287,7 @@ namespace ComputeSharp.Shaders
[MethodImpl(MethodImplOptions.NoInlining)]
private static unsafe void CreatePipelineData(GraphicsDevice device, in CachedShader<T> shaderData, out PipelineData pipelineData)
{
using ComPtr<ID3D12RootSignature> d3D12RootSignature = device.D3D12Device->CreateRootSignature(shaderData.Loader.D3D12Root32BitConstantsCount, shaderData.Loader.D3D12DescriptorRanges1);
using ComPtr<ID3D12RootSignature> d3D12RootSignature = device.D3D12Device->CreateRootSignature(shaderData.Loader.D3D12Root32BitConstantsCount, shaderData.Loader.D3D12DescriptorRanges1, shaderData.Loader.IsStaticSamplerUsed);
using ComPtr<ID3D12PipelineState> d3D12PipelineState = device.D3D12Device->CreateComputePipelineState(d3D12RootSignature.Get(), shaderData.Bytecode.D3D12ShaderBytecode);
pipelineData = new PipelineData(d3D12RootSignature.Get(), d3D12PipelineState.Get());
+20
ファイルの表示
@@ -45,6 +45,11 @@ namespace ComputeSharp.Shaders.Translation
/// </summary>
private uint readWriteBuffersCount;
/// <summary>
/// The number of samplers to define in the shader.
/// </summary>
private uint samplersCount;
/// <summary>
/// The array of <see cref="D3D12_DESCRIPTOR_RANGE1"/> items that are required to load the captured values.
/// </summary>
@@ -101,6 +106,11 @@ namespace ComputeSharp.Shaders.Translation
/// <inheritdoc/>
public bool IsComputeShader { get; private set; }
/// <summary>
/// Gets whether or not the current shader requires access to a static sampler.
/// </summary>
public bool IsStaticSamplerUsed { get; private set; }
/// <inheritdoc/>
public IReadOnlyList<HlslResourceInfo> HlslResourceInfo => this.hlslResourceInfo;
@@ -205,6 +215,16 @@ namespace ComputeSharp.Shaders.Translation
ThrowHelper.ThrowInvalidOperationException("The shader body must contain at least one field");
}
// Add the implicit sampler descriptor if necessary
if (Attribute.ImplicitSamplerField is not null)
{
(string hlslType, string hlslName) = Attribute.ImplicitSamplerField!.Value;
this.hlslResourceInfo.Add(new HlslResourceInfo.Sampler(hlslType, hlslName, (int)this.samplersCount++));
IsStaticSamplerUsed = true;
}
// Inspect the captured fields
foreach (FieldInfo fieldInfo in shaderFields)
{