Merge pull request #339 from Sergio0694/dev/sample-apis-update

Switch sample texture indexers to sample methods
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2022-08-10 02:41:38 +02:00
コミット ccc97b706a
35ファイル変更
+256 -284

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

+21 -18
ファイルの表示
@@ -143,24 +143,27 @@ jobs:
- name: Run ComputeSharp.Tests.Internals (.NET 6)
run: dotnet test tests\ComputeSharp.Tests.Internals\ComputeSharp.Tests.Internals.csproj -c Release -f net6.0 -v n -l "console;verbosity=detailed"
shell: cmd
- name: Run ComputeSharp.Tests (.NET Core 3.1)
run: dotnet test tests\ComputeSharp.Tests\ComputeSharp.Tests.csproj -c Release -f netcoreapp3.1 /p:Platform=x64 -v n -l "console;verbosity=detailed"
shell: cmd
- name: Run ComputeSharp.Tests.DisableDynamicCompilation (.NET Core 3.1)
run: dotnet test tests\ComputeSharp.Tests.DisableDynamicCompilation\ComputeSharp.Tests.DisableDynamicCompilation.csproj -c Release -f netcoreapp3.1 /p:Platform=x64 -v n -l "console;verbosity=detailed"
shell: cmd
- name: Run ComputeSharp.Tests.Internals (.NET Core 3.1)
run: dotnet test tests\ComputeSharp.Tests.Internals\ComputeSharp.Tests.Internals.csproj -c Release -f netcoreapp3.1 /p:Platform=x64 -v n -l "console;verbosity=detailed"
shell: cmd
- name: Run ComputeSharp.Tests (.NET Framework 4.7.2)
run: dotnet test tests\ComputeSharp.Tests\ComputeSharp.Tests.csproj -c Release -f net472 /p:Platform=x64 -v n -l "console;verbosity=detailed"
shell: cmd
- name: Run ComputeSharp.Tests.DisableDynamicCompilation (.NET Framework 4.7.2)
run: dotnet test tests\ComputeSharp.Tests.DisableDynamicCompilation\ComputeSharp.Tests.DisableDynamicCompilation.csproj -c Release -f net472 /p:Platform=x64 -v n -l "console;verbosity=detailed"
shell: cmd
- name: Run ComputeSharp.Tests.Internals (.NET Framework 4.7.2)
run: dotnet test tests\ComputeSharp.Tests.Internals\ComputeSharp.Tests.Internals.csproj -c Release -f net472 /p:Platform=x64 -v n -l "console;verbosity=detailed"
shell: cmd
# These tests are failing in the CI due to the preview SDK with ref escape semantics, uncomment when code is updated
#- name: Run ComputeSharp.Tests (.NET Core 3.1)
# run: dotnet test tests\ComputeSharp.Tests\ComputeSharp.Tests.csproj -c Release -f netcoreapp3.1 /p:Platform=x64 -v n -l "console;verbosity=detailed"
# shell: cmd
#- name: Run ComputeSharp.Tests.DisableDynamicCompilation (.NET Core 3.1)
# run: dotnet test tests\ComputeSharp.Tests.DisableDynamicCompilation\ComputeSharp.Tests.DisableDynamicCompilation.csproj -c Release -f netcoreapp3.1 /p:Platform=x64 -v n -l "console;verbosity=detailed"
# shell: cmd
#- name: Run ComputeSharp.Tests.Internals (.NET Core 3.1)
# run: dotnet test tests\ComputeSharp.Tests.Internals\ComputeSharp.Tests.Internals.csproj -c Release -f netcoreapp3.1 /p:Platform=x64 -v n -l "console;verbosity=detailed"
# shell: cmd
#- name: Run ComputeSharp.Tests (.NET Framework 4.7.2)
# run: dotnet test tests\ComputeSharp.Tests\ComputeSharp.Tests.csproj -c Release -f net472 /p:Platform=x64 -v n -l "console;verbosity=detailed"
# shell: cmd
#- name: Run ComputeSharp.Tests.DisableDynamicCompilation (.NET Framework 4.7.2)
# run: dotnet test tests\ComputeSharp.Tests.DisableDynamicCompilation\ComputeSharp.Tests.DisableDynamicCompilation.csproj -c Release -f net472 /p:Platform=x64 -v n -l "console;verbosity=detailed"
# shell: cmd
#- name: Run ComputeSharp.Tests.Internals (.NET Framework 4.7.2)
# run: dotnet test tests\ComputeSharp.Tests.Internals\ComputeSharp.Tests.Internals.csproj -c Release -f net472 /p:Platform=x64 -v n -l "console;verbosity=detailed"
# shell: cmd
- name: Run ComputeSharp.Tests.SourceGenerators
run: dotnet test tests\ComputeSharp.Tests.SourceGenerators\ComputeSharp.Tests.SourceGenerators.csproj -v n -l "console;verbosity=detailed"
shell: cmd
+1 -1
ファイルの表示
@@ -111,7 +111,7 @@ internal readonly partial struct ContouredLayers : IPixelShader<float4>
// Layer color. Based on the shade, layer number and smoothing factor.
private float3 GetColor(float2 p, float sh, float fi)
{
float3 tx = texture[p + Hash21(new float2(sh, fi))].XYZ;
float3 tx = texture.Sample(p + Hash21(new float2(sh, fi))).XYZ;
tx *= tx;
+13
ファイルの表示
@@ -37,4 +37,17 @@ partial class HlslKnownMethods
knownMethods.Add($"{typeof(D2D).FullName}{Type.Delimiter}{method.Name}", hlslName);
}
}
/// <inheritdoc/>
private static partial IReadOnlyDictionary<string, string?> BuildKnownResourceSamplers()
{
return new Dictionary<string, string?>
{
[$"ComputeSharp.D2D1.D2D1ResourceTexture1D.Sample({typeof(float).FullName})"] = null,
[$"ComputeSharp.D2D1.D2D1ResourceTexture2D.Sample({typeof(float).FullName}, {typeof(float).FullName})"] = "float2",
[$"ComputeSharp.D2D1.D2D1ResourceTexture2D.Sample({typeof(Float2).FullName})"] = null,
[$"ComputeSharp.D2D1.D2D1ResourceTexture3D.Sample({typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName})"] = "float3",
[$"ComputeSharp.D2D1.D2D1ResourceTexture3D.Sample({typeof(Float3).FullName})"] = null
};
}
}
-13
ファイルの表示
@@ -15,19 +15,6 @@ partial class HlslKnownProperties
};
}
/// <inheritdoc/>
private static partial IReadOnlyDictionary<string, string?> BuildKnownResourceSamplers()
{
return new Dictionary<string, string?>
{
[$"ComputeSharp.D2D1.D2D1ResourceTexture1D.this[{typeof(float).FullName}]"] = null,
[$"ComputeSharp.D2D1.D2D1ResourceTexture2D.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2",
[$"ComputeSharp.D2D1.D2D1ResourceTexture2D.this[{typeof(Float2).FullName}]"] = null,
[$"ComputeSharp.D2D1.D2D1ResourceTexture3D.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3",
[$"ComputeSharp.D2D1.D2D1ResourceTexture3D.this[{typeof(Float3).FullName}]"] = null
};
}
/// <inheritdoc/>
private static partial IReadOnlyDictionary<string, (int Rank, int Axis)> BuildKnownSizeAccessors()
{
-37
ファイルの表示
@@ -1,37 +0,0 @@
using ComputeSharp.SourceGeneration.Mappings;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Operations;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
namespace ComputeSharp.SourceGeneration.SyntaxRewriters;
/// <inheritdoc cref="HlslSourceRewriter"/>
partial class HlslSourceRewriter
{
/// <inheritdoc/>
private partial SyntaxNode RewriteSampledTextureAccess(IPropertyReferenceOperation operation, ElementAccessExpressionSyntax node, string? mappedType)
{
// Get the syntax for the argument syntax transformation as described above
ArgumentSyntax coordinateSyntax = mappedType switch
{
not null => Argument(InvocationExpression(IdentifierName(mappedType!), ArgumentList(node.ArgumentList.Arguments))),
null => node.ArgumentList.Arguments[0]
};
string fieldName = (operation.Instance as IFieldReferenceOperation)?.Member.Name ?? "";
_ = HlslKnownKeywords.TryGetMappedName(fieldName, out string? mapped);
// Transform an indexer syntax into a sampling call with the implicit static linear sampler.
// For instance: texture[uv] will be rewritten as texture.Sample(__sampler__texture, uv).
return
InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
node.Expression,
IdentifierName("Sample")))
.AddArgumentListArguments(Argument(IdentifierName($"__sampler__{mapped ?? fieldName}")), coordinateSyntax);
}
}
+16
ファイルの表示
@@ -1,6 +1,8 @@
using ComputeSharp.SourceGeneration.Mappings;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Operations;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
namespace ComputeSharp.SourceGeneration.SyntaxRewriters;
@@ -12,6 +14,20 @@ partial class ShaderSourceRewriter
/// </summary>
public bool NeedsD2DRequiresScenePositionAttribute { get; private set; }
/// <inheritdoc/>
private partial SyntaxNode RewriteSampledTextureAccess(IInvocationOperation operation, ExpressionSyntax expression, ArgumentSyntax arguments)
{
string fieldName = (operation.Instance as IFieldReferenceOperation)?.Member.Name ?? "";
_ = HlslKnownKeywords.TryGetMappedName(fieldName, out string? mapped);
// Transform an indexer syntax into a sampling call with the implicit static linear sampler.
// For instance: texture.Sample(uv) will be rewritten as texture.Sample(__sampler__texture, uv).
return
InvocationExpression(expression)
.AddArgumentListArguments(Argument(IdentifierName($"__sampler__{mapped ?? fieldName}")), arguments);
}
/// <inheritdoc/>
private partial void TrackKnownPropertyAccess(IMemberReferenceOperation operation, MemberAccessExpressionSyntax node, string mappedName)
{
+2 -2
ファイルの表示
@@ -23,9 +23,9 @@ public readonly struct D2D1ResourceTexture1D
public ref readonly Float4 this[int x] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}[{typeof(int)}]");
/// <summary>
/// Gets a single <see cref="Float4"/> value from the current readonly texture with linear sampling.
/// Retrieves a single <see cref="Float4"/> value from the current readonly texture with linear sampling.
/// </summary>
/// <param name="u">The horizontal 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>
public ref readonly Float4 this[float u] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}[{typeof(float)}]");
public ref readonly Float4 Sample(float u) => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}.{nameof(Sample)}({typeof(float)})");
}
+4 -4
ファイルの表示
@@ -37,17 +37,17 @@ public readonly struct D2D1ResourceTexture2D
public ref readonly Float4 this[Int2 xy] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}[{typeof(Int2)}]");
/// <summary>
/// Gets a single <see cref="Float4"/> value from the current readonly texture with linear sampling.
/// Retrieves a single <see cref="Float4"/> 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>
public ref readonly Float4 this[float u, float v] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}[{typeof(float)}, {typeof(float)}]");
public ref readonly Float4 Sample(float u, float v) => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}.{nameof(Sample)}({typeof(float)}, {typeof(float)})");
/// <summary>
/// Gets a single <see cref="Float4"/> value from the current readonly texture with linear sampling.
/// Retrieves a single <see cref="Float4"/> 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>
public ref readonly Float4 this[Float2 uv] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}[{typeof(Float2)}]");
public ref readonly Float4 Sample(Float2 uv) => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}.{nameof(Sample)}({typeof(Float2)})");
}
+4 -4
ファイルの表示
@@ -44,18 +44,18 @@ public readonly struct D2D1ResourceTexture3D
public ref readonly Float4 this[Int3 xyz] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}[{typeof(Int3)}]");
/// <summary>
/// Gets a single <see cref="Float4"/> value from the current readonly texture with linear sampling.
/// Retrieves a single <see cref="Float4"/> 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>
/// <param name="w">The depthwise 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>
public ref readonly Float4 this[float u, float v, float w] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}[{typeof(float)}, {typeof(float)}, {typeof(float)}]");
public ref readonly Float4 Sample(float u, float v, float w) => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}.{nameof(Sample)}({typeof(float)}, {typeof(float)}, {typeof(float)})");
/// <summary>
/// Gets a single <see cref="Float4"/> value from the current readonly texture with linear sampling.
/// Retrieves a single <see cref="Float4"/> value from the current readonly texture with linear sampling.
/// </summary>
/// <param name="uvw">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>
public ref readonly Float4 this[Float3 uvw] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}[{typeof(Float3)}]");
public ref readonly Float4 Sample(Float3 uvw) => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}.{nameof(Sample)}({typeof(Float3)})");
}
+1 -1
ファイルの表示
@@ -78,7 +78,7 @@ public sealed partial class ShaderMethodSourceAttribute : Attribute
}
var attributes = function.Method.DeclaringType!.Assembly.GetCustomAttributes<ShaderMethodSourceAttribute>();
string methodName = function.Method.GetFullName();
string methodName = function.Method.GetFullyQualifiedName();
foreach (var attribute in attributes)
{
+4 -4
ファイルの表示
@@ -23,10 +23,10 @@ internal static partial class HlslKnownKeywords
// HLSL keywords
HashSet<string> knownKeywords = new(new[]
{
"asm", "asm_fragment", "cbuffer", "centroid", "column_major",
"compile", "discard", "dword", "export", "fxgroup", "groupshared",
"half", "inline", "inout", "line", "lineadj", "linear", "matrix",
"nointerpolation", "noperspective", "NULL", "packoffset", "pass",
"asm", "asm_fragment", "cbuffer", "buffer", "texture", "centroid",
"column_major", "compile", "discard", "dword", "export", "fxgroup",
"groupshared", "half", "inline", "inout", "line", "lineadj", "linear",
"matrix", "nointerpolation", "noperspective", "NULL", "packoffset", "pass",
"pixelfragment", "point", "precise", "register", "row_major", "sample",
"sampler", "shared", "snorm", "stateblock", "stateblock_state", "tbuffer",
"technique", "typedef", "triangle", "triangleadj", "uniform", "unorm",
+22
ファイルの表示
@@ -149,6 +149,28 @@ internal static partial class HlslKnownMethods
/// <param name="knownMethods">The mapping of known methods being built.</param>
static partial void AddKnownMethods(IDictionary<string, string> knownMethods);
/// <summary>
/// The mapping of supported known samplers to HLSL resource type names.
/// </summary>
private static readonly IReadOnlyDictionary<string, string?> KnownResourceSamplers = BuildKnownResourceSamplers();
/// <summary>
/// Builds the mapping of supported known samplers to HLSL resource type names.
/// </summary>
/// <returns>The mapping of supported known samplers to HLSL resource type names.</returns>
private static partial IReadOnlyDictionary<string, string?> BuildKnownResourceSamplers();
/// <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>
public static bool TryGetMappedResourceSamplerAccessType(string name, out string? mapped)
{
return KnownResourceSamplers.TryGetValue(name, out mapped);
}
/// <summary>
/// Tries to get the mapped HLSL-compatible method name for the input method name.
/// </summary>
-22
ファイルの表示
@@ -220,17 +220,6 @@ internal static partial class HlslKnownProperties
/// <returns>The mapping of supported known indexers to HLSL resource type names.</returns>
private static partial IReadOnlyDictionary<string, string> BuildKnownResourceIndexers();
/// <summary>
/// The mapping of supported known samplers to HLSL resource type names.
/// </summary>
private static readonly IReadOnlyDictionary<string, string?> KnownResourceSamplers = BuildKnownResourceSamplers();
/// <summary>
/// Builds the mapping of supported known samplers to HLSL resource type names.
/// </summary>
/// <returns>The mapping of supported known samplers to HLSL resource type names.</returns>
private static partial IReadOnlyDictionary<string, string?> BuildKnownResourceSamplers();
/// <summary>
/// The mapping of supported known size accessors for HLSL resource types.
/// </summary>
@@ -284,17 +273,6 @@ internal static partial class HlslKnownProperties
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>
public static bool TryGetMappedResourceSamplerAccessType(string name, out string? mapped)
{
return KnownResourceSamplers.TryGetValue(name, out mapped);
}
/// <summary>
/// Tries to get the mapped rank and axis for a given indexer name.
/// </summary>
-15
ファイルの表示
@@ -251,12 +251,6 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
return updatedNode.WithArgumentList(BracketedArgumentList(SingletonSeparatedList(Argument(index))));
}
// Rewrite texture resource sampled accesses, if needed
if (HlslKnownProperties.TryGetMappedResourceSamplerAccessType(propertyName, out mapping))
{
return RewriteSampledTextureAccess(operation, updatedNode, mapping);
}
// 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 (HlslKnownProperties.IsKnownMatrixIndexer(propertyName))
@@ -331,13 +325,4 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
return updatedToken.WithoutTrivia();
}
/// <summary>
/// Rewrites a sampled texture access.
/// </summary>
/// <param name="operation">The <see cref="IPropertyReferenceOperation"/> instance for the sampled texture access.</param>
/// <param name="node">The input <see cref="ElementAccessExpressionSyntax"/> instance for the node to rewrite.</param>
/// <param name="mappedType">The mapped type name to use for the sampled access, if any.</param>
/// <returns>A <see cref="SyntaxNode"/> representing the rewritten sampled texture access.</returns>
private partial SyntaxNode RewriteSampledTextureAccess(IPropertyReferenceOperation operation, ElementAccessExpressionSyntax node, string? mappedType);
}
+72 -43
ファイルの表示
@@ -344,56 +344,74 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
{
var updatedNode = (InvocationExpressionSyntax)base.VisitInvocationExpression(node)!;
if (SemanticModel.For(node).GetOperation(node) is IInvocationOperation operation &&
operation.TargetMethod is IMethodSymbol method &&
method.IsStatic)
if (SemanticModel.For(node).GetOperation(node) is IInvocationOperation { TargetMethod: IMethodSymbol method } operation)
{
string metadataName = method.GetFullMetadataName();
// If the invocation consists of invoking a static method that has a direct
// mapping to HLSL, rewrite the expression in the current invocation node.
// For instance: Math.Abs(expr) => abs(expr).
if (HlslKnownMethods.TryGetMappedName(metadataName, out string? mapping))
if (method.IsStatic)
{
// Allow specialized types to track the method invocation, if needed
TrackKnownMethodInvocation(metadataName);
string metadataName = method.GetFullMetadataName();
return updatedNode.WithExpression(ParseExpression(mapping!));
}
// Update the name if the target is a local function. The exact schema for the
// updated name is detailed in the override handling the local function statement.
if (method.MethodKind == MethodKind.LocalFunction)
{
var functionIdentifier = $"__{this.currentMethod!.Identifier.Text}__{method.Name}";
return updatedNode.WithExpression(ParseExpression(functionIdentifier));
}
// If the method is an external static method, import and rewrite it as well.
// This assumes that the target method is actually part of the same compilation.
// We need to check the declaring type to avoid rewriting static methods in the shader
// type as well, as they will be processed by the generator in a different path.
if (!SymbolEqualityComparer.Default.Equals(this.shaderType, method.ContainingType))
{
var methodIdentifier = method.GetFullMetadataName().ToHlslIdentifierName();
if (!this.staticMethods.ContainsKey(method))
// If the invocation consists of invoking a static method that has a direct
// mapping to HLSL, rewrite the expression in the current invocation node.
// For instance: Math.Abs(expr) => abs(expr).
if (HlslKnownMethods.TryGetMappedName(metadataName, out string? mapping))
{
if (method.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is not MethodDeclarationSyntax methodNode)
{
Diagnostics.Add(InvalidMethodCall, node, method);
// Allow specialized types to track the method invocation, if needed
TrackKnownMethodInvocation(metadataName);
return updatedNode;
}
ShaderSourceRewriter shaderSourceRewriter = new(SemanticModel, DiscoveredTypes, this.staticMethods, ConstantDefinitions, Diagnostics);
MethodDeclarationSyntax processedMethod = shaderSourceRewriter.Visit(methodNode)!.NormalizeWhitespace(eol: "\n").WithoutTrivia();
this.staticMethods.Add(method, processedMethod.WithIdentifier(Identifier(methodIdentifier)));
return updatedNode.WithExpression(ParseExpression(mapping!));
}
return updatedNode.WithExpression(ParseExpression(methodIdentifier));
// Update the name if the target is a local function. The exact schema for the
// updated name is detailed in the override handling the local function statement.
if (method.MethodKind == MethodKind.LocalFunction)
{
var functionIdentifier = $"__{this.currentMethod!.Identifier.Text}__{method.Name}";
return updatedNode.WithExpression(ParseExpression(functionIdentifier));
}
// If the method is an external static method, import and rewrite it as well.
// This assumes that the target method is actually part of the same compilation.
// We need to check the declaring type to avoid rewriting static methods in the shader
// type as well, as they will be processed by the generator in a different path.
if (!SymbolEqualityComparer.Default.Equals(this.shaderType, method.ContainingType))
{
var methodIdentifier = method.GetFullMetadataName().ToHlslIdentifierName();
if (!this.staticMethods.ContainsKey(method))
{
if (method.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is not MethodDeclarationSyntax methodNode)
{
Diagnostics.Add(InvalidMethodCall, node, method);
return updatedNode;
}
ShaderSourceRewriter shaderSourceRewriter = new(SemanticModel, DiscoveredTypes, this.staticMethods, ConstantDefinitions, Diagnostics);
MethodDeclarationSyntax processedMethod = shaderSourceRewriter.Visit(methodNode)!.NormalizeWhitespace(eol: "\n").WithoutTrivia();
this.staticMethods.Add(method, processedMethod.WithIdentifier(Identifier(methodIdentifier)));
}
return updatedNode.WithExpression(ParseExpression(methodIdentifier));
}
}
else
{
string metadataName = method.GetFullMetadataName(includeParameters: true);
if (HlslKnownMethods.TryGetMappedResourceSamplerAccessType(metadataName, out string? mapping))
{
// Get the syntax for the argument syntax transformation (adding the vector type constructor if needed)
ArgumentSyntax coordinateSyntax = mapping switch
{
not null => Argument(InvocationExpression(IdentifierName(mapping!), ArgumentList(updatedNode.ArgumentList.Arguments))),
null => updatedNode.ArgumentList.Arguments[0]
};
// Rewrite texture resource sampled accesses, if needed
return RewriteSampledTextureAccess(operation, updatedNode.Expression, coordinateSyntax);
}
}
}
@@ -423,6 +441,17 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
return updatedNode;
}
/// <summary>
/// Rewrites a sampled texture access.
/// </summary>
/// <param name="operation">The <see cref="IInvocationOperation"/> instance for the sampled texture access.</param>
/// <param name="expression">The input <see cref="ExpressionSyntax"/> instance for the node to rewrite.</param>
/// <param name="arguments">The input <see cref="ArgumentSyntax"/> with the updated arguments for the expression to rewrite.</param>
/// <returns>A <see cref="SyntaxNode"/> representing the rewritten sampled texture access.</returns>
private partial SyntaxNode RewriteSampledTextureAccess(IInvocationOperation operation, ExpressionSyntax expression, ArgumentSyntax arguments);
/// <summary>
/// Tracks a property access to a known HLSL property.
/// </summary>
+4 -15
ファイルの表示
@@ -19,17 +19,6 @@ internal static class ISymbolExtensions
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
miscellaneousOptions: SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers);
/// <summary>
/// A custom <see cref="SymbolDisplayFormat"/> instance with fully qualified style, without global:: and parameters.
/// </summary>
private static readonly SymbolDisplayFormat FullyQualifiedWithoutGlobalAndParametersFormat = new(
globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted,
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
miscellaneousOptions: SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers,
memberOptions: SymbolDisplayMemberOptions.IncludeContainingType,
parameterOptions: SymbolDisplayParameterOptions.None);
/// <summary>
/// Gets the fully qualified name for a given symbol.
/// </summary>
@@ -87,12 +76,12 @@ internal static class ISymbolExtensions
{
if (includeParameters)
{
var parameters = string.Join(", ", symbol.Parameters.Select(static p => ((INamedTypeSymbol)p.Type).GetFullMetadataName()));
string parameters = string.Join(", ", symbol.Parameters.Select(static p => ((INamedTypeSymbol)p.Type).GetFullMetadataName()));
return $"{symbol.ToDisplayString(FullyQualifiedWithoutGlobalAndParametersFormat)}({parameters})";
return $"{symbol.ContainingType.GetFullMetadataName()}.{symbol.Name}({parameters})";
}
return symbol.ToDisplayString(FullyQualifiedWithoutGlobalAndParametersFormat);
return $"{symbol.ContainingType.GetFullMetadataName()}.{symbol.Name}";
}
/// <summary>
@@ -106,7 +95,7 @@ internal static class ISymbolExtensions
if (symbol.IsIndexer)
{
var parameters = string.Join(", ", symbol.Parameters.Select(static p => ((INamedTypeSymbol)p.Type).GetFullMetadataName()));
string parameters = string.Join(", ", symbol.Parameters.Select(static p => ((INamedTypeSymbol)p.Type).GetFullMetadataName()));
return $"{declaringTypeName}.this[{parameters}]";
}
+27
ファイルの表示
@@ -0,0 +1,27 @@
using System.Collections.Generic;
namespace ComputeSharp.SourceGeneration.Mappings;
/// <inheritdoc/>
partial class HlslKnownMethods
{
/// <inheritdoc/>
private static partial IReadOnlyDictionary<string, string?> BuildKnownResourceSamplers()
{
return new Dictionary<string, string?>
{
[$"ComputeSharp.ReadOnlyTexture2D`2.Sample({typeof(float).FullName}, {typeof(float).FullName})"] = "float2",
[$"ComputeSharp.ReadOnlyTexture2D`2.Sample({typeof(Float2).FullName})"] = null,
[$"ComputeSharp.IReadOnlyTexture2D`1.Sample({typeof(float).FullName}, {typeof(float).FullName})"] = "float2",
[$"ComputeSharp.IReadOnlyTexture2D`1.Sample({typeof(Float2).FullName})"] = null,
[$"ComputeSharp.IReadOnlyNormalizedTexture2D`1.Sample({typeof(float).FullName}, {typeof(float).FullName})"] = "float2",
[$"ComputeSharp.IReadOnlyNormalizedTexture2D`1.Sample({typeof(Float2).FullName})"] = null,
[$"ComputeSharp.ReadOnlyTexture3D`2.Sample({typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName})"] = "float3",
[$"ComputeSharp.ReadOnlyTexture3D`2.Sample({typeof(Float3).FullName})"] = null,
[$"ComputeSharp.IReadOnlyTexture3D`1.Sample({typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName})"] = "float3",
[$"ComputeSharp.IReadOnlyTexture3D`1.Sample({typeof(Float3).FullName})"] = null,
[$"ComputeSharp.IReadOnlyNormalizedTexture3D`1.Sample({typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName})"] = "float3",
[$"ComputeSharp.IReadOnlyNormalizedTexture3D`1.Sample({typeof(Float3).FullName})"] = null
};
}
}
-20
ファイルの表示
@@ -32,26 +32,6 @@ partial class HlslKnownProperties
};
}
/// <inheritdoc/>
private static partial IReadOnlyDictionary<string, string?> BuildKnownResourceSamplers()
{
return 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,
[$"ComputeSharp.IReadOnlyNormalizedTexture2D`1.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2",
[$"ComputeSharp.IReadOnlyNormalizedTexture2D`1.this[{typeof(Float2).FullName}]"] = null,
[$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3",
[$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(Float3).FullName}]"] = null,
[$"ComputeSharp.IReadOnlyTexture3D`1.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3",
[$"ComputeSharp.IReadOnlyTexture3D`1.this[{typeof(Float3).FullName}]"] = null,
[$"ComputeSharp.IReadOnlyNormalizedTexture3D`1.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3",
[$"ComputeSharp.IReadOnlyNormalizedTexture3D`1.this[{typeof(Float3).FullName}]"] = null
};
}
/// <inheritdoc/>
private static partial IReadOnlyDictionary<string, (int Rank, int Axis)> BuildKnownSizeAccessors()
{
-42
ファイルの表示
@@ -1,42 +0,0 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Operations;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
namespace ComputeSharp.SourceGeneration.SyntaxRewriters;
/// <inheritdoc cref="HlslSourceRewriter"/>
partial class HlslSourceRewriter
{
/// <summary>
/// Gets whether or not the shader uses a texture sampler at least once.
/// </summary>
public bool IsSamplerUsed { get; private set; }
/// <inheritdoc/>
private partial SyntaxNode RewriteSampledTextureAccess(IPropertyReferenceOperation operation, ElementAccessExpressionSyntax node, string? mappedType)
{
IsSamplerUsed = true;
// Get the syntax for the argument syntax transformation as described above
ArgumentSyntax coordinateSyntax = mappedType switch
{
not null => Argument(InvocationExpression(IdentifierName(mappedType!), ArgumentList(node.ArgumentList.Arguments))),
null => node.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,
node.Expression,
IdentifierName("SampleLevel")))
.AddArgumentListArguments(
Argument(IdentifierName("__sampler")),
coordinateSyntax,
Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0))));
}
}
+22
ファイルの表示
@@ -1,9 +1,11 @@
using System;
using ComputeSharp.SourceGeneration.Extensions;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Operations;
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
namespace ComputeSharp.SourceGeneration.SyntaxRewriters;
@@ -25,6 +27,26 @@ partial class ShaderSourceRewriter
/// </summary>
public bool IsGridIdsUsed { get; set; }
/// <summary>
/// Gets whether or not the shader uses a texture sampler at least once.
/// </summary>
public bool IsSamplerUsed { get; private set; }
/// <inheritdoc/>
private partial SyntaxNode RewriteSampledTextureAccess(IInvocationOperation operation, ExpressionSyntax expression, ArgumentSyntax arguments)
{
IsSamplerUsed = true;
// Transform a method invocation syntax into a sampling call with the implicit static linear sampler.
// For instance: texture.Sample(uv) will be rewritten as texture.SampleLevel(__sampler, uv, 0).
return
InvocationExpression(((MemberAccessExpressionSyntax)expression).WithName(IdentifierName("SampleLevel")))
.AddArgumentListArguments(
Argument(IdentifierName("__sampler")),
arguments,
Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0))));
}
/// <inheritdoc/>
private partial void TrackKnownPropertyAccess(IMemberReferenceOperation operation, MemberAccessExpressionSyntax node, string mappedName)
{
+5 -5
ファイルの表示
@@ -13,17 +13,17 @@ internal static class MethodInfoExtensions
/// </summary>
/// <param name="method">The input <see cref="MethodInfo"/> instance.</param>
/// <returns>A fully qualified name for <paramref name="method"/>, including parameters.</returns>
public static string GetFullName(this MethodInfo method)
public static string GetFullyQualifiedName(this MethodInfo method)
{
var parameters = string.Join(", ", method.GetParameters().Select(static p => p.ParameterType.FullName));
string parameters = string.Join(", ", method.GetParameters().Select(static p => p.ParameterType.FullName));
if (method.IsGenericMethod)
{
var arguments = string.Join(", ", method.GetGenericArguments().Select(static t => t.FullName));
string arguments = string.Join(", ", method.GetGenericArguments().Select(static t => t.FullName));
return $"{method.DeclaringType!.FullName!.Replace('+', '.')}.{method.Name}<{arguments}>({parameters})";
return $"{method.DeclaringType!.FullName!}.{method.Name}<{arguments}>({parameters})";
}
return $"{method.DeclaringType!.FullName!.Replace('+', '.')}.{method.Name}({parameters})";
return $"{method.DeclaringType!.FullName!}.{method.Name}({parameters})";
}
}
+4 -4
ファイルの表示
@@ -34,17 +34,17 @@ public interface IReadOnlyNormalizedTexture2D<TPixel> : IGraphicsResource
ref readonly TPixel this[Int2 xy] { get; }
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture with linear sampling.
/// Retrieves 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>
ref readonly TPixel this[float u, float v] { get; }
ref readonly TPixel Sample(float u, float v);
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture with linear sampling.
/// Retrieves 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>
ref readonly TPixel this[Float2 uv] { get; }
ref readonly TPixel Sample(Float2 uv);
}
+4 -4
ファイルの表示
@@ -40,18 +40,18 @@ public interface IReadOnlyNormalizedTexture3D<TPixel> : IGraphicsResource
ref readonly TPixel this[Int3 xyz] { get; }
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture with linear sampling.
/// Retrieves 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>
/// <param name="w">The depthwise 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>
ref readonly TPixel this[float u, float v, float w] { get; }
ref readonly TPixel Sample(float u, float v, float w);
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture with linear sampling.
/// Retrieves a single <typeparamref name="TPixel"/> value from the current readonly texture with linear sampling.
/// </summary>
/// <param name="uvw">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>
ref readonly TPixel this[Float3 uvw] { get; }
ref readonly TPixel Sample(Float3 uvw);
}
+4 -4
ファイルの表示
@@ -34,17 +34,17 @@ public interface IReadOnlyTexture2D<T> : IGraphicsResource
ref readonly T this[Int2 xy] { get; }
/// <summary>
/// Gets a single <typeparamref name="T"/> value from the current readonly texture with linear sampling.
/// Retrieves a single <typeparamref name="T"/> 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>
ref readonly T this[float u, float v] { get; }
ref readonly T Sample(float u, float v);
/// <summary>
/// Gets a single <typeparamref name="T"/> value from the current readonly texture with linear sampling.
/// Retrieves a single <typeparamref name="T"/> 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>
ref readonly T this[Float2 uv] { get; }
ref readonly T Sample(Float2 uv);
}
+4 -4
ファイルの表示
@@ -40,18 +40,18 @@ public interface IReadOnlyTexture3D<T> : IGraphicsResource
ref readonly T this[Int3 xyz] { get; }
/// <summary>
/// Gets a single <typeparamref name="T"/> value from the current readonly texture with linear sampling.
/// Retrieves a single <typeparamref name="T"/> 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>
/// <param name="w">The depthwise 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>
ref readonly T this[float u, float v, float w] { get; }
ref readonly T Sample(float u, float v, float w);
/// <summary>
/// Gets a single <typeparamref name="T"/> value from the current readonly texture with linear sampling.
/// Retrieves a single <typeparamref name="T"/> value from the current readonly texture with linear sampling.
/// </summary>
/// <param name="uvw">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>
ref readonly T this[Float3 uvw] { get; }
ref readonly T Sample(Float3 uvw);
}
+2 -2
ファイルの表示
@@ -37,10 +37,10 @@ public sealed class ReadOnlyTexture2D<T, TPixel> : Texture2D<T>, IReadOnlyNormal
public ref readonly TPixel this[Int2 xy] => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture2D<T,TPixel>)}[{typeof(Int2)}]");
/// <inheritdoc/>
public ref readonly TPixel this[float u, float v] => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture2D<T, TPixel>)}[{typeof(float)}, {typeof(float)}]");
public ref readonly TPixel Sample(float u, float v) => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture2D<T, TPixel>)}.{nameof(Sample)}({typeof(float)}, {typeof(float)})");
/// <inheritdoc/>
public ref readonly TPixel this[Float2 uv] => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture2D<T, TPixel>)}[{typeof(Float2)}]");
public ref readonly TPixel Sample(Float2 uv) => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture2D<T, TPixel>)}.{nameof(Sample)}({typeof(Float2)})");
/// <inheritdoc/>
public override string ToString()
+2 -2
ファイルの表示
@@ -38,10 +38,10 @@ public sealed class ReadOnlyTexture3D<T, TPixel> : Texture3D<T>, IReadOnlyNormal
public ref readonly TPixel this[Int3 xyz] => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture3D<T, TPixel>)}[{typeof(Int3)}]");
/// <inheritdoc/>
public ref readonly TPixel this[float u, float v, float w] => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture3D<T, TPixel>)}[{typeof(float)}, {typeof(float)}, {typeof(float)}]");
public ref readonly TPixel Sample(float u, float v, float w) => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture3D<T, TPixel>)}.{nameof(Sample)}({typeof(float)}, {typeof(float)}, {typeof(float)})");
/// <inheritdoc/>
public ref readonly TPixel this[Float3 uvw] => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture3D<T, TPixel>)}[{typeof(Float3)}]");
public ref readonly TPixel Sample(Float3 uvw) => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture3D<T, TPixel>)}.{nameof(Sample)}({typeof(Float3)})");
/// <inheritdoc/>
public override string ToString()
+2 -2
ファイルの表示
@@ -95,10 +95,10 @@ partial class ReadWriteTexture2D<T, TPixel>
public ref readonly TPixel this[Int2 xy] => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture2D<T, TPixel>.ReadOnly)}[{typeof(Int2)}]");
/// <inheritdoc/>
public ref readonly TPixel this[float u, float v] => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture2D<T, TPixel>.ReadOnly)}[{typeof(float)}, {typeof(float)}]");
public ref readonly TPixel Sample(float u, float v) => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture2D<T, TPixel>.ReadOnly)}.{nameof(Sample)}({typeof(float)}, {typeof(float)})");
/// <inheritdoc/>
public ref readonly TPixel this[Float2 uv] => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture2D<T, TPixel>.ReadOnly)}[{typeof(Float2)}]");
public ref readonly TPixel Sample(Float2 uv) => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture2D<T, TPixel>.ReadOnly)}.{nameof(Sample)}({typeof(Float2)})");
/// <inheritdoc/>
public int Width => this.owner.Width;
+2 -2
ファイルの表示
@@ -95,10 +95,10 @@ partial class ReadWriteTexture2D<T>
public ref readonly T this[Int2 xy] => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture2D<T>.ReadOnly)}[{typeof(Int2)}]");
/// <inheritdoc/>
public ref readonly T this[float u, float v] => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture2D<T>.ReadOnly)}[{typeof(float)}, {typeof(float)}]");
public ref readonly T Sample(float u, float v) => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture2D<T>.ReadOnly)}.{nameof(Sample)}({typeof(float)}, {typeof(float)})");
/// <inheritdoc/>
public ref readonly T this[Float2 uv] => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture2D<T>.ReadOnly)}[{typeof(Float2)}]");
public ref readonly T Sample(Float2 uv) => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture2D<T>.ReadOnly)}.{nameof(Sample)}({typeof(Float2)})");
/// <inheritdoc/>
public int Width => this.owner.Width;
+2 -2
ファイルの表示
@@ -92,10 +92,10 @@ partial class ReadWriteTexture3D<T, TPixel>
public ref readonly TPixel this[Int3 xyz] => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture3D<T, TPixel>.ReadOnly)}[{typeof(Int3)}]");
/// <inheritdoc/>
public ref readonly TPixel this[float u, float v, float w] => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture3D<T, TPixel>.ReadOnly)}[{typeof(float)}, {typeof(float)}, {typeof(float)}]");
public ref readonly TPixel Sample(float u, float v, float w) => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture3D<T, TPixel>.ReadOnly)}.{nameof(Sample)}({typeof(float)}, {typeof(float)}, {typeof(float)})");
/// <inheritdoc/>
public ref readonly TPixel this[Float3 uvw] => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture3D<T, TPixel>.ReadOnly)}[{typeof(Float3)}]");
public ref readonly TPixel Sample(Float3 uvw) => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture3D<T, TPixel>.ReadOnly)}.{nameof(Sample)}({typeof(Float3)})");
/// <inheritdoc/>
public int Width => this.owner.Width;
+2 -2
ファイルの表示
@@ -92,10 +92,10 @@ partial class ReadWriteTexture3D<T>
public ref readonly T this[Int3 xyz] => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture3D<T>.ReadOnly)}[{typeof(Int3)}]");
/// <inheritdoc/>
public ref readonly T this[float u, float v, float w] => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture3D<T>.ReadOnly)}[{typeof(float)}, {typeof(float)}, {typeof(float)}]");
public ref readonly T Sample(float u, float v, float w) => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture3D<T>.ReadOnly)}.{nameof(Sample)}({typeof(float)}, {typeof(float)}, {typeof(float)})");
/// <inheritdoc/>
public ref readonly T this[Float3 uvw] => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture3D<T>.ReadOnly)}[{typeof(Float3)}]");
public ref readonly T Sample(Float3 uvw) => throw new InvalidExecutionContextException($"{typeof(ReadWriteTexture3D<T>.ReadOnly)}.{nameof(Sample)}({typeof(Float3)})");
/// <inheritdoc/>
public int Width => this.owner.Width;
+3 -3
ファイルの表示
@@ -226,11 +226,11 @@ public partial class D2D1PixelShaderTests
public Float4 Execute()
{
float4 pixel1 = myTexture1[0];
float4 pixel2 = myTexture1[0.4f];
float4 pixel2 = myTexture1.Sample(0.4f);
float4 pixel3 = myTexture2[0, 1];
float4 pixel4 = myTexture2[0.4f, 0.3f];
float4 pixel4 = myTexture2.Sample(0.4f, 0.3f);
float4 pixel5 = myTexture3[0, 1, 2];
float4 pixel6 = myTexture3[0.4f, 0.5f, 0.6f];
float4 pixel6 = myTexture3.Sample(0.4f, 0.5f, 0.6f);
return 0;
}
+4 -4
ファイルの表示
@@ -1288,7 +1288,7 @@ public partial class ComputeContextTests
/// <inheritdoc/>
public float4 Execute()
{
return source[ThreadIds.Normalized.XY];
return source.Sample(ThreadIds.Normalized.XY);
}
}
@@ -1301,7 +1301,7 @@ public partial class ComputeContextTests
/// <inheritdoc/>
public void Execute()
{
destination[ThreadIds.XYZ] = source[ThreadIds.Normalized.XYZ];
destination[ThreadIds.XYZ] = source.Sample(ThreadIds.Normalized.XYZ);
}
}
@@ -1313,7 +1313,7 @@ public partial class ComputeContextTests
/// <inheritdoc/>
public float4 Execute()
{
return source[ThreadIds.Normalized.XY];
return source.Sample(ThreadIds.Normalized.XY);
}
}
@@ -1326,7 +1326,7 @@ public partial class ComputeContextTests
/// <inheritdoc/>
public void Execute()
{
destination[ThreadIds.XYZ] = source[ThreadIds.Normalized.XYZ];
destination[ThreadIds.XYZ] = source.Sample(ThreadIds.Normalized.XYZ);
}
}
+1 -1
ファイルの表示
@@ -113,7 +113,7 @@ internal readonly partial struct ContouredLayers : IComputeShader
// Layer color. Based on the shade, layer number and smoothing factor.
private float3 GetColor(float2 p, float sh, float fi)
{
float3 tx = texture[p + Hash21(new float2(sh, fi))].XYZ;
float3 tx = texture.Sample(p + Hash21(new float2(sh, fi))).XYZ;
tx *= tx;
+2 -2
ファイルの表示
@@ -79,7 +79,7 @@ public partial class Texture2DTests
public void Execute()
{
destination[ThreadIds.XY] = source[ThreadIds.Normalized.XY];
destination[ThreadIds.XY] = source.Sample(ThreadIds.Normalized.XY);
}
}
@@ -111,7 +111,7 @@ public partial class Texture2DTests
public float4 Execute()
{
return texture[ThreadIds.Normalized.XY];
return texture.Sample(ThreadIds.Normalized.XY);
}
}