Merge pull request #404 from Sergio0694/dev/editorconfig

Add .editorconfig file
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2022-10-15 10:39:01 -07:00
コミット 0e0830c045
913ファイル変更
+4343 -3285

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

+350
ファイルの表示
@@ -0,0 +1,350 @@
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true
# All files
[*]
#### Core EditorConfig Options ####
# Encoding
charset = utf-8
# Indentation and spacing
tab_width = 4
indent_size = 4
indent_style = space
# New line preferences
insert_final_newline = false
trim_trailing_whitespace = true
#### Build files ####
# Solution files
[*.{sln,slnx}]
tab_width = 4
indent_size = 4
indent_style = tab
# Configuration files
[*.{json,xml,yml,config,runsettings}]
indent_size = 2
# MSBuild files
[*.{slnf,props,targets,projitems,csproj,shproj}]
indent_size = 2
#### Source files ####
# Markdown files
[*.md]
indent_size = 2
insert_final_newline = true
# XAML files
[*.xaml]
indent_size = 4
# C# files
[*.cs]
#### .NET Coding Conventions ####
# this. and Me. preferences
dotnet_style_qualification_for_event = false:warning
dotnet_style_qualification_for_field = true:warning
dotnet_style_qualification_for_method = false:warning
dotnet_style_qualification_for_property = false:warning
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
dotnet_style_predefined_type_for_member_access = true:warning
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:warning
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning
# Modifier preferences (set to silent until https://github.com/dotnet/roslyn/issues/52904 is resolved)
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
# Code block preferences
dotnet_style_allow_multiple_blank_lines_experimental = false:warning
dotnet_style_allow_statement_immediately_after_block_experimental = false:warning
# Expression-level preferences
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_inlined_variable_declaration = true:warning
csharp_style_throw_expression = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_object_initializer = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:warning
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
csharp_style_implicit_object_creation_when_type_is_apparent = true:warning
# Field preferences
dotnet_style_readonly_field = true:warning
#### C# Coding Conventions ####
# var preferences
csharp_style_var_elsewhere = false:warning
csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = false:warning
# Expression-bodied members
csharp_style_expression_bodied_accessors = when_on_single_line:warning
csharp_style_expression_bodied_constructors = false:warning
csharp_style_expression_bodied_indexers = when_on_single_line:warning
csharp_style_expression_bodied_lambdas = when_on_single_line:warning
csharp_style_expression_bodied_methods = false:warning
csharp_style_expression_bodied_operators = when_on_single_line:warning
csharp_style_expression_bodied_properties = when_on_single_line:warning
# Pattern matching preferences
csharp_style_prefer_pattern_matching = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
# Null-checking preferences
csharp_style_conditional_delegate_call = true:suggestion
# Modifier preferences
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
# Code-block preferences
csharp_prefer_braces = true:suggestion
csharp_using_directive_placement = outside_namespace:warning
csharp_style_namespace_declarations = file_scoped:warning
csharp_style_unused_value_assignment_preference = discard_variable:warning
csharp_style_unused_value_expression_statement_preference = discard_variable:warning
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:warning
# Expression-level preferences
csharp_prefer_simple_default_expression = true:suggestion
csharp_prefer_static_local_function = true:warning
csharp_style_pattern_local_over_anonymous_function = true:warning
#### C# Formatting Rules ####
# New line preferences
csharp_new_line_before_catch = true
csharp_new_line_before_else = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = all
csharp_new_line_between_query_expression_clauses = true
# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = false
csharp_indent_labels = no_change
csharp_indent_switch_labels = true
# Space preferences
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false
# Wrapping preferences
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
# Naming Symbols
# constant_fields - Define constant fields
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.required_modifiers = const
# static_readonly_fields - Define all static readonly fields
dotnet_naming_symbols.static_readonly_fields.applicable_accessibilities = *
dotnet_naming_symbols.static_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.static_readonly_fields.required_modifiers = static, readonly
# non_private_fields - Define all fields that are not private
dotnet_naming_symbols.non_private_fields.applicable_accessibilities = public, internal, protected, protected_internal, private_protected
dotnet_naming_symbols.non_private_fields.applicable_kinds = field
# private_fields - Define all private fields
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
dotnet_naming_symbols.private_fields.applicable_kinds = field
# public_symbols - Define any public symbol
dotnet_naming_symbols.public_symbols.applicable_accessibilities = *
dotnet_naming_symbols.public_symbols.applicable_kinds = method, property, event, delegate, class, struct, enum, delegate
# parameters - Defines any parameter
dotnet_naming_symbols.parameters.applicable_accessibilities = *
dotnet_naming_symbols.parameters.applicable_kinds = parameter
# interface_types - Defines interfaces
dotnet_naming_symbols.interface_types.applicable_accessibilities = *
dotnet_naming_symbols.interface_types.applicable_kinds = interface
# Naming Styles
# camel_case - Define the camelCase style
dotnet_naming_style.camel_case.capitalization = camel_case
# pascal_case - Define the PascalCase style
dotnet_naming_style.pascal_case.capitalization = pascal_case
# prefix_interface_interface_with_i - Interfaces must be PascalCase and the first character of an interface must be an 'I'
dotnet_naming_style.prefix_interface_interface_with_i.capitalization = pascal_case
dotnet_naming_style.prefix_interface_interface_with_i.required_prefix = I
# Naming Rules
# Async methods should have the "Async" suffix (disabled because it can't currently exclude async void methods)
dotnet_naming_rule.async_methods_end_in_async.severity = none
dotnet_naming_rule.async_methods_end_in_async.symbols = any_async_methods
dotnet_naming_rule.async_methods_end_in_async.style = end_in_async
dotnet_naming_symbols.any_async_methods.applicable_kinds = method
dotnet_naming_symbols.any_async_methods.applicable_accessibilities = *
dotnet_naming_symbols.any_async_methods.required_modifiers = async
dotnet_naming_style.end_in_async.required_suffix = Async
dotnet_naming_style.end_in_async.capitalization = pascal_case
# Private fields must be camelCase
dotnet_naming_rule.private_fields_must_be_pascal_case.severity = warning
dotnet_naming_rule.private_fields_must_be_pascal_case.symbols = private_fields
dotnet_naming_rule.private_fields_must_be_pascal_case.style = camel_case
# Constant fields must be PascalCase
dotnet_naming_rule.constant_fields_must_be_pascal_case.severity = warning
dotnet_naming_rule.constant_fields_must_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_must_be_pascal_case.style = pascal_case
# Static readonly fields must be PascalCase
dotnet_naming_rule.static_readonly_fields_must_be_pascal_case.severity = warning
dotnet_naming_rule.static_readonly_fields_must_be_pascal_case.symbols = static_readonly_fields
dotnet_naming_rule.static_readonly_fields_must_be_pascal_case.style = pascal_case
# Non private fields must be PascalCase
dotnet_naming_rule.non_private_fields_must_be_pascal_case.severity = warning
dotnet_naming_rule.non_private_fields_must_be_pascal_case.symbols = non_private_fields
dotnet_naming_rule.non_private_fields_must_be_pascal_case.style = pascal_case
# Public symbols must be capitalized
dotnet_naming_rule.public_symbols_must_be_capitalized.severity = warning
dotnet_naming_rule.public_symbols_must_be_capitalized.symbols = public_symbols
dotnet_naming_rule.public_symbols_must_be_capitalized.style = pascal_case
# Parameters must be camelCase (ignored because some use PascalCase to match Win32 parameter names)
dotnet_naming_rule.parameters_must_be_camel_case.severity = none
dotnet_naming_rule.parameters_must_be_camel_case.symbols = parameters
dotnet_naming_rule.parameters_must_be_camel_case.style = camel_case
# Interfaces must be PascalCase and start with an 'I'
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.severity = warning
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.symbols = interface_types
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.style = prefix_interface_interface_with_i
# .NET Code Analysis
dotnet_diagnostic.CA1001.severity = warning
dotnet_diagnostic.CA1009.severity = warning
dotnet_diagnostic.CA1016.severity = warning
dotnet_diagnostic.CA1033.severity = warning
dotnet_diagnostic.CA1049.severity = warning
dotnet_diagnostic.CA1060.severity = warning
dotnet_diagnostic.CA1061.severity = warning
dotnet_diagnostic.CA1063.severity = warning
dotnet_diagnostic.CA1065.severity = warning
dotnet_diagnostic.CA1301.severity = warning
dotnet_diagnostic.CA1400.severity = warning
dotnet_diagnostic.CA1401.severity = warning
dotnet_diagnostic.CA1403.severity = warning
dotnet_diagnostic.CA1404.severity = warning
dotnet_diagnostic.CA1405.severity = warning
dotnet_diagnostic.CA1410.severity = warning
dotnet_diagnostic.CA1415.severity = warning
dotnet_diagnostic.CA1821.severity = warning
dotnet_diagnostic.CA1900.severity = warning
dotnet_diagnostic.CA1901.severity = warning
dotnet_diagnostic.CA2002.severity = warning
dotnet_diagnostic.CA2100.severity = warning
dotnet_diagnostic.CA2101.severity = warning
dotnet_diagnostic.CA2108.severity = warning
dotnet_diagnostic.CA2111.severity = warning
dotnet_diagnostic.CA2112.severity = warning
dotnet_diagnostic.CA2114.severity = warning
dotnet_diagnostic.CA2116.severity = warning
dotnet_diagnostic.CA2117.severity = warning
dotnet_diagnostic.CA2122.severity = warning
dotnet_diagnostic.CA2123.severity = warning
dotnet_diagnostic.CA2124.severity = warning
dotnet_diagnostic.CA2126.severity = warning
dotnet_diagnostic.CA2131.severity = warning
dotnet_diagnostic.CA2132.severity = warning
dotnet_diagnostic.CA2133.severity = warning
dotnet_diagnostic.CA2134.severity = warning
dotnet_diagnostic.CA2137.severity = warning
dotnet_diagnostic.CA2138.severity = warning
dotnet_diagnostic.CA2140.severity = warning
dotnet_diagnostic.CA2141.severity = warning
dotnet_diagnostic.CA2146.severity = warning
dotnet_diagnostic.CA2147.severity = warning
dotnet_diagnostic.CA2149.severity = warning
dotnet_diagnostic.CA2200.severity = warning
dotnet_diagnostic.CA2202.severity = warning
dotnet_diagnostic.CA2207.severity = warning
dotnet_diagnostic.CA2212.severity = warning
dotnet_diagnostic.CA2213.severity = warning
dotnet_diagnostic.CA2214.severity = warning
dotnet_diagnostic.CA2216.severity = warning
dotnet_diagnostic.CA2220.severity = warning
dotnet_diagnostic.CA2229.severity = warning
dotnet_diagnostic.CA2231.severity = warning
dotnet_diagnostic.CA2232.severity = warning
dotnet_diagnostic.CA2235.severity = warning
dotnet_diagnostic.CA2236.severity = warning
dotnet_diagnostic.CA2237.severity = warning
dotnet_diagnostic.CA2238.severity = warning
dotnet_diagnostic.CA2240.severity = warning
dotnet_diagnostic.CA2241.severity = warning
dotnet_diagnostic.CA2242.severity = warning
## CodeStyle Code Analysis
dotnet_diagnostic.IDE0010.severity = none
dotnet_diagnostic.IDE0130.severity = none
dotnet_diagnostic.IDE0060.severity = none
dotnet_diagnostic.IDE1006.severity = none
dotnet_diagnostic.IDE0023.severity = none
dotnet_diagnostic.IDE0024.severity = none
dotnet_diagnostic.IDE0060.severity = none
dotnet_diagnostic.IDE0057.severity = none
dotnet_diagnostic.IDE0046.severity = none
dotnet_diagnostic.IDE0072.severity = none
dotnet_diagnostic.IDE0064.severity = none
dotnet_diagnostic.IDE0160.severity = none
dotnet_diagnostic.IDE0040.severity = none
dotnet_diagnostic.IDE0045.severity = none
dotnet_diagnostic.IDE0032.severity = none
dotnet_diagnostic.IDE0056.severity = none
dotnet_diagnostic.IDE0032.severity = none
dotnet_diagnostic.IDE0042.severity = none
dotnet_diagnostic.IDE0180.severity = none
dotnet_diagnostic.IDE0061.severity = none
dotnet_diagnostic.IDE0078.severity = none
dotnet_diagnostic.IDE0066.severity = none
+51
ファイルの表示
@@ -0,0 +1,51 @@
# Set default file-type attributes
# All file types
* text=auto
# Markups
*.md text=auto diff=markdown
*.mdx text=auto diff=markdown
# Solutions
*.sln text=auto eol=crlf
*.slnx text=auto
# Projects
*.*proj text=auto
*.tasks text=auto
*.props text=auto
*.targets text=auto
# Sources
*.cs text=auto diff=csharp
*.csx text=auto diff=csharp
*.fs text=auto diff=fsharp
*.resx text=auto
# Scripts
*.in text eol=lf
*.sh text eol=lf
*.bat text eol=crlf
*.cmd text eol=crlf
# Images
*.png binary
*.jpg binary
*.gif binary
# Keys
*.snk binary
*.pfx binary
*.cer binary
# Others
# Preserve Line endings in diff and patch files
*.diff -text
*.patch -text
# Exclude git meta files from exporting
.gitattributes export-ignore
.gitignore export-ignore
.gitkeep export-ignore
+1
ファイルの表示
@@ -19,6 +19,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Tests.Internal
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_SolutionItems", "_SolutionItems", "{1A9C4108-F61A-4ABE-B5CF-F524521EAE2D}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
Directory.Build.props = Directory.Build.props
src\Directory.Build.props = src\Directory.Build.props
+36 -4
ファイルの表示
@@ -3,13 +3,45 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable>
<Features>strict</Features>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<!--
Enable the latest warning wave, which shows additional warnings for invalid language features that are disabled by default.
For additional info, see https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/warning-waves.
-->
<AnalysisLevel>7</AnalysisLevel>
<!-- Import the global configs from the CodeStyle package (enables all IDExxxx warnings)-->
<AnalysisLevelStyle>7-all</AnalysisLevelStyle>
<!--
Enable the compiler strict mode (see https://www.meziantou.net/csharp-compiler-strict-mode.htm).
This (poorly documented) mode enables additional warnings for incorrect usages of some features.
For instance, this will warn when using the == operator to compare a struct with a null literal.
-->
<Features>strict</Features>
</PropertyGroup>
<PropertyGroup>
<!--
This ignores the following warning:
"MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the
processor architecture of the reference". It pops up because all samples are only targeting x64/Arm64.
-->
<NoWarn>$(NoWarn);MSB3270</NoWarn>
<!--
This ignores the following warning:
"CA1060: Move P/Invokes to NativeMethods class". The whole repository is full of P/Invoke-s everywhere.
See: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1060.
-->
<NoWarn>$(NoWarn);CA1060</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.4.0-2.final" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.4.0-2.final" PrivateAssets="all" />
</ItemGroup>
<!-- Centralized location for all generated artifacts -->
@@ -37,7 +69,7 @@
</PropertyGroup>
<!-- If the current branch and action match a release for NuGet, override the relative build properties -->
<PropertyGroup Condition="'$(GITHUB_EVENT_NAME)' == 'push' AND '$(GITHUB_REF_NAME)' != '' AND '$(IsBranchNameStartingWithRefPrefix)' == 'true'">
<PropertyGroup Condition="'$(GITHUB_EVENT_NAME)' == 'push' AND '$(GITHUB_REF_NAME)' != '' AND '$(IsBranchNameStartingWithRefPrefix)' == 'true'">
<IsCommitOnReleaseBranch>true</IsCommitOnReleaseBranch>
<ComputeSharpPackageVersionFromReleaseBranch>$([System.Text.RegularExpressions.Regex]::Match($(GITHUB_REF_NAME), $(ReleaseVersionParsingRegex)).Groups[1].Value)</ComputeSharpPackageVersionFromReleaseBranch>
<ComputeSharpPackageVersionSuffixFromReleaseBranch>$([System.Text.RegularExpressions.Regex]::Match($(GITHUB_REF_NAME), $(ReleaseVersionParsingRegex)).Groups[2].Value)</ComputeSharpPackageVersionSuffixFromReleaseBranch>
@@ -58,7 +90,7 @@
<RepositoryUrl>https://github.com/Sergio0694/ComputeSharp/</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<ProjectUrl>https://github.com/Sergio0694/ComputeSharp/</ProjectUrl>
<ProjectUrl>https://github.com/Sergio0694/ComputeSharp/</ProjectUrl>
<Authors>Sergio Pedri</Authors>
<Owners>Sergio Pedri</Owners>
<Company>Sergio Pedri</Company>
@@ -71,7 +103,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.1.1" PrivateAssets="all" />
</ItemGroup>
+40 -38
ファイルの表示
@@ -1,8 +1,10 @@
using System;
using System;
using System.Buffers;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
#pragma warning disable CA1063
namespace ComputeSharp.Benchmark.Blas;
/// <summary>
@@ -17,64 +19,64 @@ public class BlasBenchmark : IDisposable
private const int C = 128;
/// <summary>
/// The nummber of rows in the <see cref="X"/> matrix.
/// The nummber of rows in the <see cref="x"/> matrix.
/// </summary>
private const int N = 512;
/// <summary>
/// The number of columns in the <see cref="X"/> matrix (same as the number of rows in the <see cref="W"/> matrix)
/// The number of columns in the <see cref="x"/> matrix (same as the number of rows in the <see cref="w"/> matrix)
/// </summary>
private const int M = 512;
/// <summary>
/// The number of columns in the <see cref="W"/> matrix.
/// The number of columns in the <see cref="w"/> matrix.
/// </summary>
private const int P = 256;
/// <summary>
/// The input tensor.
/// </summary>
private float[]? X;
private float[]? x;
/// <summary>
/// The weights tensor.
/// </summary>
private float[]? W;
private float[]? w;
/// <summary>
/// The bias tensor.
/// </summary>
private float[]? B;
private float[]? b;
/// <summary>
/// The result tensor.
/// </summary>
private float[]? Y;
private float[]? y;
/// <summary>
/// The input tensor (GPU).
/// </summary>
private ReadOnlyBuffer<float>? BufferX;
private ReadOnlyBuffer<float>? bufferX;
/// <summary>
/// The weights tensor (GPU).
/// </summary>
private ReadOnlyBuffer<float>? BufferW;
private ReadOnlyBuffer<float>? bufferW;
/// <summary>
/// The bias tensor (GPU).
/// </summary>
private ReadOnlyBuffer<float>? BufferB;
private ReadOnlyBuffer<float>? bufferB;
/// <summary>
/// The result tensor (GPU).
/// </summary>
private ReadWriteBuffer<float>? BufferY;
private ReadWriteBuffer<float>? bufferY;
/// <summary>
/// A <see cref="System.Random"/> instance to initialize the tensors.
/// </summary>
private readonly Random Random = new Random();
private readonly Random random = new();
/// <summary>
/// Initial setup for a benchmarking session.
@@ -89,21 +91,21 @@ public class BlasBenchmark : IDisposable
foreach (ref float x in array.AsSpan())
{
x = (float)Random.NextDouble();
x = (float)this.random.NextDouble();
}
return array;
}
X = CreateRandomArray(C * N * M);
W = CreateRandomArray(M * P);
B = CreateRandomArray(P);
Y = CreateRandomArray(C * N * P);
this.x = CreateRandomArray(C * N * M);
this.w = CreateRandomArray(M * P);
this.b = CreateRandomArray(P);
this.y = CreateRandomArray(C * N * P);
BufferX = GraphicsDevice.GetDefault().AllocateReadOnlyBuffer(X);
BufferW = GraphicsDevice.GetDefault().AllocateReadOnlyBuffer(W);
BufferB = GraphicsDevice.GetDefault().AllocateReadOnlyBuffer(B);
BufferY = GraphicsDevice.GetDefault().AllocateReadWriteBuffer(Y);
this.bufferX = GraphicsDevice.GetDefault().AllocateReadOnlyBuffer(this.x);
this.bufferW = GraphicsDevice.GetDefault().AllocateReadOnlyBuffer(this.w);
this.bufferB = GraphicsDevice.GetDefault().AllocateReadOnlyBuffer(this.b);
this.bufferY = GraphicsDevice.GetDefault().AllocateReadWriteBuffer(this.y);
Cpu();
GpuWithNoTemporaryBuffers();
@@ -114,15 +116,15 @@ public class BlasBenchmark : IDisposable
[GlobalCleanup]
public void Dispose()
{
ArrayPool<float>.Shared.Return(X!);
ArrayPool<float>.Shared.Return(W!);
ArrayPool<float>.Shared.Return(B!);
ArrayPool<float>.Shared.Return(Y!);
ArrayPool<float>.Shared.Return(this.x!);
ArrayPool<float>.Shared.Return(this.w!);
ArrayPool<float>.Shared.Return(this.b!);
ArrayPool<float>.Shared.Return(this.y!);
BufferX!.Dispose();
BufferW!.Dispose();
BufferB!.Dispose();
BufferY!.Dispose();
this.bufferX!.Dispose();
this.bufferW!.Dispose();
this.bufferB!.Dispose();
this.bufferY!.Dispose();
}
/// <summary>
@@ -131,7 +133,7 @@ public class BlasBenchmark : IDisposable
[Benchmark(Baseline = true)]
public void Cpu()
{
BlasHelpers.FullyConnectedForwardCpu(C, N, M, P, X!, W!, B!, Y!);
BlasHelpers.FullyConnectedForwardCpu(C, N, M, P, this.x!, this.w!, this.b!, this.y!);
}
/// <summary>
@@ -140,7 +142,7 @@ public class BlasBenchmark : IDisposable
[Benchmark]
public void GpuWithNoTemporaryBuffers()
{
BlasHelpers.FullyConnectedForwardGpu(GraphicsDevice.GetDefault(), C, N, M, P, BufferX!, BufferW!, BufferB!, BufferY!);
BlasHelpers.FullyConnectedForwardGpu(GraphicsDevice.GetDefault(), C, N, M, P, this.bufferX!, this.bufferW!, this.bufferB!, this.bufferY!);
}
/// <summary>
@@ -149,13 +151,13 @@ public class BlasBenchmark : IDisposable
[Benchmark]
public void GpuWithTemporaryBuffers()
{
using ReadOnlyBuffer<float> x = GraphicsDevice.GetDefault().AllocateReadOnlyBuffer(X!);
using ReadOnlyBuffer<float> w = GraphicsDevice.GetDefault().AllocateReadOnlyBuffer(W!);
using ReadOnlyBuffer<float> b = GraphicsDevice.GetDefault().AllocateReadOnlyBuffer(B!);
using ReadWriteBuffer<float> y = GraphicsDevice.GetDefault().AllocateReadWriteBuffer<float>(Y!.Length);
using ReadOnlyBuffer<float> x = GraphicsDevice.GetDefault().AllocateReadOnlyBuffer(this.x!);
using ReadOnlyBuffer<float> w = GraphicsDevice.GetDefault().AllocateReadOnlyBuffer(this.w!);
using ReadOnlyBuffer<float> b = GraphicsDevice.GetDefault().AllocateReadOnlyBuffer(this.b!);
using ReadWriteBuffer<float> y = GraphicsDevice.GetDefault().AllocateReadWriteBuffer<float>(this.y!.Length);
BlasHelpers.FullyConnectedForwardGpu(GraphicsDevice.GetDefault(), C, N, M, P, x, w, b, y);
y.CopyTo(Y);
y.CopyTo(this.y);
}
}
}
+15 -15
ファイルの表示
@@ -1,4 +1,4 @@
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace ComputeSharp.Benchmark.Blas;
@@ -39,7 +39,7 @@ internal static partial class BlasHelpers
for (int k = 0; k < m; k++)
{
result += Unsafe.Add(ref rx, x_offset + k) * Unsafe.Add(ref rw, k * p + j);
result += Unsafe.Add(ref rx, x_offset + k) * Unsafe.Add(ref rw, (k * p) + j);
}
Unsafe.Add(ref ry, y_offset + j) = result + Unsafe.Add(ref rb, j);
@@ -47,7 +47,7 @@ internal static partial class BlasHelpers
}
}
Parallel.For(0, c, Kernel);
_ = Parallel.For(0, c, Kernel);
}
/// <summary>
@@ -83,26 +83,26 @@ internal static partial class BlasHelpers
[AutoConstructor]
public readonly partial struct FullyConnectedForwardKernel : IComputeShader
{
public readonly int n;
public readonly int m;
public readonly int p;
public readonly ReadOnlyBuffer<float> x;
public readonly ReadOnlyBuffer<float> w;
public readonly ReadOnlyBuffer<float> b;
public readonly ReadWriteBuffer<float> y;
private readonly int n;
private readonly int m;
private readonly int p;
private readonly ReadOnlyBuffer<float> x;
private readonly ReadOnlyBuffer<float> w;
private readonly ReadOnlyBuffer<float> b;
private readonly ReadWriteBuffer<float> y;
/// <inheritdoc/>
public void Execute()
{
int x_offset = ThreadIds.X * n * p + ThreadIds.Y * m;
int x_offset = (ThreadIds.X * this.n * this.p) + (ThreadIds.Y * this.m);
float result = 0f;
for (int k = 0; k < m; k++)
for (int k = 0; k < this.m; k++)
{
result += x[x_offset + k] * w[k * p + ThreadIds.Z];
result += this.x[x_offset + k] * this.w[(k * this.p) + ThreadIds.Z];
}
y[ThreadIds.X * n * p + ThreadIds.Y * p + ThreadIds.Z] = result + b[ThreadIds.Z];
this.y[(ThreadIds.X * this.n * this.p) + (ThreadIds.Y * this.p) + ThreadIds.Z] = result + this.b[ThreadIds.Z];
}
}
}
}
+23 -21
ファイルの表示
@@ -1,8 +1,10 @@
using System;
using System;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
#pragma warning disable CA1063
namespace ComputeSharp.Benchmark.Blas;
/// <summary>
@@ -15,7 +17,7 @@ public partial class DispatchingBenchmark : IDisposable
/// <summary>
/// The test buffer.
/// </summary>
private ReadWriteBuffer<float>? Buffer;
private ReadWriteBuffer<float>? buffer;
/// <summary>
/// Initial setup for a benchmarking session.
@@ -23,14 +25,14 @@ public partial class DispatchingBenchmark : IDisposable
[GlobalSetup]
public void Setup()
{
Buffer = GraphicsDevice.GetDefault().AllocateReadWriteBuffer<float>(128);
this.buffer = GraphicsDevice.GetDefault().AllocateReadWriteBuffer<float>(128);
}
/// <inheritdoc/>
[GlobalCleanup]
public void Dispose()
{
Buffer!.Dispose();
this.buffer!.Dispose();
}
/// <summary>
@@ -40,7 +42,7 @@ public partial class DispatchingBenchmark : IDisposable
[BenchmarkCategory("SINGLE")]
public void Compute_Single()
{
GraphicsDevice.GetDefault().For(64, new TestShader(Buffer!));
GraphicsDevice.GetDefault().For(64, new TestShader(this.buffer!));
}
/// <summary>
@@ -50,9 +52,9 @@ public partial class DispatchingBenchmark : IDisposable
[BenchmarkCategory("SINGLE")]
public void Compute_Single_WithContext()
{
using var context = GraphicsDevice.GetDefault().CreateComputeContext();
using ComputeContext context = GraphicsDevice.GetDefault().CreateComputeContext();
context.For(64, new TestShader(Buffer!));
context.For(64, new TestShader(this.buffer!));
}
/// <summary>
@@ -62,9 +64,9 @@ public partial class DispatchingBenchmark : IDisposable
[BenchmarkCategory("SINGLE")]
public async Task Compute_Single_WithContext_Async()
{
await using var context = GraphicsDevice.GetDefault().CreateComputeContext();
await using ComputeContext context = GraphicsDevice.GetDefault().CreateComputeContext();
context.For(64, new TestShader(Buffer!));
context.For(64, new TestShader(this.buffer!));
}
/// <summary>
@@ -74,8 +76,8 @@ public partial class DispatchingBenchmark : IDisposable
[BenchmarkCategory("MULTIPLE")]
public void Compute_Multiple()
{
GraphicsDevice.GetDefault().For(64, new TestShader(Buffer!));
GraphicsDevice.GetDefault().For(64, new TestShader(Buffer!));
GraphicsDevice.GetDefault().For(64, new TestShader(this.buffer!));
GraphicsDevice.GetDefault().For(64, new TestShader(this.buffer!));
}
/// <summary>
@@ -85,11 +87,11 @@ public partial class DispatchingBenchmark : IDisposable
[BenchmarkCategory("MULTIPLE")]
public void Compute_Multiple_WithContext()
{
using var context = GraphicsDevice.GetDefault().CreateComputeContext();
using ComputeContext context = GraphicsDevice.GetDefault().CreateComputeContext();
context.For(64, new TestShader(Buffer!));
context.Barrier(Buffer!);
context.For(64, new TestShader(Buffer!));
context.For(64, new TestShader(this.buffer!));
context.Barrier(this.buffer!);
context.For(64, new TestShader(this.buffer!));
}
/// <summary>
@@ -99,21 +101,21 @@ public partial class DispatchingBenchmark : IDisposable
[BenchmarkCategory("MULTIPLE")]
public async Task Compute_Multiple_WithContext_Async()
{
await using var context = GraphicsDevice.GetDefault().CreateComputeContext();
await using ComputeContext context = GraphicsDevice.GetDefault().CreateComputeContext();
context.For(64, new TestShader(Buffer!));
context.Barrier(Buffer!);
context.For(64, new TestShader(Buffer!));
context.For(64, new TestShader(this.buffer!));
context.Barrier(this.buffer!);
context.For(64, new TestShader(this.buffer!));
}
[AutoConstructor]
internal readonly partial struct TestShader : IComputeShader
{
public readonly ReadWriteBuffer<float> buffer;
private readonly ReadWriteBuffer<float> buffer;
/// <inheritdoc/>
public void Execute()
{
}
}
}
}
+4 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Reflection;
using BenchmarkDotNet.Attributes;
@@ -10,6 +10,8 @@ using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Convolution;
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
#pragma warning disable CA1063
namespace ComputeSharp.Benchmark.Imaging;
/// <summary>
@@ -89,4 +91,4 @@ public class ImagingBenchmark : IDisposable
{
this.image!.Mutate(c => c.ApplyProcessor(new HlslGaussianBlurProcessor(80)));
}
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using BenchmarkDotNet.Running;
// =================
@@ -8,4 +8,4 @@ using BenchmarkDotNet.Running;
// it as the startup project for the solution and run it without the debugger
// (CTRL + F5), or compile it and then go to its bin\Release\net6.0 folder,
// open a cmd prompt and run "dotnet ComputeSharp.Benchmark.dll".
BenchmarkSwitcher.FromAssembly(Assembly.GetExecutingAssembly()).Run(args);
BenchmarkSwitcher.FromAssembly(Assembly.GetExecutingAssembly()).Run(args);
+3 -3
ファイルの表示
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System.Runtime.CompilerServices;
@@ -41,5 +41,5 @@ internal readonly struct Complex64
/// <param name="scalar">The <see cref="float"/> scalar to use to multiply the <see cref="Complex64"/> value.</param>
/// <returns>The <see cref="Complex64"/> result.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Complex64 operator *(Complex64 value, float scalar) => new Complex64(value.Real * scalar, value.Imaginary * scalar);
}
public static Complex64 operator *(Complex64 value, float scalar) => new(value.Real * scalar, value.Imaginary * scalar);
}
+3 -1
ファイルの表示
@@ -1,9 +1,11 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using System.Runtime.CompilerServices;
#pragma warning disable IDE0022
namespace SixLabors.ImageSharp;
/// <summary>
+3 -3
ファイルの表示
@@ -1,4 +1,4 @@
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using CommunityToolkit.Diagnostics;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
@@ -77,8 +77,8 @@ public sealed partial class HlslBokehBlurProcessor : IImageProcessor
ThrowHelper.ThrowInvalidOperationException("This processor only supports the RGBA32 pixel format.");
}
var processor = new Implementation(this, configuration, Unsafe.As<Image<ImageSharpRgba32>>(source), sourceRectangle);
Implementation processor = new(this, configuration, Unsafe.As<Image<ImageSharpRgba32>>(source), sourceRectangle);
return Unsafe.As<IImageProcessor<TPixel>>(processor);
}
}
}
+83 -82
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Numerics;
@@ -23,37 +23,37 @@ public sealed partial class HlslBokehBlurProcessor
/// <summary>
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
/// </summary>
private readonly GraphicsDevice GraphicsDevice;
private readonly GraphicsDevice graphicsDevice;
/// <summary>
/// The kernel radius.
/// </summary>
private readonly int Radius;
private readonly int radius;
/// <summary>
/// The maximum size of the kernel in either direction.
/// </summary>
private readonly int KernelSize;
private readonly int kernelSize;
/// <summary>
/// The number of components to use when applying the bokeh blur.
/// </summary>
private readonly int ComponentsCount;
private readonly int componentsCount;
/// <summary>
/// The kernel parameters to use for the current instance (a: X, b: Y, A: Z, B: W)
/// </summary>
private readonly Vector4[] KernelParameters;
private readonly Vector4[] kernelParameters;
/// <summary>
/// The kernel components for the current instance.
/// </summary>
private readonly Complex64[][] Kernels;
private readonly Complex64[][] kernels;
/// <summary>
/// The scaling factor for kernel values.
/// </summary>
private readonly float KernelsScale;
private readonly float kernelsScale;
/// <summary>
/// The mapping of initialized complex kernels and parameters, to speed up the initialization of new <see cref="HlslBokehBlurProcessor"/> instances.
@@ -70,29 +70,30 @@ public sealed partial class HlslBokehBlurProcessor
public Implementation(HlslBokehBlurProcessor definition, Configuration configuration, Image<ImageSharpRgba32> source, Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle)
{
GraphicsDevice = definition.GraphicsDevice;
Radius = definition.Radius;
KernelSize = Radius * 2 + 1;
ComponentsCount = definition.Components;
this.graphicsDevice = definition.GraphicsDevice;
this.radius = definition.Radius;
this.kernelSize = (this.radius * 2) + 1;
this.componentsCount = definition.Components;
// Reuse the initialized values from the cache, if possible
var parameters = (Radius, ComponentsCount);
if (Cache.TryGetValue(parameters, out var info))
(int radius, int componentsCount) parameters = (this.radius, this.componentsCount);
if (Cache.TryGetValue(parameters, out (Vector4[] Parameters, float Scale, Complex64[][] Kernels) info))
{
KernelParameters = info.Parameters;
KernelsScale = info.Scale;
Kernels = info.Kernels;
this.kernelParameters = info.Parameters;
this.kernelsScale = info.Scale;
this.kernels = info.Kernels;
}
else
{
// Initialize the complex kernels and parameters with the current arguments
(KernelParameters, KernelsScale) = GetParameters();
Kernels = CreateComplexKernels();
(this.kernelParameters, this.kernelsScale) = GetParameters();
this.kernels = CreateComplexKernels();
NormalizeKernels();
// Store them in the cache for future use
Cache.TryAdd(parameters, (KernelParameters, KernelsScale, Kernels));
_ = Cache.TryAdd(parameters, (this.kernelParameters, this.kernelsScale, this.kernels));
}
}
@@ -161,7 +162,7 @@ public sealed partial class HlslBokehBlurProcessor
private (Vector4[] Parameters, float Scale) GetParameters()
{
// Prepare the kernel components
int index = Math.Max(0, Math.Min(ComponentsCount - 1, KernelComponents.Count));
int index = Math.Max(0, Math.Min(this.componentsCount - 1, KernelComponents.Count));
return (KernelComponents[index], KernelScales[index]);
}
@@ -171,10 +172,10 @@ public sealed partial class HlslBokehBlurProcessor
/// </summary>
private Complex64[][] CreateComplexKernels()
{
var kernels = new Complex64[KernelParameters.Length][];
ref Vector4 baseRef = ref MemoryMarshal.GetReference(KernelParameters.AsSpan());
Complex64[][] kernels = new Complex64[this.kernelParameters.Length][];
ref Vector4 baseRef = ref MemoryMarshal.GetReference(this.kernelParameters.AsSpan());
for (int i = 0; i < KernelParameters.Length; i++)
for (int i = 0; i < this.kernelParameters.Length; i++)
{
ref Vector4 paramsRef = ref Unsafe.Add(ref baseRef, i);
@@ -191,15 +192,15 @@ public sealed partial class HlslBokehBlurProcessor
/// <param name="b">The angle component for each complex component.</param>
private Complex64[] CreateComplex1DKernel(float a, float b)
{
var kernel = new Complex64[KernelSize];
Complex64[] kernel = new Complex64[this.kernelSize];
ref Complex64 baseRef = ref MemoryMarshal.GetReference(kernel.AsSpan());
int r = Radius;
int r = this.radius;
int n = -r;
for (int i = 0; i < KernelSize; i++, n++)
for (int i = 0; i < this.kernelSize; i++, n++)
{
// Incrementally compute the range values
float value = n * KernelsScale * (1f / r);
float value = n * this.kernelsScale * (1f / r);
value *= value;
@@ -219,11 +220,11 @@ public sealed partial class HlslBokehBlurProcessor
{
// Calculate the complex weighted sum
float total = 0;
Span<Complex64[]> kernelsSpan = Kernels.AsSpan();
Span<Complex64[]> kernelsSpan = this.kernels.AsSpan();
ref Complex64[] baseKernelsRef = ref MemoryMarshal.GetReference(kernelsSpan);
ref Vector4 baseParamsRef = ref MemoryMarshal.GetReference(KernelParameters.AsSpan());
ref Vector4 baseParamsRef = ref MemoryMarshal.GetReference(this.kernelParameters.AsSpan());
for (int i = 0; i < KernelParameters.Length; i++)
for (int i = 0; i < this.kernelParameters.Length; i++)
{
ref Complex64[] kernelRef = ref Unsafe.Add(ref baseKernelsRef, i);
int length = kernelRef.Length;
@@ -238,8 +239,8 @@ public sealed partial class HlslBokehBlurProcessor
ref Complex64 kRef = ref Unsafe.Add(ref valueRef, k);
total +=
paramsRef.Z * (jRef.Real * kRef.Real - jRef.Imaginary * kRef.Imaginary)
+ paramsRef.W * (jRef.Real * kRef.Imaginary + jRef.Imaginary * kRef.Real);
(paramsRef.Z * ((jRef.Real * kRef.Real) - (jRef.Imaginary * kRef.Imaginary)))
+ (paramsRef.W * ((jRef.Real * kRef.Imaginary) + (jRef.Imaginary * kRef.Real)));
}
}
}
@@ -270,23 +271,23 @@ public sealed partial class HlslBokehBlurProcessor
Span<Rgba32> span = MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(pixelMemory.Span);
using ReadWriteTexture2D<Rgba32, float4> texture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, float4>(span, source.Width, source.Height);
using ReadWriteTexture2D<float4> temporary = GraphicsDevice.AllocateReadWriteTexture2D<float4>(source.Width, source.Height, AllocationMode.Clear);
using ReadWriteTexture2D<float4> reals = GraphicsDevice.AllocateReadWriteTexture2D<float4>(source.Width, source.Height);
using ReadWriteTexture2D<float4> imaginaries = GraphicsDevice.AllocateReadWriteTexture2D<float4>(source.Width, source.Height);
using ReadOnlyBuffer<Complex64> kernel = GraphicsDevice.AllocateReadOnlyBuffer<Complex64>(KernelSize);
using ReadWriteTexture2D<Rgba32, float4> texture = this.graphicsDevice.AllocateReadWriteTexture2D<Rgba32, float4>(span, source.Width, source.Height);
using ReadWriteTexture2D<float4> temporary = this.graphicsDevice.AllocateReadWriteTexture2D<float4>(source.Width, source.Height, AllocationMode.Clear);
using ReadWriteTexture2D<float4> reals = this.graphicsDevice.AllocateReadWriteTexture2D<float4>(source.Width, source.Height);
using ReadWriteTexture2D<float4> imaginaries = this.graphicsDevice.AllocateReadWriteTexture2D<float4>(source.Width, source.Height);
using ReadOnlyBuffer<Complex64> kernel = this.graphicsDevice.AllocateReadOnlyBuffer<Complex64>(this.kernelSize);
// Preliminary gamma highlight pass
GraphicsDevice.For<GammaHighlightProcessor>(source.Height, new(texture));
this.graphicsDevice.For<GammaHighlightProcessor>(source.Height, new(texture));
// Perform two 1D convolutions for each component in the current instance
for (int j = 0; j < Kernels.Length; j++)
for (int j = 0; j < this.kernels.Length; j++)
{
Vector4 parameters = KernelParameters[j];
Vector4 parameters = this.kernelParameters[j];
kernel.CopyFrom(Kernels[j]);
kernel.CopyFrom(this.kernels[j]);
using var context = GraphicsDevice.CreateComputeContext();
using ComputeContext context = this.graphicsDevice.CreateComputeContext();
context.For<VerticalConvolutionProcessor>(
source.Width,
@@ -303,7 +304,7 @@ public sealed partial class HlslBokehBlurProcessor
}
// Apply the inverse gamma exposure pass
GraphicsDevice.For<InverseGammaHighlightProcessor>(source.Height, new(temporary, texture));
this.graphicsDevice.For<InverseGammaHighlightProcessor>(source.Height, new(temporary, texture));
// Write the final pixel data
texture.CopyTo(span);
@@ -313,36 +314,36 @@ public sealed partial class HlslBokehBlurProcessor
/// Kernel for the vertical convolution pass.
/// </summary>
[AutoConstructor]
internal partial struct VerticalConvolutionProcessor : IComputeShader
internal readonly partial struct VerticalConvolutionProcessor : IComputeShader
{
public IReadWriteNormalizedTexture2D<float4> source;
public ReadWriteTexture2D<float4> reals;
public ReadWriteTexture2D<float4> imaginaries;
public ReadOnlyBuffer<Complex64> kernel;
private readonly IReadWriteNormalizedTexture2D<float4> source;
private readonly ReadWriteTexture2D<float4> reals;
private readonly ReadWriteTexture2D<float4> imaginaries;
private readonly ReadOnlyBuffer<Complex64> kernel;
/// <inheritdoc/>
public void Execute()
{
float4 real = float4.Zero;
float4 imaginary = float4.Zero;
int maxY = source.Height;
int maxX = source.Width;
int kernelLength = kernel.Length;
int maxY = this.source.Height;
int maxX = this.source.Width;
int kernelLength = this.kernel.Length;
int radiusY = kernelLength >> 1;
for (int i = 0; i < kernelLength; i++)
{
int offsetY = Hlsl.Clamp(ThreadIds.Y + i - radiusY, 0, maxY);
int offsetX = Hlsl.Clamp(ThreadIds.X, 0, maxX);
float4 color = source[offsetX, offsetY];
Complex64 factors = kernel[i];
float4 color = this.source[offsetX, offsetY];
Complex64 factors = this.kernel[i];
real += factors.Real * color;
imaginary += factors.Imaginary * color;
}
reals[ThreadIds.XY] = real;
imaginaries[ThreadIds.XY] = imaginary;
this.reals[ThreadIds.XY] = real;
this.imaginaries[ThreadIds.XY] = imaginary;
}
}
@@ -350,22 +351,22 @@ public sealed partial class HlslBokehBlurProcessor
/// Kernel for the horizontal convolution pass.
/// </summary>
[AutoConstructor]
internal partial struct HorizontalConvolutionAndAccumulatePartialsProcessor : IComputeShader
internal readonly partial struct HorizontalConvolutionAndAccumulatePartialsProcessor : IComputeShader
{
public float z;
public float w;
private readonly float z;
private readonly float w;
public ReadWriteTexture2D<float4> reals;
public ReadWriteTexture2D<float4> imaginaries;
public ReadWriteTexture2D<float4> target;
public ReadOnlyBuffer<Complex64> kernel;
private readonly ReadWriteTexture2D<float4> reals;
private readonly ReadWriteTexture2D<float4> imaginaries;
private readonly ReadWriteTexture2D<float4> target;
private readonly ReadOnlyBuffer<Complex64> kernel;
/// <inheritdoc/>
public void Execute()
{
int maxY = target.Height;
int maxX = target.Width;
int kernelLength = kernel.Length;
int maxY = this.target.Height;
int maxX = this.target.Width;
int kernelLength = this.kernel.Length;
int radiusX = kernelLength >> 1;
int offsetY = Hlsl.Clamp(ThreadIds.Y, 0, maxY);
ComplexVector4 result = default;
@@ -373,15 +374,15 @@ public sealed partial class HlslBokehBlurProcessor
for (int i = 0; i < kernelLength; i++)
{
int offsetX = Hlsl.Clamp(ThreadIds.X + i - radiusX, 0, maxX);
float4 sourceReal = reals[offsetX, offsetY];
float4 sourceImaginary = imaginaries[offsetX, offsetY];
Complex64 factors = kernel[i];
float4 sourceReal = this.reals[offsetX, offsetY];
float4 sourceImaginary = this.imaginaries[offsetX, offsetY];
Complex64 factors = this.kernel[i];
result.Real += (Vector4)(factors.Real * sourceReal - factors.Imaginary * sourceImaginary);
result.Imaginary += (Vector4)(factors.Real * sourceImaginary + factors.Imaginary * sourceReal);
result.Real += (Vector4)((factors.Real * sourceReal) - (factors.Imaginary * sourceImaginary));
result.Imaginary += (Vector4)((factors.Real * sourceImaginary) + (factors.Imaginary * sourceReal));
}
target[ThreadIds.XY] += (float4)result.WeightedSum(z, w);
this.target[ThreadIds.XY] += (float4)result.WeightedSum(this.z, this.w);
}
}
@@ -391,20 +392,20 @@ public sealed partial class HlslBokehBlurProcessor
[AutoConstructor]
internal readonly partial struct GammaHighlightProcessor : IComputeShader
{
public readonly IReadWriteNormalizedTexture2D<float4> source;
private readonly IReadWriteNormalizedTexture2D<float4> source;
/// <inheritdoc/>
public void Execute()
{
int width = source.Width;
int width = this.source.Width;
for (int i = 0; i < width; i++)
{
float4 v = source[i, ThreadIds.X];
float4 v = this.source[i, ThreadIds.X];
v.XYZ = v.XYZ * v.XYZ * v.XYZ;
source[i, ThreadIds.X] = v;
this.source[i, ThreadIds.X] = v;
}
}
}
@@ -415,24 +416,24 @@ public sealed partial class HlslBokehBlurProcessor
[AutoConstructor]
internal readonly partial struct InverseGammaHighlightProcessor : IComputeShader
{
public readonly ReadWriteTexture2D<float4> source;
public readonly IReadWriteNormalizedTexture2D<float4> target;
private readonly ReadWriteTexture2D<float4> source;
private readonly IReadWriteNormalizedTexture2D<float4> target;
/// <inheritdoc/>
public void Execute()
{
int width = source.Width;
int width = this.source.Width;
for (int i = 0; i < width; i++)
{
float4 v = source[i, ThreadIds.X];
float4 v = this.source[i, ThreadIds.X];
v = Hlsl.Clamp(v, 0, float.MaxValue);
v.XYZ = Hlsl.Pow(v.XYZ, 1 / 3f);
target[i, ThreadIds.X] = v;
this.target[i, ThreadIds.X] = v;
}
}
}
}
}
}
+6 -5
ファイルの表示
@@ -1,4 +1,4 @@
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using CommunityToolkit.Diagnostics;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
@@ -52,7 +52,8 @@ public sealed partial class HlslGaussianBlurProcessor : IImageProcessor
/// <param name="radius">The radius value representing the size of the area to sample (this should be at least twice the sigma value)</param>
public HlslGaussianBlurProcessor(GraphicsDevice device, float sigma, int radius)
{
GraphicsDevice = device;
this.graphicsDevice = device;
Sigma = sigma;
Radius = radius;
}
@@ -60,7 +61,7 @@ public sealed partial class HlslGaussianBlurProcessor : IImageProcessor
/// <summary>
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
/// </summary>
private readonly GraphicsDevice GraphicsDevice;
private readonly GraphicsDevice graphicsDevice;
/// <summary>
/// Gets the sigma value representing the weight of the blur.
@@ -81,8 +82,8 @@ public sealed partial class HlslGaussianBlurProcessor : IImageProcessor
ThrowHelper.ThrowInvalidOperationException("This processor only supports the RGBA32 pixel format.");
}
var processor = new Implementation(this, configuration, Unsafe.As<Image<ImageSharpRgba32>>(source), sourceRectangle);
Implementation processor = new(this, configuration, Unsafe.As<Image<ImageSharpRgba32>>(source), sourceRectangle);
return Unsafe.As<IImageProcessor<TPixel>>(processor);
}
}
}
+29 -29
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using CommunityToolkit.Diagnostics;
@@ -19,12 +19,12 @@ public sealed partial class HlslGaussianBlurProcessor
/// <summary>
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
/// </summary>
private readonly GraphicsDevice GraphicsDevice;
private readonly GraphicsDevice graphicsDevice;
/// <summary>
/// The 1D kernel to apply.
/// </summary>
private readonly float[] Kernel;
private readonly float[] kernel;
/// <summary>
/// Initializes a new instance of the <see cref="Implementation"/> class.
@@ -36,10 +36,10 @@ public sealed partial class HlslGaussianBlurProcessor
public Implementation(HlslGaussianBlurProcessor definition, Configuration configuration, Image<ImageSharpRgba32> source, Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle)
{
int kernelSize = definition.Radius * 2 + 1;
int kernelSize = (definition.Radius * 2) + 1;
GraphicsDevice = definition.GraphicsDevice;
Kernel = CreateGaussianBlurKernel(kernelSize, definition.Sigma);
this.graphicsDevice = definition.graphicsDevice;
this.kernel = CreateGaussianBlurKernel(kernelSize, definition.Sigma);
}
/// <summary>
@@ -100,11 +100,11 @@ public sealed partial class HlslGaussianBlurProcessor
Span<Rgba32> span = MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(pixelMemory.Span);
using ReadWriteTexture2D<Rgba32, float4> sourceTexture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, float4>(span, source.Width, source.Height);
using ReadWriteTexture2D<Rgba32, float4> firstPassTexture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, float4>(source.Width, source.Height);
using ReadOnlyBuffer<float> kernelBuffer = GraphicsDevice.AllocateReadOnlyBuffer(Kernel);
using ReadWriteTexture2D<Rgba32, float4> sourceTexture = this.graphicsDevice.AllocateReadWriteTexture2D<Rgba32, float4>(span, source.Width, source.Height);
using ReadWriteTexture2D<Rgba32, float4> firstPassTexture = this.graphicsDevice.AllocateReadWriteTexture2D<Rgba32, float4>(source.Width, source.Height);
using ReadOnlyBuffer<float> kernelBuffer = this.graphicsDevice.AllocateReadOnlyBuffer(this.kernel);
using (var context = GraphicsDevice.CreateComputeContext())
using (ComputeContext context = this.graphicsDevice.CreateComputeContext())
{
context.For<VerticalConvolutionProcessor>(source.Width, source.Height, new(sourceTexture, firstPassTexture, kernelBuffer));
context.Barrier(firstPassTexture);
@@ -120,29 +120,29 @@ public sealed partial class HlslGaussianBlurProcessor
[AutoConstructor]
internal readonly partial struct VerticalConvolutionProcessor : IComputeShader
{
public readonly IReadWriteNormalizedTexture2D<float4> source;
public readonly IReadWriteNormalizedTexture2D<float4> target;
public readonly ReadOnlyBuffer<float> kernel;
private readonly IReadWriteNormalizedTexture2D<float4> source;
private readonly IReadWriteNormalizedTexture2D<float4> target;
private readonly ReadOnlyBuffer<float> kernel;
/// <inheritdoc/>
public void Execute()
{
float4 result = float4.Zero;
int maxY = source.Height - 1;
int maxX = source.Width - 1;
int kernelLength = kernel.Length;
int maxY = this.source.Height - 1;
int maxX = this.source.Width - 1;
int kernelLength = this.kernel.Length;
int radiusY = kernelLength >> 1;
for (int i = 0; i < kernelLength; i++)
{
int offsetY = Hlsl.Clamp(ThreadIds.Y + i - radiusY, 0, maxY);
int offsetX = Hlsl.Clamp(ThreadIds.X, 0, maxX);
float4 color = source[offsetX, offsetY];
float4 color = this.source[offsetX, offsetY];
result += kernel[i] * color;
result += this.kernel[i] * color;
}
target[ThreadIds.XY] = result;
this.target[ThreadIds.XY] = result;
}
}
@@ -152,30 +152,30 @@ public sealed partial class HlslGaussianBlurProcessor
[AutoConstructor]
internal readonly partial struct HorizontalConvolutionProcessor : IComputeShader
{
public readonly IReadWriteNormalizedTexture2D<float4> source;
public readonly IReadWriteNormalizedTexture2D<float4> target;
public readonly ReadOnlyBuffer<float> kernel;
private readonly IReadWriteNormalizedTexture2D<float4> source;
private readonly IReadWriteNormalizedTexture2D<float4> target;
private readonly ReadOnlyBuffer<float> kernel;
/// <inheritdoc/>
public void Execute()
{
float4 result = float4.Zero;
int maxY = source.Height - 1;
int maxX = source.Width - 1;
int kernelLength = kernel.Length;
int maxY = this.source.Height - 1;
int maxX = this.source.Width - 1;
int kernelLength = this.kernel.Length;
int radiusX = kernelLength >> 1;
int offsetY = Hlsl.Clamp(ThreadIds.Y, 0, maxY);
for (int i = 0; i < kernelLength; i++)
{
int offsetX = Hlsl.Clamp(ThreadIds.X + i - radiusX, 0, maxX);
float4 color = source[offsetX, offsetY];
float4 color = this.source[offsetX, offsetY];
result += kernel[i] * color;
result += this.kernel[i] * color;
}
target[ThreadIds.XY] = result;
this.target[ThreadIds.XY] = result;
}
}
}
}
}
+3 -3
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Reflection;
using ComputeSharp.BokehBlur.Processors;
@@ -15,7 +15,7 @@ string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly()
using Image<ImageSharpRgba32> image = Image.Load<ImageSharpRgba32>(path);
// Apply a series of processors and save the results
foreach (var effect in new (string Name, IImageProcessor Processor)[]
foreach ((string Name, IImageProcessor Processor) effect in new (string Name, IImageProcessor Processor)[]
{
("bokeh", new HlslBokehBlurProcessor(80, 2)),
("gaussian", new HlslGaussianBlurProcessor(80))
@@ -37,4 +37,4 @@ foreach (var effect in new (string Name, IImageProcessor Processor)[]
targetPath = Path.Combine(targetPath, $"{Path.GetFileNameWithoutExtension(path)}_{effect.Name}{Path.GetExtension(path)}");
copy.Save(targetPath);
}
}
+4 -4
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.Sample.FSharp.Shaders;
namespace ComputeSharp.Sample.FSharp.Shaders;
/// <summary>
/// A sample shader thaat just multiplies items in a buffer by two.
@@ -6,11 +6,11 @@
[AutoConstructor]
public readonly partial struct MultiplyByTwo : IComputeShader
{
public readonly ReadWriteBuffer<float> buffer;
private readonly ReadWriteBuffer<float> buffer;
/// <inheritdoc/>
public void Execute()
{
buffer[ThreadIds.X] *= 2;
this.buffer[ThreadIds.X] *= 2;
}
}
}
+4 -4
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.Globalization;
using System.Linq;
using CommunityToolkit.Diagnostics;
@@ -34,12 +34,12 @@ internal static class Formatting
for (int i = 0; i < height; i++)
{
var row = array.AsSpan(i * width, width).ToArray();
var text = string.Join(",", row.Select(x => x.ToString(CultureInfo.InvariantCulture).PadLeft(numberWidth)));
float[] row = array.AsSpan(i * width, width).ToArray();
string text = string.Join(",", row.Select(x => x.ToString(CultureInfo.InvariantCulture).PadLeft(numberWidth)));
Console.WriteLine(text);
}
Console.WriteLine(new string('=', 50));
}
}
}
+4 -4
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using ComputeSharp;
using ComputeSharp.Sample;
@@ -26,11 +26,11 @@ Formatting.PrintMatrix(array, 10, 10, "AFTER");
[AutoConstructor]
internal readonly partial struct MultiplyByTwo : IComputeShader
{
public readonly ReadWriteBuffer<float> buffer;
private readonly ReadWriteBuffer<float> buffer;
/// <inheritdoc/>
public void Execute()
{
buffer[ThreadIds.X] *= 2;
this.buffer[ThreadIds.X] *= 2;
}
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.SwapChain.Core.Constants;
namespace ComputeSharp.SwapChain.Core.Constants;
/// <summary>
/// A <see langword="class"/> with the collection of tracked errors for analytics.
@@ -7,4 +7,4 @@ public static class Error
{
public const string RenderingFailedOnMainPanel = "[SHELL] RenderingFailed (main panel)";
public const string RenderingFailedOnSelectionPanel = "[SHELL] RenderingFailed (selection panel)";
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.SwapChain.Core.Constants;
namespace ComputeSharp.SwapChain.Core.Constants;
/// <summary>
/// A <see langword="class"/> with the collection of tracked events for analytics.
@@ -12,4 +12,4 @@ public static class Event
public const string IsRenderingPausedChanged = "[SETTINGS] IsRenderingPaused";
public const string OpenShaderSelectionPanel = "[SHELL] Open ShaderSelectionPanel";
public const string CloseShaderSelectionPanel = "[SHELL] Close ShaderSelectionPanel";
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
#if WINDOWS_UWP
#if WINDOWS_UWP
using Windows.UI.Xaml.Controls;
#else
using Microsoft.UI.Xaml.Controls;
@@ -20,4 +20,4 @@ public static class RenderingPauseConverter
{
return value ? Symbol.Play : Symbol.Pause;
}
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.SwapChain.Core.Converters;
namespace ComputeSharp.SwapChain.Core.Converters;
/// <summary>
/// A class with some static converters for resolution scale settings.
@@ -24,4 +24,4 @@ public static class ResolutionScaleConverter
{
return value / 100.0;
}
}
}
+10 -10
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;
using System.Text;
@@ -16,13 +16,13 @@ public sealed class DebugAnalyticsService : IAnalyticsService
{
StringBuilder builder = new();
builder.AppendLine($"[EVENT]: \"{title}\"");
_ = builder.AppendLine($"[EVENT]: \"{title}\"");
if (data is not null)
{
foreach (var info in data)
foreach ((string Property, object? Value) info in data)
{
builder.AppendLine($">> {info.Property}: \"{info.Value ?? "<NULL>"}\"");
_ = builder.AppendLine($">> {info.Property}: \"{info.Value ?? "<NULL>"}\"");
}
}
@@ -34,18 +34,18 @@ public sealed class DebugAnalyticsService : IAnalyticsService
{
StringBuilder builder = new();
builder.AppendLine($"[EXCEPTION]: \"{exception.GetType()}\"");
builder.AppendLine(">> Stack trace");
builder.AppendLine(exception.StackTrace);
_ = builder.AppendLine($"[EXCEPTION]: \"{exception.GetType()}\"");
_ = builder.AppendLine(">> Stack trace");
_ = builder.AppendLine(exception.StackTrace);
if (data is not null)
{
foreach (var info in data)
foreach ((string Property, object? Value) info in data)
{
builder.AppendLine($">> {info.Property}: \"{info.Value ?? "<NULL>"}\"");
_ = builder.AppendLine($">> {info.Property}: \"{info.Value ?? "<NULL>"}\"");
}
}
Trace.Write(builder);
}
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
#nullable enable
@@ -22,4 +22,4 @@ public interface IAnalyticsService
/// <param name="exception">The exception that has been thrown.</param>
/// <param name="data">The optional event properties.</param>
void Log(Exception exception, params (string Property, object? Value)[]? data);
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using ComputeSharp.SwapChain.Shaders;
#if WINDOWS_UWP
@@ -39,4 +39,4 @@ public sealed class ContouredLayersRunner : IShaderRunner
return true;
}
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using CommunityToolkit.Diagnostics;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
@@ -170,4 +170,4 @@ public sealed partial class MainViewModel : ObservableObject
{
IsRenderingPaused = !IsRenderingPaused;
}
}
}
+1 -1
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using CommunityToolkit.Mvvm.ComponentModel;
#if WINDOWS_UWP
using ComputeSharp.Uwp;
+7 -7
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.SwapChain.Shaders;
namespace ComputeSharp.SwapChain.Shaders;
/// <summary>
/// A shader creating an abstract and colorful animation.
@@ -15,7 +15,7 @@ internal readonly partial struct ColorfulInfinity : IPixelShader<float4>
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
/// <summary>
/// The total number of layers for the final animation.
@@ -32,7 +32,7 @@ internal readonly partial struct ColorfulInfinity : IPixelShader<float4>
/// </summary>
private float4 Tex(float3 p)
{
float t = time + 78.0f;
float t = this.time + 78.0f;
float4 o = new(p.X, p.Y, p.Z, 3.0f * Hlsl.Sin(t * 0.1f));
float4 dec =
new float4(1.0f, 0.9f, 0.1f, 0.15f) +
@@ -40,7 +40,7 @@ internal readonly partial struct ColorfulInfinity : IPixelShader<float4>
for (int i = 0; i++ < NumberOfIterations;)
{
o.XZYW = Hlsl.Abs(o / Hlsl.Dot(o, o) - dec);
o.XZYW = Hlsl.Abs((o / Hlsl.Dot(o, o)) - dec);
}
return o;
@@ -49,9 +49,9 @@ internal readonly partial struct ColorfulInfinity : IPixelShader<float4>
/// <inheritdoc/>
public float4 Execute()
{
float2 uv = (ThreadIds.XY - (float2)DispatchSize.XY * 0.5f) / DispatchSize.Y;
float2 uv = (ThreadIds.XY - ((float2)DispatchSize.XY * 0.5f)) / DispatchSize.Y;
float3 col = 0;
float t = time * 0.3f;
float t = this.time * 0.3f;
for (float i = 0.0f; i <= 1.0f; i += 1.0f / NumberOfLayers)
{
@@ -68,4 +68,4 @@ internal readonly partial struct ColorfulInfinity : IPixelShader<float4>
return new(col.X, col.Y, col.Z, 1.0f);
}
}
}
+26 -23
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.SwapChain.Shaders;
namespace ComputeSharp.SwapChain.Shaders;
/// <summary>
/// Constructing some concise contoured layers, then applying various edge and shading effects to produce some faux depth.
@@ -14,12 +14,12 @@ internal readonly partial struct ContouredLayers : IPixelShader<float4>
/// <summary>
/// The current time Hlsl.Since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
/// <summary>
/// The background texture to sample.
/// </summary>
public readonly IReadOnlyNormalizedTexture2D<float4> texture;
private readonly IReadOnlyNormalizedTexture2D<float4> texture;
// float3 to float hash.
private static float Hash21(float2 p)
@@ -34,7 +34,7 @@ internal readonly partial struct ContouredLayers : IPixelShader<float4>
p = Hlsl.Frac(new float2(262144, 32768) * n);
return Hlsl.Sin(p * 6.2831853f + time);
return Hlsl.Sin((p * 6.2831853f) + this.time);
}
// float2 to float2 hash.
@@ -42,7 +42,7 @@ internal readonly partial struct ContouredLayers : IPixelShader<float4>
{
float n = Hlsl.Sin(Hlsl.Dot(p, new float2(41, 289)));
return Hlsl.Frac(new float2(262144, 32768) * n) * 2.0f - 1.0f;
return (Hlsl.Frac(new float2(262144, 32768) * n) * 2.0f) - 1.0f;
}
// Smooth 2D noise
@@ -59,7 +59,7 @@ internal readonly partial struct ContouredLayers : IPixelShader<float4>
v.Z = Hlsl.Dot(Hash22B(i + float2.UnitY), p - float2.UnitY);
v.W = Hlsl.Dot(Hash22B(i + 1.0f), p - 1.0f);
p = p * p * (3.0f - 2.0f * p);
p = p * p * (3.0f - (2.0f * p));
return Hlsl.Lerp(Hlsl.Lerp(v.X, v.Y, p.X), Hlsl.Lerp(v.Z, v.W, p.X), p.Y);
}
@@ -68,7 +68,7 @@ internal readonly partial struct ContouredLayers : IPixelShader<float4>
private float Noise2D3G(float2 p)
{
float2 i = Hlsl.Floor(p);
p -= i;
float4 v = default;
@@ -78,7 +78,7 @@ internal readonly partial struct ContouredLayers : IPixelShader<float4>
v.Z = Hlsl.Dot(Hash22(i + float2.UnitY), p - float2.UnitY);
v.W = Hlsl.Dot(Hash22(i + 1.0f), p - 1.0f);
p = p * p * p * (p * (p * 6.0f - 15.0f) + 10.0f);
p = p * p * p * ((p * ((p * 6.0f) - 15.0f)) + 10.0f);
return Hlsl.Lerp(Hlsl.Lerp(v.X, v.Y, p.X), Hlsl.Lerp(v.Z, v.W, p.X), p.Y);
}
@@ -86,7 +86,7 @@ internal readonly partial struct ContouredLayers : IPixelShader<float4>
// Map function with noise layers
private float MapNoise(float3 p, float i)
{
return Noise2D3G(p.XY * 3.0f) * 0.66f + Noise2D3G(p.XY * 6.0f) * 0.34f + i / 10.0f * 1.0f - 0.15f;
return (Noise2D3G(p.XY * 3.0f) * 0.66f) + (Noise2D3G(p.XY * 6.0f) * 0.34f) + (i / 10.0f * 1.0f) - 0.15f;
}
// 2D derivative function.
@@ -111,13 +111,13 @@ 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.Sample(p + Hash21(new float2(sh, fi))).XYZ;
float3 tx = this.texture.Sample(p + Hash21(new float2(sh, fi))).XYZ;
tx *= tx;
float3 col;
col = (float3)1.0 * (1.0f - 0.75f / (1.0f + sh * sh * 2.0f));
col = (float3)1.0 * (1.0f - (0.75f / (1.0f + (sh * sh * 2.0f))));
col = Hlsl.Min(col * tx * 3.0f, 1.0f);
return col;
@@ -128,12 +128,15 @@ internal readonly partial struct ContouredLayers : IPixelShader<float4>
{
p *= res / 16.0f;
float hatch = Hlsl.Clamp(Hlsl.Sin((p.X - p.Y) * 3.14159f * 200.0f) * 2.0f + 0.5f, 0.0f, 1.0f);
float hatch = Hlsl.Clamp((Hlsl.Sin((p.X - p.Y) * 3.14159f * 200.0f) * 2.0f) + 0.5f, 0.0f, 1.0f);
float hRnd = Hash21(Hlsl.Floor(p * 6.0f) + 0.73f);
if (hRnd > 0.66f) hatch = hRnd;
if (hRnd > 0.66f)
{
hatch = hRnd;
}
hatch = hatch * 0.75f + 0.5f;
hatch = (hatch * 0.75f) + 0.5f;
return hatch;
}
@@ -143,7 +146,7 @@ internal readonly partial struct ContouredLayers : IPixelShader<float4>
{
float2 fragCoord = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y);
float res = Hlsl.Min(DispatchSize.Y, 700.0f);
float2 uv = (fragCoord - (float2)DispatchSize.XY * 0.5f) / res;
float2 uv = (fragCoord - ((float2)DispatchSize.XY * 0.5f)) / res;
float sf = 1.0f / DispatchSize.Y;
float3 col = GetColor(uv, 0.0f, 0.0f);
float pL = 0.0f;
@@ -161,8 +164,8 @@ internal readonly partial struct ContouredLayers : IPixelShader<float4>
hatch = Hatch(uv + Hlsl.Sin(new float2(41.0f, 289.0f) * (fi + 1.0f)), res);
float4 c = MapLayer(new float3(uv, 1.0f), fi);
float4 cSh = MapLayer(new float3(uv - new float2(0.03f, -0.03f) * ((flNum - fi) / flNum * 0.5f + 0.5f), 1.0f), fi);
float sh = (fi + 1.0f) / (flNum);
float4 cSh = MapLayer(new float3(uv - (new float2(0.03f, -0.03f) * (((flNum - fi) / flNum * 0.5f) + 0.5f)), 1.0f), fi);
float sh = (fi + 1.0f) / flNum;
float3 lCol = GetColor(uv, sh, fi + 1.0f);
float3 ld = Hlsl.Normalize(new float3(-1, 1, -0.25f));
float3 n = Hlsl.Normalize(new float3(0.0f, 0.0f, -1.0f) + c.YZW);
@@ -178,17 +181,17 @@ internal readonly partial struct ContouredLayers : IPixelShader<float4>
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sfLSh, Hlsl.Max(cSh.X, pL))) * shF);
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sfL * 3.0f, c.X)) * 0.25f);
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sfL, c.X)) * 0.85f);
col = Hlsl.Lerp(col, eCol * hatch, (1.0f - Hlsl.SmoothStep(0.0f, sfL, c.X + Hlsl.Length(c.YZX) * 0.003f)));
col = Hlsl.Lerp(col, lCol * hatch, (1.0f - Hlsl.SmoothStep(0.0f, sfL, c.X + Hlsl.Length(c.YZX) * 0.006f)));
col = Hlsl.Lerp(col, eCol * hatch, 1.0f - Hlsl.SmoothStep(0.0f, sfL, c.X + (Hlsl.Length(c.YZX) * 0.003f)));
col = Hlsl.Lerp(col, lCol * hatch, 1.0f - Hlsl.SmoothStep(0.0f, sfL, c.X + (Hlsl.Length(c.YZX) * 0.006f)));
pL = c.X;
}
col *= Hlsl.Lerp(new float3(1.8f, 1, 0.7f).ZYX, new float3(1.8f, 1, 0.7f).XZY, Noise2D(uv * 2.0f));
float3 rn3 = Noise2D(uv * DispatchSize.Y / 1.0f + 1.7f) - Noise2D(uv * DispatchSize.Y / 1.0f + 3.4f);
float3 rn3 = Noise2D((uv * DispatchSize.Y / 1.0f) + 1.7f) - Noise2D((uv * DispatchSize.Y / 1.0f) + 3.4f);
col *= 0.93f + 0.07f * rn3.XYZ + 0.07f * Hlsl.Dot(rn3, new float3(0.299f, 0.587f, 0.114f));
col *= 0.93f + (0.07f * rn3.XYZ) + (0.07f * Hlsl.Dot(rn3, new float3(0.299f, 0.587f, 0.114f)));
uv = fragCoord / DispatchSize.XY;
@@ -196,4 +199,4 @@ internal readonly partial struct ContouredLayers : IPixelShader<float4>
return new float4(Hlsl.Sqrt(Hlsl.Max(col, 0.0f)), 1);
}
}
}
+65 -38
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.SwapChain.Shaders;
namespace ComputeSharp.SwapChain.Shaders;
/// <summary>
/// A basic extruded square grid-based blobby Truchet pattern.
@@ -14,7 +14,7 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
/// <summary>
/// Curve shape - Round: 0, Semi-round: 1, Octagonal: 2, Superellipse: 3, Straight: 4.
@@ -48,11 +48,14 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
{
return Hlsl.Length(p);
}
else p = Hlsl.Abs(p);
else
{
p = Hlsl.Abs(p);
}
switch (SHAPE)
{
case 1: return Hlsl.Max(Hlsl.Length(p), (p.X + p.Y) * 0.7071f + 0.015f);
case 1: return Hlsl.Max(Hlsl.Length(p), ((p.X + p.Y) * 0.7071f) + 0.015f);
case 2: return Hlsl.Max((p.X + p.Y) * 0.7071f, Hlsl.Max(p.X, p.Y));
case 3: return Hlsl.Pow(Hlsl.Dot(Hlsl.Pow(p, 3), 1), 1.0f / 3.0f);
default: return (p.X + p.Y) * 0.7071f;
@@ -62,7 +65,7 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
// GLSL's mod function
private static float Mod(float x, float y)
{
return x - y * Hlsl.Floor(x / y);
return x - (y * Hlsl.Floor(x / y));
}
// A standard square grid 2D blobby Truchet routine: Render circles
@@ -77,17 +80,27 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
float rnd = Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(ip, new float2(1, 113))) * 45758.5453f);
if (rnd < 0.5f) p.Y = -p.Y;
if (rnd < 0.5f)
{
p.Y = -p.Y;
}
float d = Hlsl.Min(Distance(p - 0.5f * sc), Distance(p + 0.5f * sc)) - 0.5f * sc;
float d = Hlsl.Min(Distance(p - (0.5f * sc)), Distance(p + (0.5f * sc))) - (0.5f * sc);
if (SHAPE == 4)
{
d += (0.5f - 0.5f / Hlsl.Sqrt(2.0f)) * sc;
d += (0.5f - (0.5f / Hlsl.Sqrt(2.0f))) * sc;
}
if (rnd < 0.5f) d = -d;
if (Mod(ip.X + ip.Y, 2.0f) < 0.5f) d = -d;
if (rnd < 0.5f)
{
d = -d;
}
if (Mod(ip.X + ip.Y, 2.0f) < 0.5f)
{
d = -d;
}
return d - 0.03f;
}
@@ -100,18 +113,18 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
float fl = -p.Z;
float obj = Truchet(p.XY);
obj = Hlsl.Max(obj, Hlsl.Abs(p.Z) - 0.125f) - Hlsl.SmoothStep(0.03f, 0.25f, -obj) * 0.1f;
obj = Hlsl.Max(obj, Hlsl.Abs(p.Z) - 0.125f) - (Hlsl.SmoothStep(0.03f, 0.25f, -obj) * 0.1f);
float studs = 1e5f;
const float sc = 0.5f;
float2 q = p.XY + 0.5f * sc;
float2 q = p.XY + (0.5f * sc);
float2 iq = Hlsl.Floor(q / sc) + 0.5f;
q -= iq * sc;
if (Mod(iq.X + iq.Y, 2.0f) > 0.5f)
{
studs = Hlsl.Max(Hlsl.Length(q) - 0.1f * sc - 0.02f, Hlsl.Abs(p.Z) - 0.26f);
studs = Hlsl.Max(Hlsl.Length(q) - (0.1f * sc) - 0.02f, Hlsl.Abs(p.Z) - 0.26f);
}
objID = fl < obj && fl < studs ? 0 : obj < studs ? 1 : 2;
@@ -136,18 +149,20 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
for (int i = 0; i < iter; i++)
{
float d = M(ro + rd * t);
float d = M(ro + (rd * t));
shade = Hlsl.Min(shade, k * d / t);
t += Hlsl.Clamp(d, 0.01f, 0.25f);
if (d < 0.0f || t > end) break;
if (d < 0.0f || t > end)
{
break;
}
}
return Hlsl.Max(shade, 0.0f);
}
// I keep a collection of occlusion routines... OK, that sounded really nerdy. :)
// Anyway, I like this one. I'm assuHlsl.Ming it's based on IQ's original.
private float CalculateAO(in float3 p, in float3 n)
@@ -155,15 +170,18 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
float sca = 2.0f;
float occ = 0.0f;
for (int i = (int)Hlsl.Min(time, 0f); i < 5; i++)
for (int i = (int)Hlsl.Min(this.time, 0f); i < 5; i++)
{
float hr = (i + 1f) * 0.15f / 5.0f;
float d = M(p + n * hr);
float d = M(p + (n * hr));
occ += (hr - d) * sca;
sca *= 0.7f;
if (sca > 1e5f) break;
if (sca > 1e5f)
{
break;
}
}
return Hlsl.Clamp(1.0f - occ, 0.0f, 1.0f);
@@ -184,31 +202,34 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
public float4 Execute()
{
int2 coords = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y);
float2 u = (coords - (float2)DispatchSize.XY * 0.5f) / DispatchSize.Y;
float2 u = (coords - ((float2)DispatchSize.XY * 0.5f)) / DispatchSize.Y;
float3 r = Hlsl.Normalize(new float3(u, 1));
float3 o = new(0, time / 2.0f, -3);
float3 o = new(0, this.time / 2.0f, -3);
float3 l = o + new float3(0.25f, 0.25f, 2.0f);
r.YZ = Hlsl.Mul(Rotate2x2(0.15f), r.YZ);
r.XZ = Hlsl.Mul(Rotate2x2(-Hlsl.Cos(time * 3.14159f / 32.0f) / 8.0f), r.XZ);
r.XY = Hlsl.Mul(Rotate2x2(Hlsl.Sin(time * 3.14159f / 32.0f) / 8.0f), r.XY);
r.XZ = Hlsl.Mul(Rotate2x2(-Hlsl.Cos(this.time * 3.14159f / 32.0f) / 8.0f), r.XZ);
r.XY = Hlsl.Mul(Rotate2x2(Hlsl.Sin(this.time * 3.14159f / 32.0f) / 8.0f), r.XY);
float d;
float t = Hash21(r.XY * 57.0f + Hlsl.Frac(time)) * 0.5f;
float t = Hash21((r.XY * 57.0f) + Hlsl.Frac(this.time)) * 0.5f;
float glow = 0;
for (int i = 0; i < 96; i++)
{
d = M(o + r * t);
d = M(o + (r * t));
if (Hlsl.Abs(d) < 0.001f) break;
if (Hlsl.Abs(d) < 0.001f)
{
break;
}
t += d * 0.7f;
glow += 0.2f / (1.0f + Hlsl.Abs(d) * 5.0f);
glow += 0.2f / (1.0f + (Hlsl.Abs(d) * 5.0f));
}
int gObjID = objID;
float3 p = o + r * t;
float3 p = o + (r * t);
float3 n = Normal(p);
float2 uv = p.XY;
float sc = 0.5f;
@@ -216,21 +237,21 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
uv -= iuv * sc;
float2 uv2 = p.XY + 0.5f * sc;
float2 uv2 = p.XY + (0.5f * sc);
float2 iuv2 = Hlsl.Floor(uv2 / sc) + 0.5f;
uv2 -= iuv2 * sc;
float bord = Hlsl.Max(Hlsl.Abs(uv.X), Hlsl.Abs(uv.Y)) - 0.5f * sc;
float bord = Hlsl.Max(Hlsl.Abs(uv.X), Hlsl.Abs(uv.Y)) - (0.5f * sc);
bord = Hlsl.Abs(bord) - 0.002f;
d = Truchet(p.XY);
float lSc = 20.0f;
float pat = (Hlsl.Abs(Hlsl.Frac((uv.X - uv.Y) * lSc - 0.5f) - 0.5f) * 2.0f - 0.5f) / lSc;
float pat2 = (Hlsl.Abs(Hlsl.Frac((uv.X + uv.Y) * lSc + 0.5f) - 0.5f) * 2.0f - 0.5f) / lSc;
float pat = ((Hlsl.Abs(Hlsl.Frac(((uv.X - uv.Y) * lSc) - 0.5f) - 0.5f) * 2.0f) - 0.5f) / lSc;
float pat2 = ((Hlsl.Abs(Hlsl.Frac(((uv.X + uv.Y) * lSc) + 0.5f) - 0.5f) * 2.0f) - 0.5f) / lSc;
float sf = Hlsl.Dot(Hlsl.Sin(p.XY - Hlsl.Cos(p.YX * 2.0f)), 0.5f);
float sf2 = Hlsl.Dot(Hlsl.Sin(p.XY * 1.5f - Hlsl.Cos(p.YX * 3.0f)), 0.5f);
float sf2 = Hlsl.Dot(Hlsl.Sin((p.XY * 1.5f) - Hlsl.Cos(p.YX * 3.0f)), 0.5f);
float4 col1 = Hlsl.Lerp(new float4(1, 0.75f, 0.6f, 0), new float4(1, 0.85f, 0.65f, 0), Hlsl.SmoothStep(-0.5f, 0.5f, sf));
float4 col2 = Hlsl.Lerp(new float4(0.4f, 0.7f, 1, 0), new float4(0.3f, 0.85f, 0.95f, 0), Hlsl.SmoothStep(-0.5f, 0.5f, sf2) * 0.5f);
@@ -244,7 +265,10 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
oCol = Hlsl.Lerp(col2, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, pat2)) * 0.35f);
oCol = Hlsl.Lerp(oCol, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, bord)) * 0.8f);
if (Mod(iuv.X + iuv.Y, 2.0f) > 0.5f) oCol *= 0.8f;
if (Mod(iuv.X + iuv.Y, 2.0f) > 0.5f)
{
oCol *= 0.8f;
}
oCol = Hlsl.Lerp(oCol, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, d - 0.015f)) * 0.8f);
}
@@ -254,7 +278,10 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
float4 fCol = Hlsl.Lerp(col1, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, pat)) * 0.35f);
fCol = Hlsl.Lerp(fCol, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, bord)) * 0.8f);
if (Mod(iuv.X + iuv.Y, 2.0f) < 0.5f) fCol *= 0.8f;
if (Mod(iuv.X + iuv.Y, 2.0f) < 0.5f)
{
fCol *= 0.8f;
}
oCol = Hlsl.Lerp(oCol, fCol, 1 - Hlsl.SmoothStep(0, 0.01f, d + 0.08f));
oCol = Hlsl.Lerp(oCol, 0, (1 - Hlsl.SmoothStep(0, 0.01f, Hlsl.Length(uv2) - 0.08f)) * 0.8f);
@@ -283,16 +310,16 @@ internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
ld /= lDist;
float at = 1.0f / (1.0f + lDist * lDist * 0.125f);
float at = 1.0f / (1.0f + (lDist * lDist * 0.125f));
float sh = SoftShadow(p, l, n, 8);
float ao = CalculateAO(p, n);
float df = Hlsl.Max(Hlsl.Dot(n, ld), 0);
float sp = Hlsl.Pow(Hlsl.Max(Hlsl.Dot(Hlsl.Reflect(r, n), ld), 0), 32);
float4 c = oCol * (df * sh + sp * sh + 0.5f) * at * ao;
float4 c = oCol * ((df * sh) + (sp * sh) + 0.5f) * at * ao;
c = Hlsl.Sqrt(Hlsl.Max(c, 0));
return c;
}
}
}
+21 -22
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.SwapChain.Shaders;
namespace ComputeSharp.SwapChain.Shaders;
/// <summary>
/// A shader which interpolates four different colors into a rotating gradient pattern.
@@ -15,13 +15,13 @@ internal readonly partial struct FourColorGradient : IPixelShader<float4>
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
// Colors to blend together
private static readonly float3 colorOne = new(0.999f, 0.999f, 0.999f);
private static readonly float3 colorTwo = new(0.999f, 0f, 0f);
private static readonly float3 colorThree = new(0f, 0.999f, 0f);
private static readonly float3 colorFour = new(0f, 0f, 0.999f);
private static readonly float3 ColorOne = new(0.999f, 0.999f, 0.999f);
private static readonly float3 ColorTwo = new(0.999f, 0f, 0f);
private static readonly float3 ColorThree = new(0f, 0.999f, 0f);
private static readonly float3 ColorFour = new(0f, 0f, 0.999f);
/// <summary>
/// Standard 2D rotation formula.
@@ -55,24 +55,23 @@ internal readonly partial struct FourColorGradient : IPixelShader<float4>
{
float2 i = Hlsl.Floor(p);
float2 f = Hlsl.Frac(p);
float2 u = f * f * (3.0f - 2.0f * f);
float2 u = f * f * (3.0f - (2.0f * f));
// Mix -> Lerp
float n = Hlsl.Lerp(
Hlsl.Lerp(
Hlsl.Dot(-1.0f + 2.0f * Hash(i + new float2(0.0f, 0.0f)), f - new float2(0.0f, 0.0f)),
Hlsl.Dot(-1.0f + 2.0f * Hash(i + new float2(1.0f, 0.0f)), f - new float2(1.0f, 0.0f)),
Hlsl.Dot(-1.0f + (2.0f * Hash(i + new float2(0.0f, 0.0f))), f - new float2(0.0f, 0.0f)),
Hlsl.Dot(-1.0f + (2.0f * Hash(i + new float2(1.0f, 0.0f))), f - new float2(1.0f, 0.0f)),
u.X),
Hlsl.Lerp(
Hlsl.Dot(-1.0f + 2.0f * Hash(i + new float2(0.0f, 1.0f)), f - new float2(0.0f, 1.0f)),
Hlsl.Dot(-1.0f + 2.0f * Hash(i + new float2(1.0f, 1.0f)), f - new float2(1.0f, 1.0f)),
u.X),
Hlsl.Dot(-1.0f + (2.0f * Hash(i + new float2(0.0f, 1.0f))), f - new float2(0.0f, 1.0f)),
Hlsl.Dot(-1.0f + (2.0f * Hash(i + new float2(1.0f, 1.0f))), f - new float2(1.0f, 1.0f)),
u.X),
u.Y);
return 0.5f + 0.5f * n;
return 0.5f + (0.5f * n);
}
/// <inheritdoc/>
public float4 Execute()
{
@@ -84,25 +83,25 @@ internal readonly partial struct FourColorGradient : IPixelShader<float4>
tuv -= 0.5f;
// Rotate with noise
float degree = Noise(new float2(time * 0.1f, tuv.X * tuv.Y));
float degree = Noise(new float2(this.time * 0.1f, tuv.X * tuv.Y));
tuv.Y *= 1.0f / ratio;
tuv.XY = Hlsl.Mul(tuv.XY, Rotate(Hlsl.Radians((degree - 0.5f) * 720.0f + 180.0f)));
tuv.XY = Hlsl.Mul(tuv.XY, Rotate(Hlsl.Radians(((degree - 0.5f) * 720.0f) + 180.0f)));
tuv.Y *= ratio;
// Wave warp with sin
float frequency = 5.0f;
float amplitude = 30.0f;
float speed = time * 2.0f;
float speed = this.time * 2.0f;
tuv.X += Hlsl.Sin(tuv.Y * frequency + speed) / amplitude;
tuv.Y += Hlsl.Sin(tuv.X * frequency * 1.5f + speed) / (amplitude * 0.5f);
tuv.X += Hlsl.Sin((tuv.Y * frequency) + speed) / amplitude;
tuv.Y += Hlsl.Sin((tuv.X * frequency * 1.5f) + speed) / (amplitude * 0.5f);
// Draw the image
float3 layer1 = Hlsl.Lerp(colorOne, colorTwo, Hlsl.SmoothStep(-0.3f, 0.2f, Hlsl.Mul(tuv.XY, Rotate(Hlsl.Radians(-5.0f))).X));
float3 layer2 = Hlsl.Lerp(colorThree, colorFour, Hlsl.SmoothStep(-0.3f, 0.2f, Hlsl.Mul(tuv.XY, Rotate(Hlsl.Radians(-5.0f))).X));
float3 layer1 = Hlsl.Lerp(ColorOne, ColorTwo, Hlsl.SmoothStep(-0.3f, 0.2f, Hlsl.Mul(tuv.XY, Rotate(Hlsl.Radians(-5.0f))).X));
float3 layer2 = Hlsl.Lerp(ColorThree, ColorFour, Hlsl.SmoothStep(-0.3f, 0.2f, Hlsl.Mul(tuv.XY, Rotate(Hlsl.Radians(-5.0f))).X));
float3 col = Hlsl.Lerp(layer1, layer2, Hlsl.SmoothStep(0.5f, -0.3f, tuv.Y));
return new(col, 1.0f);
}
}
}
+5 -5
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.SwapChain.Shaders;
namespace ComputeSharp.SwapChain.Shaders;
/// <summary>
/// A shader creating a fractal tiling animation.
@@ -15,12 +15,12 @@ internal readonly partial struct FractalTiling : IPixelShader<float4>
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
/// <inheritdoc/>
public float4 Execute()
{
float2 position = ((float2)(256 * ThreadIds.XY)) / DispatchSize.X + time;
float2 position = (((float2)(256 * ThreadIds.XY)) / DispatchSize.X) + this.time;
float4 color = 0;
for (int i = 0; i < 6; i++)
@@ -28,7 +28,7 @@ internal readonly partial struct FractalTiling : IPixelShader<float4>
float2 a = Hlsl.Floor(position);
float2 b = Hlsl.Frac(position);
float4 w = Hlsl.Frac(
(Hlsl.Sin(a.X * 7 + 31.0f * a.Y + 0.01f * time) +
(Hlsl.Sin((a.X * 7) + (31.0f * a.Y) + (0.01f * this.time)) +
new float4(0.035f, 0.01f, 0, 0.7f))
* 13.545317f);
@@ -45,4 +45,4 @@ internal readonly partial struct FractalTiling : IPixelShader<float4>
return color;
}
}
}
+4 -4
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.SwapChain.Shaders;
namespace ComputeSharp.SwapChain.Shaders;
/// <summary>
/// A simple shader to get started with based on shadertoy new shader template.
@@ -13,7 +13,7 @@ internal readonly partial struct HelloWorld : IPixelShader<float4>
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
/// <inheritdoc/>
public float4 Execute()
@@ -22,9 +22,9 @@ internal readonly partial struct HelloWorld : IPixelShader<float4>
float2 uv = ThreadIds.Normalized.XY;
// Time varying pixel color
float3 col = 0.5f + 0.5f * Hlsl.Cos(time + new float3(uv, uv.X) + new float3(0, 2, 4));
float3 col = 0.5f + (0.5f * Hlsl.Cos(this.time + new float3(uv, uv.X) + new float3(0, 2, 4)));
// Output to screen
return new(col, 1f);
}
}
}
+28 -23
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.SwapChain.Shaders;
namespace ComputeSharp.SwapChain.Shaders;
/// <summary>
/// A shader creating a flythrough in a Menger system.
@@ -14,7 +14,7 @@ internal readonly partial struct MengerJourney : IPixelShader<float4>
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
private const int MaxSteps = 30;
private const float MinimumDistance = 0.0009f;
@@ -39,7 +39,7 @@ internal readonly partial struct MengerJourney : IPixelShader<float4>
/// </summary>
private static float2 Rotate(float2 v, float a)
{
return new(Hlsl.Cos(a) * v.X + Hlsl.Sin(a) * v.Y, -Hlsl.Sin(a) * v.X + Hlsl.Cos(a) * v.Y);
return new((Hlsl.Cos(a) * v.X) + (Hlsl.Sin(a) * v.Y), (-Hlsl.Sin(a) * v.X) + (Hlsl.Cos(a) * v.Y));
}
/// <summary>
@@ -55,8 +55,8 @@ internal readonly partial struct MengerJourney : IPixelShader<float4>
float diffuse2 = Hlsl.Max(0.0f, Hlsl.Dot(-normal, lightDir2));
return
(diffuse * Diffuse) * (LightColor * color) +
(diffuse2 * Diffuse) * (LightColor2 * color);
(diffuse * Diffuse * (LightColor * color)) +
(diffuse2 * Diffuse * (LightColor2 * color));
}
/// <summary>
@@ -68,7 +68,7 @@ internal readonly partial struct MengerJourney : IPixelShader<float4>
// Performs the GLSL mod function.
static float3 Mod(float3 x, float y)
{
return x - y * Hlsl.Floor(x / y);
return x - (y * Hlsl.Floor(x / y));
}
z = Hlsl.Abs(1.0f - Mod(z, 2.0f));
@@ -77,14 +77,16 @@ internal readonly partial struct MengerJourney : IPixelShader<float4>
for (int n = 0; n < Iterations; n++)
{
z.XY = Rotate(z.XY, 4.0f + 2.0f * Hlsl.Cos(time / 8.0f));
z.XY = Rotate(z.XY, 4.0f + (2.0f * Hlsl.Cos(this.time / 8.0f)));
z = Hlsl.Abs(z);
if (z.X < z.Y) { z.XY = z.YX; }
if (z.X < z.Z) { z.XZ = z.ZX; }
if (z.Y < z.Z) { z.YZ = z.ZY; }
z = Scale * z - Offset * (Scale - 1.0f);
z = (Scale * z) - (Offset * (Scale - 1.0f));
if (z.Z < -0.5f * Offset.Z * (Scale - 1.0))
{
@@ -100,7 +102,7 @@ internal readonly partial struct MengerJourney : IPixelShader<float4>
/// <summary>
/// Calculates the finite difference normal at a given position.
/// </summary>
private float3 getNormal(in float3 pos)
private float3 GetNormal(in float3 pos)
{
float3 e = new(0.0f, NormalDistance, 0.0f);
@@ -121,7 +123,7 @@ internal readonly partial struct MengerJourney : IPixelShader<float4>
return Hlsl.Frac(Hlsl.Cos(Hlsl.Dot(co, new float2(4.898f, 7.23f))) * 23421.631f);
}
float totalDistance = Jitter * Rand(fragCoord.XY + time);
float totalDistance = Jitter * Rand(fragCoord.XY + this.time);
float3 dir2 = dir;
float distance = 0;
int steps = 0;
@@ -129,23 +131,26 @@ internal readonly partial struct MengerJourney : IPixelShader<float4>
for (int i = 0; i < MaxSteps; i++)
{
dir.ZY = Rotate(dir2.ZY, totalDistance * Hlsl.Cos(time / 4.0f) * NonLinearPerspective);
pos = from + totalDistance * dir;
dir.ZY = Rotate(dir2.ZY, totalDistance * Hlsl.Cos(this.time / 4.0f) * NonLinearPerspective);
pos = from + (totalDistance * dir);
distance = DE(pos) * FudgeFactor;
totalDistance += distance;
if (distance < MinimumDistance) break;
if (distance < MinimumDistance)
{
break;
}
steps = i;
}
float smoothStep = steps + distance / MinimumDistance;
float ao = 1.1f - smoothStep / MaxSteps;
float3 normal = getNormal(pos - dir * NormalDistance * 3.0f);
float smoothStep = steps + (distance / MinimumDistance);
float ao = 1.1f - (smoothStep / MaxSteps);
float3 normal = GetNormal(pos - (dir * NormalDistance * 3.0f));
float3 color = 1.0f;
float3 light = GetLight(color, normal);
color = (color * Ambient + light) * ao;
color = ((color * Ambient) + light) * ao;
return new(color.X, color.Y, color.Z, 1.0f);
}
@@ -153,20 +158,20 @@ internal readonly partial struct MengerJourney : IPixelShader<float4>
/// <inheritdoc/>
public float4 Execute()
{
float3 camPos = 0.5f * time * new float3(1.0f, 0.0f, 0.0f);
float3 target = camPos + new float3(1.0f, 0.0f * Hlsl.Cos(time), 0.0f * Hlsl.Sin(0.4f * time));
float3 camPos = 0.5f * this.time * new float3(1.0f, 0.0f, 0.0f);
float3 target = camPos + new float3(1.0f, 0.0f * Hlsl.Cos(this.time), 0.0f * Hlsl.Sin(0.4f * this.time));
float3 camDir = Hlsl.Normalize(target - camPos);
float3 camUp = new(0.0f, 1.0f, 0.0f);
camUp = Hlsl.Normalize(camUp - Hlsl.Dot(camDir, camUp) * camDir);
camUp = Hlsl.Normalize(camUp - (Hlsl.Dot(camDir, camUp) * camDir));
float3 camRight = Hlsl.Normalize(Hlsl.Cross(camDir, camUp));
float2 coord = -1.0f + 2.0f * (float2)ThreadIds.XY / DispatchSize.XY;
float2 coord = -1.0f + (2.0f * (float2)ThreadIds.XY / DispatchSize.XY);
coord.X *= (float)DispatchSize.X / DispatchSize.Y;
float3 rayDir = Hlsl.Normalize(camDir + (coord.X * camRight + coord.Y * camUp) * FieldOfView);
float3 rayDir = Hlsl.Normalize(camDir + (((coord.X * camRight) + (coord.Y * camUp)) * FieldOfView));
return RayMarch(camPos, rayDir, ThreadIds.XY);
}
}
}
+16 -16
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.SwapChain.Shaders;
namespace ComputeSharp.SwapChain.Shaders;
/// <summary>
/// A shader creating an octagram animation, inspired by arabesque.
@@ -14,7 +14,7 @@ internal readonly partial struct Octagrams : IPixelShader<float4>
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
private static float2x2 Rotate(float a)
{
@@ -53,25 +53,25 @@ internal readonly partial struct Octagrams : IPixelShader<float4>
pos.Y += Hlsl.Sin(gTime * 0.4f) * 2.5f;
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.8f));
float box1 = Box(pos, 2.0f - Hlsl.Abs(Hlsl.Sin(gTime * 0.4f)) * 1.5f);
float box1 = Box(pos, 2.0f - (Hlsl.Abs(Hlsl.Sin(gTime * 0.4f)) * 1.5f));
pos = pos_origin;
pos.Y -= Hlsl.Sin(gTime * 0.4f) * 2.5f;
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.8f));
float box2 = Box(pos, 2.0f - Hlsl.Abs(Hlsl.Sin(gTime * 0.4f)) * 1.5f);
float box2 = Box(pos, 2.0f - (Hlsl.Abs(Hlsl.Sin(gTime * 0.4f)) * 1.5f));
pos = pos_origin;
pos.X += Hlsl.Sin(gTime * 0.4f) * 2.5f;
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.8f));
float box3 = Box(pos, 2.0f - Hlsl.Abs(Hlsl.Sin(gTime * 0.4f)) * 1.5f);
float box3 = Box(pos, 2.0f - (Hlsl.Abs(Hlsl.Sin(gTime * 0.4f)) * 1.5f));
pos = pos_origin;
pos.X -= Hlsl.Sin(gTime * 0.4f) * 2.5f;
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.8f));
float box4 = Box(pos, 2.0f - Hlsl.Abs(Hlsl.Sin(gTime * 0.4f)) * 1.5f);
float box4 = Box(pos, 2.0f - (Hlsl.Abs(Hlsl.Sin(gTime * 0.4f)) * 1.5f));
pos = pos_origin;
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.8f));
@@ -89,12 +89,12 @@ internal readonly partial struct Octagrams : IPixelShader<float4>
/// <inheritdoc/>
public float4 Execute()
{
float2 p = ((float2)ThreadIds.XY * 2.0f - DispatchSize.XY) / Hlsl.Min(DispatchSize.X, DispatchSize.Y);
float3 ro = new(0.0f, -0.2f, time * 4.0f);
float2 p = (((float2)ThreadIds.XY * 2.0f) - DispatchSize.XY) / Hlsl.Min(DispatchSize.X, DispatchSize.Y);
float3 ro = new(0.0f, -0.2f, this.time * 4.0f);
float3 ray = Hlsl.Normalize(new float3(p, 1.5f));
ray.XY = Hlsl.Mul(ray.XY, Rotate(Hlsl.Sin(time * 0.03f) * 5.0f));
ray.YZ = Hlsl.Mul(ray.YZ, Rotate(Hlsl.Sin(time * 0.05f) * 0.2f));
ray.XY = Hlsl.Mul(ray.XY, Rotate(Hlsl.Sin(this.time * 0.03f) * 5.0f));
ray.YZ = Hlsl.Mul(ray.YZ, Rotate(Hlsl.Sin(this.time * 0.05f) * 0.2f));
float t = 0.1f;
float ac = 0.0f;
@@ -103,14 +103,14 @@ internal readonly partial struct Octagrams : IPixelShader<float4>
{
static float3 Mod(float3 x, float y)
{
return x - y * Hlsl.Floor(x / y);
return x - (y * Hlsl.Floor(x / y));
}
float3 pos = ro + ray * t;
float3 pos = ro + (ray * t);
pos = Mod(pos - 2.0f, 4.0f) - 2.0f;
float gTime = time - i * 0.01f;
float gTime = this.time - (i * 0.01f);
float d = BoxSet(pos, gTime);
d = Hlsl.Max(Hlsl.Abs(d), 0.01f);
@@ -118,9 +118,9 @@ internal readonly partial struct Octagrams : IPixelShader<float4>
t += d * 0.55f;
}
float3 col = ac * 0.02f + new float3(0.0f, 0.2f * Hlsl.Abs(Hlsl.Sin(time)), 0.5f + Hlsl.Sin(time) * 0.2f);
float4 color = new(col, 1.0f - t * (0.02f + 0.02f * Hlsl.Sin(time)));
float3 col = (ac * 0.02f) + new float3(0.0f, 0.2f * Hlsl.Abs(Hlsl.Sin(this.time)), 0.5f + (Hlsl.Sin(this.time) * 0.2f));
float4 color = new(col, 1.0f - (t * (0.02f + (0.02f * Hlsl.Sin(this.time)))));
return color;
}
}
}
+29 -26
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.SwapChain.Shaders;
namespace ComputeSharp.SwapChain.Shaders;
/// <summary>
/// Fully procedural 3D animated volume with three evaluations per step (for shading).
@@ -15,15 +15,15 @@ internal readonly partial struct ProteanClouds : IPixelShader<float4>
/// <summary>
/// The current time Hlsl.Since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
private static readonly float3x3 m3 = new float3x3(0.33338f, 0.56034f, -0.71817f, -0.87887f, 0.32651f, -0.15323f, 0.15162f, 0.69596f, 0.61339f) * 1.93f;
private static readonly float3x3 M3 = new float3x3(0.33338f, 0.56034f, -0.71817f, -0.87887f, 0.32651f, -0.15323f, 0.15162f, 0.69596f, 0.61339f) * 1.93f;
private static float2x2 Rotate(in float a)
{
float c = Hlsl.Cos(a);
float s = Hlsl.Sin(a);
return new(c, s, -s, c);
}
@@ -42,7 +42,7 @@ internal readonly partial struct ProteanClouds : IPixelShader<float4>
float3 p2 = p;
p2.XY -= Disp(p.Z).XY;
p.XY = Hlsl.Mul(p.XY, Rotate(Hlsl.Sin(p.Z + time) * (0.1f + prm1 * 0.05f) + time * 0.09f));
p.XY = Hlsl.Mul(p.XY, Rotate((Hlsl.Sin(p.Z + this.time) * (0.1f + (prm1 * 0.05f))) + (this.time * 0.09f)));
float cl = Hlsl.Dot(p2.XY, p2.XY);
float d = 0.0f;
@@ -51,21 +51,21 @@ internal readonly partial struct ProteanClouds : IPixelShader<float4>
float z = 1.0f;
float trk = 1.0f;
float dspAmp = 0.1f + prm1 * 0.2f;
float dspAmp = 0.1f + (prm1 * 0.2f);
for (int i = 0; i < 5; i++)
{
p += Hlsl.Sin(p.ZXY * 0.75f * trk + time * trk * 0.8f) * dspAmp;
p += Hlsl.Sin((p.ZXY * 0.75f * trk) + (this.time * trk * 0.8f)) * dspAmp;
d -= Hlsl.Abs(Hlsl.Dot(Hlsl.Cos(p), Hlsl.Sin(p.YZX)) * z);
z *= 0.57f;
trk *= 1.4f;
p = Hlsl.Mul(p, m3);
p = Hlsl.Mul(p, M3);
}
d = Hlsl.Abs(d + prm1 * 3.0f) + prm1 * 0.3f - 2.5f + bsMo.Y;
d = Hlsl.Abs(d + (prm1 * 3.0f)) + (prm1 * 0.3f) - 2.5f + bsMo.Y;
return new float2(d + cl * 0.2f + 0.25f, cl);
return new float2(d + (cl * 0.2f) + 0.25f, cl);
}
private float4 Render(float3 ro, float3 rd, float time, float prm1, float2 bsMo)
@@ -76,33 +76,36 @@ internal readonly partial struct ProteanClouds : IPixelShader<float4>
for (int i = 0; i < 130; i++)
{
if (rez.A > 0.99f) break;
if (rez.A > 0.99f)
{
break;
}
float3 pos = ro + t * rd;
float3 pos = ro + (t * rd);
float2 mpv = Map(pos, prm1, bsMo);
float den = Hlsl.Clamp(mpv.X - 0.3f, 0.0f, 1.0f) * 1.12f;
float dn = Hlsl.Clamp((mpv.X + 2.0f), 0.0f, 3.0f);
float dn = Hlsl.Clamp(mpv.X + 2.0f, 0.0f, 3.0f);
float4 col = 0f;
if (mpv.X > 0.6f)
{
col = new float4(Hlsl.Sin(new float3(5.0f, 0.4f, 0.2f) + mpv.Y * 0.1f + Hlsl.Sin(pos.Z * 0.4f) * 0.5f + 1.8f) * 0.5f + 0.5f, 0.08f);
col = new float4((Hlsl.Sin(new float3(5.0f, 0.4f, 0.2f) + (mpv.Y * 0.1f) + (Hlsl.Sin(pos.Z * 0.4f) * 0.5f) + 1.8f) * 0.5f) + 0.5f, 0.08f);
col *= den * den * den;
col.RGB *= LinStep(4.0f, -2.5f, mpv.X) * 2.3f;
float dif = Hlsl.Clamp((den - Map(pos + 0.8f, prm1, bsMo).X) / 9.0f, 0.001f, 1.0f);
dif += Hlsl.Clamp((den - Map(pos + 0.35f, prm1, bsMo).X) / 2.5f, 0.001f, 1.0f);
col.XYZ *= den * (new float3(0.005f, 0.045f, 0.075f) + 1.5f * new float3(0.033f, 0.07f, 0.03f) * dif);
col.XYZ *= den * (new float3(0.005f, 0.045f, 0.075f) + (1.5f * new float3(0.033f, 0.07f, 0.03f) * dif));
}
float fogC = Hlsl.Exp(t * 0.2f - 2.2f);
float fogC = Hlsl.Exp((t * 0.2f) - 2.2f);
col += new float4(0.06f, 0.11f, 0.11f, 0.1f) * Hlsl.Clamp(fogC - fogT, 0.0f, 1.0f);
fogT = fogC;
rez += col * (1.0f - rez.A);
t += Hlsl.Clamp(0.5f - dn * dn * 0.05f, 0.09f, 0.3f);
t += Hlsl.Clamp(0.5f - (dn * dn * 0.05f), 0.09f, 0.3f);
}
return Hlsl.Clamp(rez, 0.0f, 1.0f);
@@ -120,7 +123,7 @@ internal readonly partial struct ProteanClouds : IPixelShader<float4>
{
float3 ic = Hlsl.Lerp(a, b, x) + new float3((float)1e-6, 0.0f, 0.0f);
float sd = Hlsl.Abs(GetSaturation(ic) - Hlsl.Lerp(GetSaturation(a), GetSaturation(b), x));
float3 dir = Hlsl.Normalize(new float3(2.0f * ic.X - ic.Y - ic.Z, 2.0f * ic.Y - ic.X - ic.Z, 2.0f * ic.Z - ic.Y - ic.X));
float3 dir = Hlsl.Normalize(new float3((2.0f * ic.X) - ic.Y - ic.Z, (2.0f * ic.Y) - ic.X - ic.Z, (2.0f * ic.Z) - ic.Y - ic.X));
float lgt = Hlsl.Dot(1.0f, ic);
float ff = Hlsl.Dot(dir, Hlsl.Normalize(ic));
@@ -133,12 +136,12 @@ internal readonly partial struct ProteanClouds : IPixelShader<float4>
public float4 Execute()
{
float2 q = (float2)ThreadIds.XY / DispatchSize.XY;
float2 p = (ThreadIds.XY - 0.5f * (float2)DispatchSize.XY) / DispatchSize.Y;
float2 p = (ThreadIds.XY - (0.5f * (float2)DispatchSize.XY)) / DispatchSize.Y;
float2 bsMo = -0.5f * (float2)DispatchSize.XY / DispatchSize.Y;
float scaledTime = time * 3.0f;
float scaledTime = this.time * 3.0f;
float3 ro = new(0, 0, scaledTime);
ro += new float3(Hlsl.Sin(time) * 0.5f, Hlsl.Sin(time * 1.0f) * 0.0f, 0);
ro += new float3(Hlsl.Sin(this.time) * 0.5f, Hlsl.Sin(this.time * 1.0f) * 0.0f, 0);
float dspAmp = 0.85f;
@@ -154,18 +157,18 @@ internal readonly partial struct ProteanClouds : IPixelShader<float4>
rightdir = Hlsl.Normalize(Hlsl.Cross(updir, target));
float3 rd = Hlsl.Normalize((p.X * rightdir + p.Y * updir) * 1.0f - target);
float3 rd = Hlsl.Normalize((((p.X * rightdir) + (p.Y * updir)) * 1.0f) - target);
rd.XY = Hlsl.Mul(rd.XY, Rotate(-Disp(scaledTime + 3.5f).X * 0.2f + bsMo.X));
rd.XY = Hlsl.Mul(rd.XY, Rotate((-Disp(scaledTime + 3.5f).X * 0.2f) + bsMo.X));
float prm1 = Hlsl.SmoothStep(-0.4f, 0.4f, Hlsl.Sin(time * 0.3f));
float prm1 = Hlsl.SmoothStep(-0.4f, 0.4f, Hlsl.Sin(this.time * 0.3f));
float4 scn = Render(ro, rd, scaledTime, prm1, bsMo);
float3 col = scn.RGB;
col = ILerp(col.BGR, col.RGB, Hlsl.Clamp(1.0f - prm1, 0.05f, 1.0f));
col = Hlsl.Pow(col, new float3(0.55f, 0.65f, 0.6f)) * new float3(1.0f, 0.97f, 0.9f);
col *= Hlsl.Pow(16.0f * q.X * q.Y * (1.0f - q.X) * (1.0f - q.Y), 0.12f) * 0.7f + 0.3f;
col *= (Hlsl.Pow(16.0f * q.X * q.Y * (1.0f - q.X) * (1.0f - q.Y), 0.12f) * 0.7f) + 0.3f;
return new(col, 1.0f);
}
}
}
+41 -28
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.SwapChain.Shaders;
namespace ComputeSharp.SwapChain.Shaders;
/// <summary>
/// An offset grid of square-based pyramids whose tips have been offset according to an underlying directional noise field.
@@ -15,7 +15,7 @@ internal readonly partial struct PyramidPattern : IPixelShader<float4>
/// <summary>
/// The current time Hlsl.Since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
// Standard 2D rotation formula.
private static float2x2 Rotate2x2(in float a)
@@ -37,14 +37,14 @@ internal readonly partial struct PyramidPattern : IPixelShader<float4>
{
float n = Hlsl.Sin(Hlsl.Dot(p, new float2(41, 289)));
return Hlsl.Frac(new float2(262144, 32768) * n) * 2.0f - 1.0f;
return (Hlsl.Frac(new float2(262144, 32768) * n) * 2.0f) - 1.0f;
}
// Based on IQ's gradient noise formula.
private static float N2D3G(float2 p)
{
float2 i = Hlsl.Floor(p);
p -= i;
float4 v = default;
@@ -54,7 +54,7 @@ internal readonly partial struct PyramidPattern : IPixelShader<float4>
v.Z = Hlsl.Dot(Hash22B(i + float2.UnitY), p - float2.UnitY);
v.W = Hlsl.Dot(Hash22B(i + 1.0f), p - 1.0f);
p = p * p * (3.0f - 2.0f * p);
p = p * p * (3.0f - (2.0f * p));
return Hlsl.Lerp(Hlsl.Lerp(v.X, v.Y, p.X), Hlsl.Lerp(v.Z, v.W, p.X), p.Y);
}
@@ -62,13 +62,13 @@ internal readonly partial struct PyramidPattern : IPixelShader<float4>
// Two layers of noise.
private static float FBM(float2 p)
{
return N2D3G(p) * 0.66f + N2D3G(p * 2.0f) * 0.34f;
return (N2D3G(p) * 0.66f) + (N2D3G(p * 2.0f) * 0.34f);
}
// HLSL mod from GLSL
private static float Mod(float x, float y)
{
return x - y * Hlsl.Floor(x / y);
return x - (y * Hlsl.Floor(x / y));
}
private float BMap(float2 p)
@@ -84,20 +84,31 @@ internal readonly partial struct PyramidPattern : IPixelShader<float4>
p -= ip + 0.5f;
float ang = -3.14159f * 3.0f / 5.0f + (FBM(ip / 8.0f + time / 3.0f)) * 6.2831f * 2.0f;
float ang = (-3.14159f * 3.0f / 5.0f) + (FBM((ip / 8.0f) + (this.time / 3.0f)) * 6.2831f * 2.0f);
float2 offs = new float2(Hlsl.Cos(ang), Hlsl.Sin(ang)) * 0.35f;
if (p.X < offs.X) p.X = 1.0f - (p.X + 0.5f) / Hlsl.Abs(offs.X + 0.5f);
else p.X = (p.X - offs.X) / (0.5f - offs.X);
if (p.X < offs.X)
{
p.X = 1.0f - ((p.X + 0.5f) / Hlsl.Abs(offs.X + 0.5f));
}
else
{
p.X = (p.X - offs.X) / (0.5f - offs.X);
}
if (p.Y < offs.Y) p.Y = 1.0f - (p.Y + 0.5f) / Hlsl.Abs(offs.Y + 0.5f);
else p.Y = (p.Y - offs.Y) / (0.5f - offs.Y);
if (p.Y < offs.Y)
{
p.Y = 1.0f - ((p.Y + 0.5f) / Hlsl.Abs(offs.Y + 0.5f));
}
else
{
p.Y = (p.Y - offs.Y) / (0.5f - offs.Y);
}
return 1.0f - Hlsl.Max(p.X, p.Y);
}
// Standard function-based bump mapping function, with an edge value included for good measure
private float3 DoBumpMap(in float2 p, in float3 n, float bumpfactor, ref float edge)
{
@@ -109,26 +120,28 @@ internal readonly partial struct PyramidPattern : IPixelShader<float4>
float fx2 = BMap(p + e.XY);
float fy2 = BMap(p + e.YX);
float3 grad = (new float3(fx - fx2, fy - fx2, 0)) / e.X / 2.0f;
float3 grad = new float3(fx - fx2, fy - fx2, 0) / e.X / 2.0f;
edge = Hlsl.Length(new float2(fx, fy) + new float2(fx2, fy2) - f * 2.0f);
edge = Hlsl.Length(new float2(fx, fy) + new float2(fx2, fy2) - (f * 2.0f));
edge = Hlsl.SmoothStep(0.0f, 1.0f, edge / e.X);
grad -= n * Hlsl.Dot(n, grad);
return Hlsl.Normalize(n + grad * bumpfactor);
return Hlsl.Normalize(n + (grad * bumpfactor));
}
// A hatch-like algorithm, or a stipple... or some kind of textured pattern
private float DoHatch(float2 p, float res)
{
p *= res / 16.0f;
float hatch = Hlsl.Clamp(Hlsl.Sin((p.X - p.Y) * 3.14159f * 200.0f) * 2.0f + 0.5f, 0.0f, 1.0f);
float hatch = Hlsl.Clamp((Hlsl.Sin((p.X - p.Y) * 3.14159f * 200.0f) * 2.0f) + 0.5f, 0.0f, 1.0f);
float hRnd = Hash21(Hlsl.Floor(p * 6.0f) + 0.73f);
if (hRnd > 0.66f) hatch = hRnd;
if (hRnd > 0.66f)
{
hatch = hRnd;
}
return hatch;
}
@@ -138,10 +151,10 @@ internal readonly partial struct PyramidPattern : IPixelShader<float4>
{
int2 coordinate = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y);
float iRes = Hlsl.Min(DispatchSize.Y, 800.0f);
float2 uv = (coordinate - (float2)DispatchSize.XY * 0.5f) / iRes;
float2 uv = (coordinate - ((float2)DispatchSize.XY * 0.5f)) / iRes;
float3 rd = Hlsl.Normalize(new float3(uv, 0.5f));
const float gSc = 10.0f;
float2 p = uv * gSc + new float2(0, time / 2.0f);
float2 p = (uv * gSc) + new float2(0, this.time / 2.0f);
float2 oP = p;
float m = BMap(p);
float3 n = new(0, 0, -1);
@@ -150,7 +163,7 @@ internal readonly partial struct PyramidPattern : IPixelShader<float4>
n = DoBumpMap(p, n, bumpFactor, ref edge);
float3 lp = new float3(-0.0f + Hlsl.Sin(time) * 0.3f, 0.0f + Hlsl.Cos(time * 1.3f) * 0.3f, -1) - new float3(uv, 0);
float3 lp = new float3(-0.0f + (Hlsl.Sin(this.time) * 0.3f), 0.0f + (Hlsl.Cos(this.time * 1.3f) * 0.3f), -1) - new float3(uv, 0);
float lDist = Hlsl.Max(Hlsl.Length(lp), 0.001f);
float3 ld = lp / lDist;
float diff = Hlsl.Max(Hlsl.Dot(n, ld), 0.0f);
@@ -159,20 +172,20 @@ internal readonly partial struct PyramidPattern : IPixelShader<float4>
float spec = Hlsl.Pow(Hlsl.Max(Hlsl.Dot(Hlsl.Reflect(-ld, n), -rd), 0.0f), 16.0f);
float fre = Hlsl.Min(Hlsl.Pow(Hlsl.Max(1.0f + Hlsl.Dot(n, rd), 0.0f), 4.0f), 3.0f);
float3 col = 0.15f * (diff + 0.251f + spec * new float3(1, 0.7f, 0.3f) * 9.0f + fre * new float3(0.1f, 0.3f, 1) * 12.0f);
float rf = Hlsl.SmoothStep(0.0f, 0.35f, BMap(Hlsl.Reflect(rd, n).XY * 2.0f) * FBM(Hlsl.Reflect(rd, n).XY * 3.0f) + 0.1f);
float3 col = 0.15f * (diff + 0.251f + (spec * new float3(1, 0.7f, 0.3f) * 9.0f) + (fre * new float3(0.1f, 0.3f, 1) * 12.0f));
float rf = Hlsl.SmoothStep(0.0f, 0.35f, (BMap(Hlsl.Reflect(rd, n).XY * 2.0f) * FBM(Hlsl.Reflect(rd, n).XY * 3.0f)) + 0.1f);
col += col * col * rf * rf * new float3(1, 0.1f, 0.1f) * 15.0f;
float shade = m * 0.83f + 0.17f;
float shade = (m * 0.83f) + 0.17f;
col *= shade;
col *= 1.0f - edge * 0.8f;
col *= 1.0f - (edge * 0.8f);
float hatch = DoHatch(oP / gSc, iRes);
col *= hatch * 0.5f + 0.7f;
col *= (hatch * 0.5f) + 0.7f;
return new(Hlsl.Sqrt(Hlsl.Max(col, 0.0f)), 1);
}
}
}
+70 -42
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.SwapChain.Shaders;
namespace ComputeSharp.SwapChain.Shaders;
/// <summary>
/// Utilizing a 2D simplex grid to construct the isolines of a noise function.
@@ -14,7 +14,7 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
/// <summary>
/// The current time Hlsl.Since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
// Standard 2D rotation formula.
private static float2x2 Rotate2x2(in float a)
@@ -38,14 +38,14 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
p = Hlsl.Frac(new float2(262144, 32768) * n);
return Hlsl.Sin(p * 6.2831853f + time);
return Hlsl.Sin((p * 6.2831853f) + this.time);
}
// Based on IQ's gradient noise formula.
private float N2D3G(float2 p)
{
float2 i = Hlsl.Floor(p);
p -= i;
float4 v = default;
@@ -55,16 +55,15 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
v.Z = Hlsl.Dot(Hash22(i + float2.UnitY), p - float2.UnitY);
v.W = Hlsl.Dot(Hash22(i + 1.0f), p - 1.0f);
p = p * p * p * (p * (p * 6.0f - 15.0f) + 10.0f);
p = p * p * p * ((p * ((p * 6.0f) - 15.0f)) + 10.0f);
return Hlsl.Lerp(Hlsl.Lerp(v.X, v.Y, p.X), Hlsl.Lerp(v.Z, v.W, p.X), p.Y);
}
// The isofunction. Just a Hlsl.Single noise function, but it can be more elaborate.
private float IsoFunction(in float2 p)
{
return N2D3G(p / 4.0f + 0.07f);
return N2D3G((p / 4.0f) + 0.07f);
}
// Unsigned distance to the segment joining "a" and "b".
@@ -74,11 +73,11 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
float h = Hlsl.Clamp(Hlsl.Dot(a, b) / Hlsl.Dot(b, b), 0.0f, 1.0f);
return Hlsl.Length(a - b * h);
return Hlsl.Length(a - (b * h));
}
// Based on IQ's signed distance to the segment joining "a" and "b".
private static float distEdge(float2 a, float2 b)
private static float DistEdge(float2 a, float2 b)
{
return Hlsl.Dot((a + b) * 0.5f, Hlsl.Normalize((b - a).YX * new float2(-1, 1)));
}
@@ -86,7 +85,7 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
// Interpolating along the edge connecting vertices v1 and v2 with respect to the isovalue.
private static float2 Interpolate(in float2 p1, in float2 p2, float v1, float v2, float isovalue)
{
return Hlsl.Lerp(p1, p2, (isovalue - v1) / (v2 - v1) * 0.75f + 0.25f / 2.0f);
return Hlsl.Lerp(p1, p2, ((isovalue - v1) / (v2 - v1) * 0.75f) + (0.25f / 2.0f));
}
// Isoline function.
@@ -105,9 +104,20 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
int iTh = 0;
if (n3.X > isovalue) iTh += 4;
if (n3.Y > isovalue) iTh += 2;
if (n3.Z > isovalue) iTh += 1;
if (n3.X > isovalue)
{
iTh += 4;
}
if (n3.Y > isovalue)
{
iTh += 2;
}
if (n3.Z > isovalue)
{
iTh += 1;
}
if (iTh == 1 || iTh == 6)
{
@@ -130,7 +140,7 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
if (iTh >= 4 && iTh <= 6)
{
float2 tmp = p0;
p0 = p1;
p1 = tmp;
}
@@ -138,7 +148,7 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
if (i == 0.0f)
{
float2 tmp = p0;
p0 = p1;
p1 = tmp;
}
@@ -154,11 +164,11 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
float2 oP = p;
p += new float2(N2D3G(p * 3.5f), N2D3G(p * 3.5f + 7.3f)) * 0.015f;
p += new float2(N2D3G(p * 3.5f), N2D3G((p * 3.5f) + 7.3f)) * 0.015f;
float2 s = Hlsl.Floor(p + (p.X + p.Y) * 0.36602540378f);
float2 s = Hlsl.Floor(p + ((p.X + p.Y) * 0.36602540378f));
p -= s - (s.X + s.Y) * 0.211324865f;
p -= s - ((s.X + s.Y) * 0.211324865f);
float i = p.X < p.Y ? 1.0f : 0.0f;
float2 ioffs = new(1.0f - i, i);
@@ -188,14 +198,14 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
float2 p1 = default;
int iTh = IsoLine(n3, ip0, ip1, ip2, isovalue, i, ref p0, ref p1);
d = Hlsl.Min(d, distEdge(p - p0, p - p1));
d = Hlsl.Min(d, DistEdge(p - p0, p - p1));
if (iTh == 7)
{
d = 0;
}
d3 = Hlsl.Min(d3, DistLine((p - p0), (p - p1)));
d3 = Hlsl.Min(d3, DistLine(p - p0, p - p1));
d4 = Hlsl.Min(d4, Hlsl.Min(Hlsl.Length(p - p0), Hlsl.Length(p - p1)));
float tri = Hlsl.Min(Hlsl.Min(DistLine(p - ip0, p - ip1), DistLine(p - ip1, p - ip2)), DistLine(p - ip2, p - ip0));
@@ -206,15 +216,20 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
int iTh2 = IsoLine(n3, ip0, ip1, ip2, isovalue, i, ref p0, ref p1);
d2 = Hlsl.Min(d2, distEdge(p - p0, p - p1));
d2 = Hlsl.Min(d2, DistEdge(p - p0, p - p1));
float oldD2 = d2;
if (iTh2 == 7)
{
d2 = 0.0f;
}
if (iTh2 == 7) d2 = 0.0f;
if (iTh == 7) d2 = 1e5f;
if (iTh == 7)
{
d2 = 1e5f;
}
d2 = Hlsl.Max(d2, -d);
d3 = Hlsl.Min(d3, DistLine((p - p0), (p - p1)));
d3 = Hlsl.Min(d3, DistLine(p - p0, p - p1));
d4 = Hlsl.Min(d4, Hlsl.Min(Hlsl.Length(p - p0), Hlsl.Length(p - p1)));
d4 -= 0.075f;
d3 -= 0.0125f;
@@ -227,35 +242,48 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
float3 col = new(1, 0.85f, 0.6f);
float sf = 0.004f;
if (d > 0.0f && d2 > 0.0f) col = new float3(1, 1.8f, 3) * 0.45f;
if (d > 0.0f) col = Hlsl.Lerp(col, new float3(1, 1.85f, 3) * 0.3f, (1.0f - Hlsl.SmoothStep(0.0f, sf, d2 - 0.012f)));
if (d > 0.0f && d2 > 0.0f)
{
col = new float3(1, 1.8f, 3) * 0.45f;
}
col = Hlsl.Lerp(col, new float3(1.1f, 0.85f, 0.6f), (1.0f - Hlsl.SmoothStep(0.0f, sf, d2)));
col = Hlsl.Lerp(col, new float3(1.5f, 0.9f, 0.6f) * 0.6f, (1.0f - Hlsl.SmoothStep(0.0f, sf, d - 0.012f)));
col = Hlsl.Lerp(col, new float3(1, 0.8f, 0.6f) * new float3(0.7f, 1.0f, 0.75f) * 0.95f, (1.0f - Hlsl.SmoothStep(0.0f, sf, d)));
if (d > 0.0f)
{
col = Hlsl.Lerp(col, new float3(1, 1.85f, 3) * 0.3f, 1.0f - Hlsl.SmoothStep(0.0f, sf, d2 - 0.012f));
}
if (d2 > 0.0f) col *= (Hlsl.Abs(Hlsl.Dot(n3, float3.One)) * 1.25f + 1.25f) / 2.0f;
else col *= Hlsl.Max(2.0f - (Hlsl.Dot(n3, float3.One) + 1.45f) / 1.25f, 0.0f);
col = Hlsl.Lerp(col, new float3(1.1f, 0.85f, 0.6f), 1.0f - Hlsl.SmoothStep(0.0f, sf, d2));
col = Hlsl.Lerp(col, new float3(1.5f, 0.9f, 0.6f) * 0.6f, 1.0f - Hlsl.SmoothStep(0.0f, sf, d - 0.012f));
col = Hlsl.Lerp(col, new float3(1, 0.8f, 0.6f) * new float3(0.7f, 1.0f, 0.75f) * 0.95f, 1.0f - Hlsl.SmoothStep(0.0f, sf, d));
float pat = Hlsl.Abs(Hlsl.Frac(tri * 12.5f + 0.4f) - 0.5f) * 2.0f;
if (d2 > 0.0f)
{
col *= ((Hlsl.Abs(Hlsl.Dot(n3, float3.One)) * 1.25f) + 1.25f) / 2.0f;
}
else
{
col *= Hlsl.Max(2.0f - ((Hlsl.Dot(n3, float3.One) + 1.45f) / 1.25f), 0.0f);
}
col *= pat * 0.425f + 0.75f;
float pat = Hlsl.Abs(Hlsl.Frac((tri * 12.5f) + 0.4f) - 0.5f) * 2.0f;
col *= (pat * 0.425f) + 0.75f;
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sf, d5)) * 0.95f);
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sf, d3)));
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sf, d4)));
col = Hlsl.Lerp(col, float3.One, (1.0f - Hlsl.SmoothStep(0.0f, sf, d4 + 0.005f)));
col = Hlsl.Lerp(col, float3.Zero, 1.0f - Hlsl.SmoothStep(0.0f, sf, d3));
col = Hlsl.Lerp(col, float3.Zero, 1.0f - Hlsl.SmoothStep(0.0f, sf, d4));
col = Hlsl.Lerp(col, float3.One, 1.0f - Hlsl.SmoothStep(0.0f, sf, d4 + 0.005f));
float2 q = oP * 1.5f;
col = Hlsl.Min(col, 1.0f);
float gr = Hlsl.Sqrt(Hlsl.Dot(col, new float3(0.299f, 0.587f, 0.114f))) * 1.25f;
float ns = (N2D3G(q * 4.0f * new float2(1.0f / 3.0f, 3)) * 0.64f + N2D3G(q * 8.0f * new float2(1.0f / 3.0f, 3)) * 0.34f) * 0.5f + 0.5f;
float ns = (((N2D3G(q * 4.0f * new float2(1.0f / 3.0f, 3)) * 0.64f) + (N2D3G(q * 8.0f * new float2(1.0f / 3.0f, 3)) * 0.34f)) * 0.5f) + 0.5f;
ns = gr - ns;
q = Hlsl.Mul(q, Rotate2x2(3.14159f / 3.0f));
float ns2 = (N2D3G(q * 4.0f * new float2(1.0f / 3.0f, 3)) * 0.64f + N2D3G(q * 8.0f * new float2(1.0f / 3.0f, 3)) * 0.34f) * 0.5f + 0.5f;
float ns2 = (((N2D3G(q * 4.0f * new float2(1.0f / 3.0f, 3)) * 0.64f) + (N2D3G(q * 8.0f * new float2(1.0f / 3.0f, 3)) * 0.34f)) * 0.5f) + 0.5f;
ns2 = gr - ns2;
ns = Hlsl.SmoothStep(0.0f, 1.0f, Hlsl.Min(ns, ns2));
@@ -268,8 +296,8 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
public float4 Execute()
{
int2 coordinate = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y);
float2 uv = (coordinate - (float2)DispatchSize.XY * 0.5f) / Hlsl.Min(650.0f, DispatchSize.Y);
float2 p = Hlsl.Mul(Rotate2x2(3.14159f / 12.0f), uv) + new float2(0.8660254f, 0.5f) * time / 16.0f;
float2 uv = (coordinate - ((float2)DispatchSize.XY * 0.5f)) / Hlsl.Min(650.0f, DispatchSize.Y);
float2 p = Hlsl.Mul(Rotate2x2(3.14159f / 12.0f), uv) + (new float2(0.8660254f, 0.5f) * this.time / 16.0f);
float3 col = SimplexContour(p);
uv = coordinate / (float2)DispatchSize.XY;
@@ -277,4 +305,4 @@ internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
return new(Hlsl.Sqrt(Hlsl.Max(col, 0.0f)), 1);
}
}
}
+15 -15
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.SwapChain.Shaders;
namespace ComputeSharp.SwapChain.Shaders;
/// <summary>
/// A shader creating an animated two-tiles Truchet arrangement.
@@ -14,7 +14,7 @@ internal readonly partial struct TwoTiledTruchet : IPixelShader<float4>
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
/// <summary>
/// Calculates the Truchet distance field.
@@ -33,7 +33,7 @@ internal readonly partial struct TwoTiledTruchet : IPixelShader<float4>
// HLSL's port of the GLSL mod intrinsic
static float Mod(float x, float y)
{
return x - y * Hlsl.Floor(x / y);
return x - (y * Hlsl.Floor(x / y));
}
float2 ip2 = Hlsl.Floor(p / 2.0f);
@@ -106,7 +106,7 @@ internal readonly partial struct TwoTiledTruchet : IPixelShader<float4>
ang *= 2.0f;
}
ang = Hlsl.Frac(ang + time / 4.0f);
ang = Hlsl.Frac(ang + (this.time / 4.0f));
return d;
}
@@ -114,28 +114,28 @@ internal readonly partial struct TwoTiledTruchet : IPixelShader<float4>
/// <inheritdoc/>
public float4 Execute()
{
float2 uv = (ThreadIds.XY - (float2)DispatchSize.XY * 0.5f) / DispatchSize.Y;
float2 uv = (ThreadIds.XY - ((float2)DispatchSize.XY * 0.5f)) / DispatchSize.Y;
float gSc = 7.0f;
float2 p = uv * gSc - new float2(-1, -0.5f) * time / 2.0f;
float2 p = (uv * gSc) - (new float2(-1, -0.5f) * this.time / 2.0f);
float sf = 2.0f / DispatchSize.Y * gSc;
float lSc = 6.0f;
float lw = 1.0f / lSc / gSc;
float2 d = DistanceField(p, out float2 ang) - 2.5f / lSc;
float2 d = DistanceField(p, out float2 ang) - (2.5f / lSc);
float3 col = new(1.0f, 0.9f, 0.8f);
for (int i = 0; i < 2; i++)
{
float di = d[i] - lw / 4.0f;
float tracks = Hlsl.Clamp(Hlsl.Sin(ang[i] * 6.2831f + time * 6.0f) * 4.0f, 0.0f, 1.0f);
float di = d[i] - (lw / 4.0f);
float tracks = Hlsl.Clamp(Hlsl.Sin((ang[i] * 6.2831f) + (this.time * 6.0f)) * 4.0f, 0.0f, 1.0f);
float gap = 1.0f + lw;
col = Hlsl.Lerp(col, 0, (1.0f - Hlsl.SmoothStep(0.0f, sf * 6.0f, di)) * 0.35f);
col = Hlsl.Lerp(col, 0, 1.0f - Hlsl.SmoothStep(0.0f, sf, di));
col = Hlsl.Lerp(col, new(1.0f, 0.9f, 0.8f), 1.0f - Hlsl.SmoothStep(0.0f, sf, di + lw * 2.0f));
col = Hlsl.Lerp(col, 0, 1.0f - Hlsl.SmoothStep(0.0f, sf, di + gap / lSc));
col = Hlsl.Lerp(col, 1, 1.0f - Hlsl.SmoothStep(0.0f, sf, di + gap / lSc + lw));
col = Hlsl.Lerp(col, 0, 1.0f - Hlsl.SmoothStep(0.0f, sf, di + 2.0f * gap / lSc));
col = Hlsl.Lerp(col, 1 * tracks, 1.0f - Hlsl.SmoothStep(0.0f, sf, di + 2.0f * gap / lSc + lw));
col = Hlsl.Lerp(col, new(1.0f, 0.9f, 0.8f), 1.0f - Hlsl.SmoothStep(0.0f, sf, di + (lw * 2.0f)));
col = Hlsl.Lerp(col, 0, 1.0f - Hlsl.SmoothStep(0.0f, sf, di + (gap / lSc)));
col = Hlsl.Lerp(col, 1, 1.0f - Hlsl.SmoothStep(0.0f, sf, di + (gap / lSc) + lw));
col = Hlsl.Lerp(col, 0, 1.0f - Hlsl.SmoothStep(0.0f, sf, di + (2.0f * gap / lSc)));
col = Hlsl.Lerp(col, 1 * tracks, 1.0f - Hlsl.SmoothStep(0.0f, sf, di + (2.0f * gap / lSc) + lw));
}
float3 rgb = Hlsl.Sqrt(Hlsl.Max(col, 0.0f));
@@ -143,4 +143,4 @@ internal readonly partial struct TwoTiledTruchet : IPixelShader<float4>
return color;
}
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
#if !DEBUG
#if !DEBUG
using System;
using System.Diagnostics;
using System.Reflection;
@@ -112,4 +112,4 @@ sealed partial class App : Application
coreTitleBar.ExtendViewIntoTitleBar = true;
}
}
}
+7 -58
ファイルの表示
@@ -3,7 +3,7 @@
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
<ProjectGuid>{FBD388A5-7855-4408-98FF-E689F509DB5A}</ProjectGuid>
<OutputType>AppContainerExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
@@ -18,58 +18,14 @@
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WindowsXamlEnableOverview>true</WindowsXamlEnableOverview>
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
<AppxBundlePlatforms>x64;ARM64</AppxBundlePlatforms>
<NoWarn>$(NoWarn);IDE0240</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<NoWarn>$(NoWarn);2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>ARM64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
@@ -81,7 +37,7 @@
<OutputPath>bin\ARM64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<NoWarn>$(NoWarn);2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
@@ -93,7 +49,7 @@
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<NoWarn>$(NoWarn);2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
@@ -104,7 +60,7 @@
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<NoWarn>$(NoWarn);2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
@@ -252,11 +208,4 @@
<PropertyGroup>
<PreBuildEvent>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(SolutionDir)\build\CreateBlankAppCenterToken.ps1</PreBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System.IO;
using System.IO;
using System.Reflection;
using CommunityToolkit.Diagnostics;
@@ -41,4 +41,4 @@ public static class AssemblyExtensions
return false;
}
}
}
}
+1 -1
ファイルの表示
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+1 -1
ファイルの表示
@@ -1,4 +1,4 @@
namespace System.Runtime.CompilerServices;
namespace System.Runtime.CompilerServices;
/// <summary>
/// Used to indicate to the compiler that the <c>.locals init</c> flag should not be set in method headers.
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using ComputeSharp.SwapChain.Core.Services;
@@ -58,4 +58,4 @@ public sealed class AppCenterService : IAnalyticsService
: $"|{text.Substring(text.Length - PropertyStringMaxLength)}";
});
}
}
}
+8 -8
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using CommunityToolkit.Mvvm.DependencyInjection;
using ComputeSharp.SwapChain.Core.Constants;
using ComputeSharp.SwapChain.Core.Services;
@@ -31,8 +31,8 @@ public sealed partial class MainView : UserControl
{
Ioc.Default.GetRequiredService<IAnalyticsService>().Log(Event.OpenShaderSelectionPanel);
Root.Resources.Remove("ShaderSelectionPanel");
Root.Children.Add(ShaderSelectionPanel);
_ = this.Root.Resources.Remove("ShaderSelectionPanel");
this.Root.Children.Add(this.ShaderSelectionPanel);
}
// Hides the shader selection panel
@@ -40,13 +40,13 @@ public sealed partial class MainView : UserControl
{
Ioc.Default.GetRequiredService<IAnalyticsService>().Log(Event.CloseShaderSelectionPanel);
Root.Children.Remove(ShaderSelectionPanel);
_ = this.Root.Children.Remove(this.ShaderSelectionPanel);
}
// Updates the size of the shaders list panel
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
{
ShadersListContainerPanel.Height = Math.Round(e.NewSize.Height * 0.35);
this.ShadersListContainerPanel.Height = Math.Round(e.NewSize.Height * 0.35);
}
// Logs rendering failed in the main panel
@@ -54,7 +54,7 @@ public sealed partial class MainView : UserControl
{
Ioc.Default.GetRequiredService<IAnalyticsService>().Log(args.Exception, (nameof(Error), Error.RenderingFailedOnMainPanel));
RenderingErrorInfoBar.IsOpen = true;
this.RenderingErrorInfoBar.IsOpen = true;
}
// Logs rendering failed in a secondary panel
@@ -62,6 +62,6 @@ public sealed partial class MainView : UserControl
{
Ioc.Default.GetRequiredService<IAnalyticsService>().Log(args.Exception, (nameof(Error), Error.RenderingFailedOnSelectionPanel));
RenderingErrorInfoBar.IsOpen = true;
this.RenderingErrorInfoBar.IsOpen = true;
}
}
}
+11 -8
ファイルの表示
@@ -1,8 +1,10 @@
using System;
using System;
using System.Threading;
using ComputeSharp.SwapChain.WinUI.Views;
using Microsoft.UI.Xaml;
#pragma warning disable CA1001, IDE0052
namespace ComputeSharp.SwapChain.WinUI;
/// <summary>
@@ -27,25 +29,26 @@ public sealed partial class App : Application
/// </summary>
public App()
{
this.InitializeComponent();
InitializeComponent();
}
/// <inheritdoc/>
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
mainWindow = new MainWindow();
mainWindow.Closed += (_, _) =>
this.mainWindow = new MainWindow();
this.mainWindow.Closed += (_, _) =>
{
// Due to an issue (https://discord.com/channels/372137812037730304/663434534087426129/979543152853663744), the WinUI 3 app
// will keep running after the window is closed if any render thread is still going. To work around this, each loaded shader
// panel is tracked in a conditional weak table, and then when the window is closed they're all manually stopped by setting
// their shader runners to null. After this, the app should just be able to close automatically when the panels are done.
mainWindow.OnShutdown();
this.mainWindow.OnShutdown();
// For good measure, also start a timer of one second. If the app is still alive by then (ie. if the timer callback is
// executed at all), then just force the whole process to terminate, and exit with the E_APPLICATION_EXITING error code.
shutdownTimer = new Timer(_ => Environment.Exit(unchecked((int)(0x8000001A))), this, 1000, Timeout.Infinite);
this.shutdownTimer = new Timer(_ => Environment.Exit(unchecked((int)0x8000001A)), this, 1000, Timeout.Infinite);
};
mainWindow.Activate();
this.mainWindow.Activate();
}
}
}
+2 -1
ファイルの表示
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
@@ -11,6 +11,7 @@
<UseWinUI>true</UseWinUI>
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
<DefineConstants>$(DefineConstants);SAMPLE_APP</DefineConstants>
<NoWarn>$(NoWarn);IDE0240</NoWarn>
</PropertyGroup>
<ItemGroup>
+11 -11
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.CompilerServices;
using ComputeSharp.SwapChain.Core.Services;
using ComputeSharp.SwapChain.Core.ViewModels;
@@ -23,24 +23,24 @@ public sealed partial class MainWindow : Window
this.InitializeComponent();
this.ExtendsContentIntoTitleBar = true;
SetTitleBar(TitleBarRectangle);
SetTitleBar(this.TitleBarRectangle);
Root.DataContext = new MainViewModel(new DebugAnalyticsService());
this.Root.DataContext = new MainViewModel(new DebugAnalyticsService());
}
/// <summary>
/// Gets the <see cref="MainViewModel"/> instance for the current view.
/// </summary>
public MainViewModel ViewModel => (MainViewModel)Root.DataContext;
public MainViewModel ViewModel => (MainViewModel)this.Root.DataContext;
/// <summary>
/// Stops all rendering when the application is closing.
/// </summary>
public void OnShutdown()
{
ShaderPanel.ShaderRunner = null;
this.ShaderPanel.ShaderRunner = null;
foreach (var (panel, _) in this.shaderPanels)
foreach ((AnimatedComputeShaderPanel panel, object _) in this.shaderPanels)
{
panel.ShaderRunner = null;
}
@@ -49,20 +49,20 @@ public sealed partial class MainWindow : Window
// Opens the shader selection panel
private void OpenShaderSelectionPanelButton_Click(object sender, RoutedEventArgs e)
{
Root.Resources.Remove("ShaderSelectionPanel");
Root.Children.Add(ShaderSelectionPanel);
_ = this.Root.Resources.Remove("ShaderSelectionPanel");
this.Root.Children.Add(this.ShaderSelectionPanel);
}
// Hides the shader selection panel
private void ShaderSelectionPanel_Tapped(object sender, TappedRoutedEventArgs e)
{
Root.Children.Remove(ShaderSelectionPanel);
_ = this.Root.Children.Remove(this.ShaderSelectionPanel);
}
// Updates the size of the shaders list panel
private void UserControl_SizeChanged(object sender, WindowSizeChangedEventArgs e)
{
ShadersListContainerPanel.Height = Math.Round(e.Size.Height * 0.35);
this.ShadersListContainerPanel.Height = Math.Round(e.Size.Height * 0.35);
}
// Tracks the current panel
@@ -70,4 +70,4 @@ public sealed partial class MainWindow : Window
{
this.shaderPanels.AddOrUpdate((AnimatedComputeShaderPanel)sender, null);
}
}
}
+23 -23
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using ComputeSharp.Interop;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
@@ -100,7 +100,7 @@ internal sealed class SwapChainApplication<T> : Win32Application
d3D12CommandQueueDesc.Flags = D3D12_COMMAND_QUEUE_FLAGS.D3D12_COMMAND_QUEUE_FLAG_NONE;
d3D12CommandQueueDesc.NodeMask = 0;
_ = d3D12Device.Get()->CreateCommandQueue(
_ = this.d3D12Device.Get()->CreateCommandQueue(
&d3D12CommandQueueDesc,
Windows.__uuidof<ID3D12CommandQueue>(),
(void**)d3D12CommandQueue);
@@ -136,7 +136,7 @@ internal sealed class SwapChainApplication<T> : Win32Application
dxgiSwapChainDesc1.SwapEffect = DXGI_SWAP_EFFECT.DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
_ = dxgiFactory2.Get()->CreateSwapChainForHwnd(
(IUnknown*)d3D12CommandQueue.Get(),
(IUnknown*)this.d3D12CommandQueue.Get(),
hwnd,
&dxgiSwapChainDesc1,
null,
@@ -147,7 +147,7 @@ internal sealed class SwapChainApplication<T> : Win32Application
// Create the command allocator to use
fixed (ID3D12CommandAllocator** d3D12CommandAllocator = this.d3D12CommandAllocator)
{
this.d3D12Device.Get()->CreateCommandAllocator(
_ = this.d3D12Device.Get()->CreateCommandAllocator(
D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT,
Windows.__uuidof<ID3D12CommandAllocator>(),
(void**)d3D12CommandAllocator);
@@ -156,17 +156,17 @@ internal sealed class SwapChainApplication<T> : Win32Application
// Create the reusable command list to copy data to the back buffers
fixed (ID3D12GraphicsCommandList** d3D12GraphicsCommandList = this.d3D12GraphicsCommandList)
{
this.d3D12Device.Get()->CreateCommandList(
_ = this.d3D12Device.Get()->CreateCommandList(
0,
D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT,
d3D12CommandAllocator,
this.d3D12CommandAllocator,
null,
Windows.__uuidof<ID3D12GraphicsCommandList>(),
(void**)d3D12GraphicsCommandList);
}
// Close the command list to prepare it for future use
this.d3D12GraphicsCommandList.Get()->Close();
_ = this.d3D12GraphicsCommandList.Get()->Close();
}
/// <inheritdoc/>
@@ -180,10 +180,10 @@ internal sealed class SwapChainApplication<T> : Win32Application
/// </summary>
private unsafe void ApplyResize()
{
this.d3D12CommandQueue.Get()->Signal(this.d3D12Fence.Get(), this.nextD3D12FenceValue);
_ = this.d3D12CommandQueue.Get()->Signal(this.d3D12Fence.Get(), this.nextD3D12FenceValue);
// Wait for the fence again to ensure there are no pending operations
this.d3D12Fence.Get()->SetEventOnCompletion(this.nextD3D12FenceValue, default);
_ = this.d3D12Fence.Get()->SetEventOnCompletion(this.nextD3D12FenceValue, default);
this.nextD3D12FenceValue++;
@@ -192,7 +192,7 @@ internal sealed class SwapChainApplication<T> : Win32Application
this.d3D12Resource1.Dispose();
// Resize the swap chain buffers
this.dxgiSwapChain1.Get()->ResizeBuffers(0, 0, 0, DXGI_FORMAT.DXGI_FORMAT_UNKNOWN, 0);
_ = this.dxgiSwapChain1.Get()->ResizeBuffers(0, 0, 0, DXGI_FORMAT.DXGI_FORMAT_UNKNOWN, 0);
// Get the index of the initial back buffer
using (ComPtr<IDXGISwapChain3> dxgiSwapChain3 = default)
@@ -206,8 +206,8 @@ internal sealed class SwapChainApplication<T> : Win32Application
fixed (ID3D12Resource** d3D12Resource0 = this.d3D12Resource0)
fixed (ID3D12Resource** d3D12Resource1 = this.d3D12Resource1)
{
_ = dxgiSwapChain1.Get()->GetBuffer(0, Windows.__uuidof<ID3D12Resource>(), (void**)d3D12Resource0);
_ = dxgiSwapChain1.Get()->GetBuffer(1, Windows.__uuidof<ID3D12Resource>(), (void**)d3D12Resource1);
_ = this.dxgiSwapChain1.Get()->GetBuffer(0, Windows.__uuidof<ID3D12Resource>(), (void**)d3D12Resource0);
_ = this.dxgiSwapChain1.Get()->GetBuffer(1, Windows.__uuidof<ID3D12Resource>(), (void**)d3D12Resource1);
}
this.texture?.Dispose();
@@ -249,8 +249,8 @@ internal sealed class SwapChainApplication<T> : Win32Application
this.currentBufferIndex ^= 1;
// Reset the command list and command allocator
this.d3D12CommandAllocator.Get()->Reset();
this.d3D12GraphicsCommandList.Get()->Reset(this.d3D12CommandAllocator.Get(), null);
_ = this.d3D12CommandAllocator.Get()->Reset();
_ = this.d3D12GraphicsCommandList.Get()->Reset(this.d3D12CommandAllocator.Get(), null);
D3D12_RESOURCE_BARRIER* d3D12ResourceBarriers = stackalloc D3D12_RESOURCE_BARRIER[]
{
@@ -265,10 +265,10 @@ internal sealed class SwapChainApplication<T> : Win32Application
};
// Transition the resources to COPY_DEST and COPY_SOURCE respectively
d3D12GraphicsCommandList.Get()->ResourceBarrier(2, d3D12ResourceBarriers);
this.d3D12GraphicsCommandList.Get()->ResourceBarrier(2, d3D12ResourceBarriers);
// Copy the generated frame to the target back buffer
d3D12GraphicsCommandList.Get()->CopyResource(d3D12ResourceBackBuffer, d3D12Resource.Get());
this.d3D12GraphicsCommandList.Get()->CopyResource(d3D12ResourceBackBuffer, d3D12Resource.Get());
d3D12ResourceBarriers[0] = D3D12_RESOURCE_BARRIER.InitTransition(
d3D12Resource.Get(),
@@ -281,22 +281,22 @@ internal sealed class SwapChainApplication<T> : Win32Application
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COMMON);
// Transition the resources back to COMMON and UNORDERED_ACCESS respectively
d3D12GraphicsCommandList.Get()->ResourceBarrier(2, d3D12ResourceBarriers);
this.d3D12GraphicsCommandList.Get()->ResourceBarrier(2, d3D12ResourceBarriers);
d3D12GraphicsCommandList.Get()->Close();
_ = this.d3D12GraphicsCommandList.Get()->Close();
// Execute the command list to perform the copy
this.d3D12CommandQueue.Get()->ExecuteCommandLists(1, (ID3D12CommandList**)d3D12GraphicsCommandList.GetAddressOf());
this.d3D12CommandQueue.Get()->Signal(this.d3D12Fence.Get(), this.nextD3D12FenceValue);
this.d3D12CommandQueue.Get()->ExecuteCommandLists(1, (ID3D12CommandList**)this.d3D12GraphicsCommandList.GetAddressOf());
_ = this.d3D12CommandQueue.Get()->Signal(this.d3D12Fence.Get(), this.nextD3D12FenceValue);
// Present the new frame
this.dxgiSwapChain1.Get()->Present(0, 0);
_ = this.dxgiSwapChain1.Get()->Present(0, 0);
if (this.nextD3D12FenceValue > this.d3D12Fence.Get()->GetCompletedValue())
{
this.d3D12Fence.Get()->SetEventOnCompletion(this.nextD3D12FenceValue, default);
_ = this.d3D12Fence.Get()->SetEventOnCompletion(this.nextD3D12FenceValue, default);
}
this.nextD3D12FenceValue++;
}
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using TerraFX.Interop.Windows;
namespace ComputeSharp.SwapChain.Backend;
@@ -24,4 +24,4 @@ internal abstract class Win32Application
/// </summary>
/// <param name="time">The current time since the start of the application.</param>
public abstract void OnUpdate(TimeSpan time);
}
}
+51 -18
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Reflection;
@@ -11,7 +11,7 @@ namespace ComputeSharp.SwapChain.Backend;
/// <summary>
/// A helper class to manage the creation and execution of Win32 applications.
/// </summary>
internal unsafe static class Win32ApplicationRunner
internal static unsafe class Win32ApplicationRunner
{
/// <summary>
/// Whether or not a resize operation is in progress.
@@ -185,6 +185,7 @@ internal unsafe static class Win32ApplicationRunner
{
isPaused = false;
}
return 0;
}
@@ -196,11 +197,11 @@ internal unsafe static class Win32ApplicationRunner
if (isPaused)
{
Windows.SetCapture(hwnd);
_ = Windows.SetCapture(hwnd);
}
else
{
Windows.ReleaseCapture();
_ = Windows.ReleaseCapture();
}
isPaused = !isPaused;
@@ -229,7 +230,7 @@ internal unsafe static class Win32ApplicationRunner
// Size update
case WM.WM_SIZE:
{
if (!isResizing && wParam != (byte)Windows.SIZE_MINIMIZED)
if (!isResizing && wParam != Windows.SIZE_MINIMIZED)
{
application.OnResize();
}
@@ -252,36 +253,68 @@ internal unsafe static class Win32ApplicationRunner
_ = Windows.GetCursorPos(&point);
_ = Windows.GetWindowRect(hwnd, &rect);
bool isAtTop = Math.Abs(point.y - rect.top) < 12;
bool isAtRight = Math.Abs(point.x - rect.right) < 12;
bool isAtBottom = Math.Abs(point.y - rect.bottom) < 12;
bool isAtLeft = Math.Abs(point.x - rect.left) < 12;
bool isAtTop = Math.Abs(point.y - rect.top) < 12;
bool isAtRight = Math.Abs(point.x - rect.right) < 12;
bool isAtBottom = Math.Abs(point.y - rect.bottom) < 12;
bool isAtLeft = Math.Abs(point.x - rect.left) < 12;
if (isAtTop)
{
if (isAtRight) return Windows.HTTOPRIGHT;
if (isAtLeft) return Windows.HTTOPLEFT;
if (isAtRight)
{
return Windows.HTTOPRIGHT;
}
if (isAtLeft)
{
return Windows.HTTOPLEFT;
}
return Windows.HTTOP;
}
if (isAtRight)
{
if (isAtTop) return Windows.HTTOPRIGHT;
if (isAtBottom) return Windows.HTBOTTOMRIGHT;
if (isAtTop)
{
return Windows.HTTOPRIGHT;
}
if (isAtBottom)
{
return Windows.HTBOTTOMRIGHT;
}
return Windows.HTRIGHT;
}
if (isAtBottom)
{
if (isAtRight) return Windows.HTBOTTOMRIGHT;
if (isAtLeft) return Windows.HTBOTTOMLEFT;
if (isAtRight)
{
return Windows.HTBOTTOMRIGHT;
}
if (isAtLeft)
{
return Windows.HTBOTTOMLEFT;
}
return Windows.HTBOTTOM;
}
if (isAtLeft)
{
if (isAtTop) return Windows.HTTOPLEFT;
if (isAtBottom) return Windows.HTBOTTOMLEFT;
if (isAtTop)
{
return Windows.HTTOPLEFT;
}
if (isAtBottom)
{
return Windows.HTBOTTOMLEFT;
}
return Windows.HTLEFT;
}
@@ -312,4 +345,4 @@ internal unsafe static class Win32ApplicationRunner
return Windows.DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
}
}
+4 -4
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Runtime.CompilerServices;
using ComputeSharp.SwapChain.Backend;
@@ -48,7 +48,7 @@ class Program
}
Console.WriteLine($"{Samples.Length}+: Exit (Use Escape, 'Q', or Alt + F4 to exit a sample once chosen)");
Console.WriteLine();
Console.WriteLine();
do
{
@@ -61,7 +61,7 @@ class Program
Console.WriteLine();
Console.WriteLine($"Starting {Samples[index].ShaderName}...");
Win32ApplicationRunner.Run(Samples[index].Application);
_ = Win32ApplicationRunner.Run(Samples[index].Application);
}
}
while (index >= 0 && index < Samples.Length);
@@ -78,4 +78,4 @@ class Program
return GraphicsDevice.GetDefault().LoadReadOnlyTexture2D<Rgba32, float4>(filename);
}
}
}
@@ -1,4 +1,4 @@
namespace System.Runtime.CompilerServices;
namespace System.Runtime.CompilerServices;
/// <summary>
/// Indicates which arguments to a method involving an interpolated string handler should be passed to that handler.
@@ -11,14 +11,20 @@ public sealed class InterpolatedStringHandlerArgumentAttribute : Attribute
/// </summary>
/// <param name="argument">The name of the argument that should be passed to the handler.</param>
/// <remarks><see langword="null"/> may be used as the name of the receiver in an instance method.</remarks>
public InterpolatedStringHandlerArgumentAttribute(string argument) => Arguments = new string[] { argument };
public InterpolatedStringHandlerArgumentAttribute(string argument)
{
Arguments = new string[] { argument };
}
/// <summary>
/// Initializes a new instance of the <see cref="InterpolatedStringHandlerArgumentAttribute"/> class.
/// </summary>
/// <param name="arguments">The names of the arguments that should be passed to the handler.</param>
/// <remarks><see langword="null"/> may be used as the name of the receiver in an instance method.</remarks>
public InterpolatedStringHandlerArgumentAttribute(params string[] arguments) => Arguments = arguments;
public InterpolatedStringHandlerArgumentAttribute(params string[] arguments)
{
Arguments = arguments;
}
/// <summary>
/// Gets the names of the arguments that should be passed to the handler.
@@ -1,4 +1,4 @@
namespace System.Runtime.CompilerServices;
namespace System.Runtime.CompilerServices;
/// <summary>
/// Indicates the attributed type is to be used as an interpolated string handler.
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.ComponentModel;
@@ -12,4 +12,4 @@ namespace System.Runtime.CompilerServices;
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit
{
}
}
+5 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.InteropServices;
namespace ComputeSharp.Core.NetStandard.System.Runtime.CompilerServices;
@@ -14,5 +14,8 @@ internal static class RuntimeHelpers
/// <param name="type">The type to associate the memory to.</param>
/// <param name="size">The size in byte of the memory to allocate.</param>
/// <returns>A pointer to the allocated memory.</returns>
public static IntPtr AllocateTypeAssociatedMemory(Type type, int size) => Marshal.AllocHGlobal(size);
public static IntPtr AllocateTypeAssociatedMemory(Type type, int size)
{
return Marshal.AllocHGlobal(size);
}
}
@@ -1,4 +1,4 @@
namespace System.Runtime.CompilerServices;
namespace System.Runtime.CompilerServices;
/// <summary>
/// Used to indicate to the compiler that the <c>.locals init</c>
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using System.Text;
using ComputeSharp.Core.SourceGenerators.Models;
using ComputeSharp.SourceGeneration.Extensions;
@@ -145,4 +145,4 @@ public sealed class AutoConstructorGenerator : IIncrementalGenerator
return hierarchyInfo.GetSyntax(constructorDeclaration.AddAttributeLists(attributes));
}
}
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System.IO;
using System.IO;
using System.Reflection;
using Microsoft.CodeAnalysis;
@@ -25,4 +25,4 @@ public sealed class GlobalUsingDirectivesGenerator : IIncrementalGenerator
context.AddSource("GlobalUsingDirectives.g.cs", globalUsingDirectives);
});
}
}
}
+9 -3
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
@@ -14,10 +14,16 @@ namespace ComputeSharp.Core.SourceGenerators.Models;
internal sealed record ConstructorInfo(ImmutableArray<ParameterInfo> Parameters, ImmutableArray<string> DefaultedFields)
{
/// <inheritdoc/>
public bool Equals(ConstructorInfo? obj) => Comparer.Default.Equals(this, obj);
public bool Equals(ConstructorInfo? obj)
{
return Comparer.Default.Equals(this, obj);
}
/// <inheritdoc/>
public override int GetHashCode() => Comparer.Default.GetHashCode(this);
public override int GetHashCode()
{
return Comparer.Default.GetHashCode(this);
}
/// <summary>
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="ConstructorInfo"/>.
+2 -2
ファイルの表示
@@ -1,8 +1,8 @@
namespace ComputeSharp.Core.SourceGenerators.Models;
namespace ComputeSharp.Core.SourceGenerators.Models;
/// <summary>
/// A model describing info on a constructor parameter.
/// </summary>
/// <param name="Type">The fully qualified type name.</param>
/// <param name="Name">The parameter name.</param>
internal sealed record ParameterInfo(string Type, string Name);
internal sealed record ParameterInfo(string Type, string Name);
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
namespace ComputeSharp;
@@ -8,4 +8,4 @@ namespace ComputeSharp;
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
public sealed class AutoConstructorAttribute : Attribute
{
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp;
namespace ComputeSharp;
/// <summary>
/// Indicates the behavior of fields annotated with <see cref="AutoConstructorBehaviorAttribute"/>.
@@ -9,4 +9,4 @@ internal enum AutoConstructorBehavior
/// Causes <see cref="AutoConstructorAttribute"/> to ignore fields and set their values to <see langword="default"/>.
/// </summary>
IgnoreAndSetToDefault
}
}
+1 -1
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
namespace ComputeSharp;
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
namespace ComputeSharp.Exceptions;
@@ -15,4 +15,4 @@ public sealed class InvalidExecutionContextException : InvalidOperationException
: base($"The API {name} can only be used from within an HLSL shader.")
{
}
}
}
+37 -33
ファイルの表示
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Buffers;
@@ -61,10 +61,10 @@ internal ref struct FormatInterpolatedStringHandler
{
this.format = format;
this.formatProvider = formatProvider;
characters = initialBuffer;
arrayToReturnToPool = null;
position = 0;
hasCustomFormatter = formatProvider is not null && HasCustomFormatter(formatProvider);
this.characters = initialBuffer;
this.arrayToReturnToPool = null;
this.position = 0;
this.hasCustomFormatter = formatProvider is not null && HasCustomFormatter(formatProvider);
}
/// <summary>
@@ -96,11 +96,11 @@ internal ref struct FormatInterpolatedStringHandler
public string ToStringAndClear()
{
#if NET6_0_OR_GREATER
string result = new(characters.Slice(0, position));
string result = new(this.characters.Slice(0, this.position));
#else
string result = characters.Slice(0, position).ToString();
string result = this.characters.Slice(0, this.position).ToString();
#endif
char[]? toReturn = arrayToReturnToPool;
char[]? toReturn = this.arrayToReturnToPool;
this = default;
@@ -121,26 +121,27 @@ internal ref struct FormatInterpolatedStringHandler
{
if (value.Length == 1)
{
Span<char> chars = characters;
int pos = position;
Span<char> chars = this.characters;
int pos = this.position;
if ((uint)pos < (uint)chars.Length)
{
chars[pos] = value[0];
position = pos + 1;
this.position = pos + 1;
}
else
{
GrowThenCopyString(value);
}
return;
}
if (value.Length == 2)
{
Span<char> chars = characters;
int pos = position;
Span<char> chars = this.characters;
int pos = this.position;
if ((uint)pos < chars.Length - 1)
{
@@ -152,12 +153,13 @@ internal ref struct FormatInterpolatedStringHandler
Unsafe.ReadUnaligned<int>(ref Unsafe.As<char, byte>(ref MemoryMarshal.GetReference(value.AsSpan()))));
#endif
position = pos + 2;
this.position = pos + 2;
}
else
{
GrowThenCopyString(value);
}
return;
}
@@ -171,12 +173,12 @@ internal ref struct FormatInterpolatedStringHandler
private void AppendStringDirect(string value)
{
#if NET6_0_OR_GREATER
if (value.TryCopyTo(characters.Slice(position)))
if (value.TryCopyTo(this.characters.Slice(this.position)))
#else
if (value.AsSpan().TryCopyTo(characters.Slice(position)))
if (value.AsSpan().TryCopyTo(this.characters.Slice(this.position)))
#endif
{
position += value.Length;
this.position += value.Length;
}
else
{
@@ -204,23 +206,23 @@ internal ref struct FormatInterpolatedStringHandler
where T : IFormattable
#endif
{
if (hasCustomFormatter)
if (this.hasCustomFormatter)
{
AppendCustomFormatter(value, format);
AppendCustomFormatter(value, this.format);
return;
}
#if NET6_0_OR_GREATER
int charsWritten;
while (!value.TryFormat(characters.Slice(position), out charsWritten, format, formatProvider))
while (!value.TryFormat(this.characters.Slice(this.position), out charsWritten, this.format, this.formatProvider))
{
Grow();
}
position += charsWritten;
this.position += charsWritten;
#else
AppendStringDirect(value.ToString(format, formatProvider));
AppendStringDirect(value.ToString(this.format, this.formatProvider));
#endif
}
@@ -243,9 +245,9 @@ internal ref struct FormatInterpolatedStringHandler
[MethodImpl(MethodImplOptions.NoInlining)]
private void AppendCustomFormatter<T>(T value, string? format)
{
ICustomFormatter? formatter = (ICustomFormatter?)formatProvider?.GetFormat(typeof(ICustomFormatter));
ICustomFormatter? formatter = (ICustomFormatter?)this.formatProvider?.GetFormat(typeof(ICustomFormatter));
if (formatter is not null && formatter.Format(format, value, formatProvider) is string customFormatted)
if (formatter is not null && formatter.Format(format, value, this.formatProvider) is string customFormatted)
{
AppendStringDirect(customFormatted);
}
@@ -261,12 +263,12 @@ internal ref struct FormatInterpolatedStringHandler
Grow(value.Length);
#if NET6_0_OR_GREATER
value.CopyTo(characters.Slice(position));
value.CopyTo(this.characters.Slice(this.position));
#else
value.AsSpan().CopyTo(characters.Slice(position));
value.AsSpan().CopyTo(this.characters.Slice(this.position));
#endif
position += value.Length;
this.position += value.Length;
}
/// <summary>
@@ -275,17 +277,19 @@ internal ref struct FormatInterpolatedStringHandler
[MethodImpl(MethodImplOptions.NoInlining)]
private void Grow(int additionalChars)
{
GrowCore((uint)position + (uint)additionalChars);
GrowCore((uint)this.position + (uint)additionalChars);
}
#if NET6_0_OR_GREATER
/// <summary>
/// Grows the size of <see cref="characters"/>.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
private void Grow()
{
GrowCore((uint)characters.Length + 1);
GrowCore((uint)this.characters.Length + 1);
}
#endif
/// <summary>
/// Grow the size of <see cref="characters"/> to at least the specified <paramref name="requiredMinCapacity"/>.
@@ -293,7 +297,7 @@ internal ref struct FormatInterpolatedStringHandler
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void GrowCore(uint requiredMinCapacity)
{
uint newCapacity = Math.Max(requiredMinCapacity, Math.Min((uint)characters.Length * 2, 0x3FFFFFDF));
uint newCapacity = Math.Max(requiredMinCapacity, Math.Min((uint)this.characters.Length * 2, 0x3FFFFFDF));
#if NET6_0_OR_GREATER
int arraySize = (int)Math.Clamp(newCapacity, MinimumArrayPoolLength, int.MaxValue);
#else
@@ -301,11 +305,11 @@ internal ref struct FormatInterpolatedStringHandler
#endif
char[] newArray = ArrayPool<char>.Shared.Rent(arraySize);
characters.Slice(0, position).CopyTo(newArray);
this.characters.Slice(0, this.position).CopyTo(newArray);
char[]? toReturn = arrayToReturnToPool;
char[]? toReturn = this.arrayToReturnToPool;
characters = arrayToReturnToPool = newArray;
this.characters = this.arrayToReturnToPool = newArray;
if (toReturn is not null)
{
+25 -27
ファイルの表示
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Runtime.InteropServices;
@@ -34,12 +34,12 @@ internal ref struct TryWriteFormatInterpolatedStringHandler
/// <summary>
/// The number of characters written to <see cref="destination"/>.
/// </summary>
internal int position;
private int position;
/// <summary>
/// Indicates whether all formatting operations have succeeded.
/// </summary>
internal bool success;
private bool success;
/// <summary>
/// Whether <see cref="formatProvider"/> provides an <see cref="ICustomFormatter"/>.
@@ -62,9 +62,9 @@ internal ref struct TryWriteFormatInterpolatedStringHandler
this.format = format;
this.formatAsString = null;
this.formatProvider = formatProvider;
position = 0;
success = shouldAppend = destination.Length >= literalLength;
hasCustomFormatter = formatProvider is not null && FormatInterpolatedStringHandler.HasCustomFormatter(formatProvider);
this.position = 0;
this.success = shouldAppend = destination.Length >= literalLength;
this.hasCustomFormatter = formatProvider is not null && FormatInterpolatedStringHandler.HasCustomFormatter(formatProvider);
}
/// <summary>
@@ -106,13 +106,13 @@ internal ref struct TryWriteFormatInterpolatedStringHandler
if (value.Length == 1)
{
Span<char> destination = this.destination;
int pos = position;
int pos = this.position;
if ((uint)pos < (uint)destination.Length)
{
destination[pos] = value[0];
position = pos + 1;
this.position = pos + 1;
return true;
}
@@ -123,7 +123,7 @@ internal ref struct TryWriteFormatInterpolatedStringHandler
if (value.Length == 2)
{
Span<char> destination = this.destination;
int pos = position;
int pos = this.position;
if ((uint)pos < destination.Length - 1)
{
@@ -135,7 +135,7 @@ internal ref struct TryWriteFormatInterpolatedStringHandler
Unsafe.ReadUnaligned<int>(ref Unsafe.As<char, byte>(ref MemoryMarshal.GetReference(value.AsSpan()))));
#endif
position = pos + 2;
this.position = pos + 2;
return true;
}
@@ -154,12 +154,12 @@ internal ref struct TryWriteFormatInterpolatedStringHandler
private bool AppendStringDirect(string value)
{
#if NET6_0_OR_GREATER
if (value.TryCopyTo(destination.Slice(position)))
if (value.TryCopyTo(this.destination.Slice(this.position)))
#else
if (value.AsSpan().TryCopyTo(destination.Slice(position)))
if (value.AsSpan().TryCopyTo(this.destination.Slice(this.position)))
#endif
{
position += value.Length;
this.position += value.Length;
return true;
}
@@ -177,24 +177,22 @@ internal ref struct TryWriteFormatInterpolatedStringHandler
where T : IFormattable
#endif
{
if (hasCustomFormatter)
if (this.hasCustomFormatter)
{
return AppendCustomFormatter(value, formatAsString ??= format.ToString());
return AppendCustomFormatter(value, this.formatAsString ??= this.format.ToString());
}
#if NET6_0_OR_GREATER
int charsWritten;
if (value.TryFormat(destination.Slice(position), out charsWritten, format, formatProvider))
if (value.TryFormat(this.destination.Slice(this.position), out int charsWritten, this.format, this.formatProvider))
{
position += charsWritten;
this.position += charsWritten;
return true;
}
return Fail();
#else
return AppendStringDirect(value.ToString(formatAsString ??= format.ToString(), formatProvider));
return AppendStringDirect(value.ToString(this.formatAsString ??= this.format.ToString(), this.formatProvider));
#endif
}
@@ -204,7 +202,7 @@ internal ref struct TryWriteFormatInterpolatedStringHandler
/// <param name="value">The value to write.</param>
public bool AppendFormatted(string? value)
{
if (hasCustomFormatter)
if (this.hasCustomFormatter)
{
return AppendCustomFormatter(value, format: null);
}
@@ -215,12 +213,12 @@ internal ref struct TryWriteFormatInterpolatedStringHandler
}
#if NET6_0_OR_GREATER
if (value.TryCopyTo(destination.Slice(position)))
if (value.TryCopyTo(this.destination.Slice(this.position)))
#else
if (value.AsSpan().TryCopyTo(destination.Slice(position)))
if (value.AsSpan().TryCopyTo(this.destination.Slice(this.position)))
#endif
{
position += value.Length;
this.position += value.Length;
return true;
}
@@ -236,9 +234,9 @@ internal ref struct TryWriteFormatInterpolatedStringHandler
[MethodImpl(MethodImplOptions.NoInlining)]
private bool AppendCustomFormatter<T>(T value, string? format)
{
ICustomFormatter? formatter = (ICustomFormatter?)formatProvider?.GetFormat(typeof(ICustomFormatter));
ICustomFormatter? formatter = (ICustomFormatter?)this.formatProvider?.GetFormat(typeof(ICustomFormatter));
if (formatter is not null && formatter.Format(format, value, formatProvider) is string customFormatted)
if (formatter is not null && formatter.Format(format, value, this.formatProvider) is string customFormatted)
{
return AppendStringDirect(customFormatted);
}
@@ -251,7 +249,7 @@ internal ref struct TryWriteFormatInterpolatedStringHandler
/// </summary>
private bool Fail()
{
success = false;
this.success = false;
return false;
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;
namespace ComputeSharp.Core.Intrinsics.Attributes;
@@ -28,4 +28,4 @@ internal sealed class HlslIntrinsicNameAttribute : Attribute
/// Gets whether or not matching parameters is also required to extract the name of this intrinsic.
/// </summary>
public bool RequiresParametersMatching { get; init; }
}
}
+2
ファイルの表示
@@ -1,5 +1,7 @@
using ComputeSharp.Core.Intrinsics.Attributes;
#pragma warning disable IDE0022
namespace ComputeSharp;
/// <inheritdoc cref="Hlsl"/>
+2
ファイルの表示
@@ -4,6 +4,8 @@
<#@ output extension=".g.cs"#>
using ComputeSharp.Core.Intrinsics.Attributes;
#pragma warning disable IDE0022
namespace ComputeSharp;
/// <inheritdoc cref="Hlsl"/>
+2
ファイルの表示
@@ -1,6 +1,8 @@
using ComputeSharp.Core.Intrinsics.Attributes;
using ComputeSharp.Exceptions;
#pragma warning disable IDE0022
namespace ComputeSharp;
/// <inheritdoc cref="Hlsl"/>
+2
ファイルの表示
@@ -2,6 +2,8 @@
using ComputeSharp.Core.Intrinsics.Attributes;
using ComputeSharp.Exceptions;
#pragma warning disable IDE0022
namespace ComputeSharp;
/// <inheritdoc cref="Hlsl"/>
+4 -2
ファイルの表示
@@ -1,6 +1,8 @@
using ComputeSharp.Core.Intrinsics.Attributes;
using ComputeSharp.Core.Intrinsics.Attributes;
using ComputeSharp.Exceptions;
#pragma warning disable IDE0022
namespace ComputeSharp;
/// <summary>
@@ -88,4 +90,4 @@ public static partial class Hlsl
/// </remarks>
[HlslIntrinsicName("lit")]
public static float Lit(float nDotL, float nDotH, float m) => default;
}
}
+2
ファイルの表示
@@ -1,6 +1,8 @@
using ComputeSharp.Core.Intrinsics.Attributes;
using ComputeSharp.Exceptions;
#pragma warning disable IDE0022
namespace ComputeSharp;
/// <inheritdoc cref="Hlsl"/>
+2
ファイルの表示
@@ -2,6 +2,8 @@
using ComputeSharp.Core.Intrinsics.Attributes;
using ComputeSharp.Exceptions;
#pragma warning disable IDE0022
namespace ComputeSharp;
/// <inheritdoc cref="Hlsl"/>
+9 -9
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.InteropServices;
namespace ComputeSharp;
@@ -13,7 +13,7 @@ public readonly struct Bool
/// The wrapped <see cref="int"/> value for the current instance.
/// </summary>
[FieldOffset(0)]
private readonly int Value;
private readonly int value;
/// <summary>
/// Creates a new <see cref="Bool"/> instance for a given <see cref="bool"/> value.
@@ -21,19 +21,19 @@ public readonly struct Bool
/// <param name="value">.</param>
private Bool(bool value)
{
Value = value ? 1 : 0;
this.value = value ? 1 : 0;
}
/// <inheritdoc/>
public override bool Equals(object? obj)
{
return obj is Bool x && Value == x.Value;
return obj is Bool x && this.value == x.value;
}
/// <inheritdoc/>
public override int GetHashCode()
{
return Value.GetHashCode();
return this.value.GetHashCode();
}
/// <inheritdoc/>
@@ -94,24 +94,24 @@ public readonly struct Bool
/// </summary>
/// <param name="left">The left <see cref="Bool"/> instance.</param>
/// <param name="right">The right <see cref="Bool"/> instance.</param>
public static bool operator ==(Bool left, Bool right) => left.Value == right.Value;
public static bool operator ==(Bool left, Bool right) => left.value == right.value;
/// <summary>
/// Checks whether or not two <see cref="Bool"/> instances represent a different <see cref="bool"/> value.
/// </summary>
/// <param name="left">The left <see cref="Bool"/> instance.</param>
/// <param name="right">The right <see cref="Bool"/> instance.</param>
public static bool operator !=(Bool left, Bool right) => left.Value != right.Value;
public static bool operator !=(Bool left, Bool right) => left.value != right.value;
/// <summary>
/// Converts a given <see cref="Bool"/> instance to its corresponding <see cref="bool"/> value.
/// </summary>
/// <param name="x">The input <see cref="Bool"/> instance.</param>
public static implicit operator bool(Bool x) => x.Value != 0;
public static implicit operator bool(Bool x) => x.value != 0;
/// <summary>
/// Converts a <see cref="bool"/> value to a corresponding <see cref="Bool"/> instance.
/// </summary>
/// <param name="x">The input <see cref="bool"/> value.</param>
public static implicit operator Bool(bool x) => new(x);
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable CS0660, CS0661
#pragma warning disable CS0660, CS0661
namespace ComputeSharp;
@@ -23,4 +23,4 @@ public partial struct Bool2
/// </summary>
/// <param name="x">The value to use for the components of the new <see cref="Bool2"/> instance.</param>
public static implicit operator Bool2(bool x) => new(x, x);
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable CS0660, CS0661
#pragma warning disable CS0660, CS0661
namespace ComputeSharp;
@@ -49,4 +49,4 @@ public partial struct Bool3
/// </summary>
/// <param name="x">The value to use for the components of the new <see cref="Bool3"/> instance.</param>
public static implicit operator Bool3(bool x) => new(x, x, x);
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable CS0660, CS0661
#pragma warning disable CS0660, CS0661
namespace ComputeSharp;
@@ -94,4 +94,4 @@ public partial struct Bool4
/// </summary>
/// <param name="x">The value to use for the components of the new <see cref="Bool4"/> instance.</param>
public static implicit operator Bool4(bool x) => new(x, x, x, x);
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable CS0660, CS0661
#pragma warning disable CS0660, CS0661
namespace ComputeSharp;
@@ -44,4 +44,4 @@ public partial struct Double2
/// <param name="xy">The input <see cref="Double2"/> value to cast.</param>
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
public static explicit operator Float2(Double2 xy) => default;
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable CS0660, CS0661
#pragma warning disable CS0660, CS0661
namespace ComputeSharp;
@@ -70,4 +70,4 @@ public partial struct Double3
/// <param name="xyz">The input <see cref="Double3"/> value to cast.</param>
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
public static explicit operator Float3(Double3 xyz) => default;
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable CS0660, CS0661
#pragma warning disable CS0660, CS0661
namespace ComputeSharp;
@@ -115,4 +115,4 @@ public partial struct Double4
/// <param name="xyzw">The input <see cref="Double4"/> value to cast.</param>
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
public static explicit operator Float4(Double4 xyzw) => default;
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System.Numerics;
using System.Numerics;
#pragma warning disable CS0660, CS0661
@@ -58,4 +58,4 @@ public partial struct Float2
/// <param name="xy">The input <see cref="Float2"/> value to cast.</param>
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
public static explicit operator UInt2(Float2 xy) => default;
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System.Numerics;
using System.Numerics;
#pragma warning disable CS0660, CS0661
@@ -84,4 +84,4 @@ public partial struct Float3
/// <param name="xyz">The input <see cref="Float3"/> value to cast.</param>
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
public static explicit operator UInt3(Float3 xyz) => default;
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System.Numerics;
using System.Numerics;
#pragma warning disable CS0660, CS0661
@@ -129,4 +129,4 @@ public partial struct Float4
/// <param name="xyzw">The input <see cref="Float4"/> value to cast.</param>
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
public static explicit operator UInt4(Float4 xyzw) => default;
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable CS0660, CS0661
#pragma warning disable CS0660, CS0661
namespace ComputeSharp;
@@ -44,4 +44,4 @@ public partial struct Int2
/// <param name="xy">The input <see cref="Int2"/> value to cast.</param>
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
public static implicit operator Double2(Int2 xy) => default;
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable CS0660, CS0661
#pragma warning disable CS0660, CS0661
namespace ComputeSharp;
@@ -70,4 +70,4 @@ public partial struct Int3
/// <param name="xyz">The input <see cref="Int3"/> value to cast.</param>
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
public static implicit operator Double3(Int3 xyz) => default;
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable CS0660, CS0661
#pragma warning disable CS0660, CS0661
namespace ComputeSharp;
@@ -115,4 +115,4 @@ public partial struct Int4
/// <param name="xyzw">The input <see cref="Int4"/> value to cast.</param>
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
public static implicit operator Double4(Int4 xyzw) => default;
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp;
namespace ComputeSharp;
/// <summary>
/// A type indicating a base-1 index into a matrix type. This can be used to extract references to swizzled vectors within a given matrix value.
@@ -93,4 +93,4 @@ public enum MatrixIndex
/// The fourth item in the fourth row.
/// </summary>
M44
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable CS0660, CS0661
#pragma warning disable CS0660, CS0661
namespace ComputeSharp;
@@ -44,4 +44,4 @@ public partial struct UInt2
/// <param name="xy">The input <see cref="UInt2"/> value to cast.</param>
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
public static implicit operator Double2(UInt2 xy) => default;
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable CS0660, CS0661
#pragma warning disable CS0660, CS0661
namespace ComputeSharp;
@@ -70,4 +70,4 @@ public partial struct UInt3
/// <param name="xyz">The input <see cref="UInt3"/> value to cast.</param>
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
public static implicit operator Double3(UInt3 xyz) => default;
}
}
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
#pragma warning disable CS0660, CS0661
#pragma warning disable CS0660, CS0661
namespace ComputeSharp;
@@ -115,4 +115,4 @@ public partial struct UInt4
/// <param name="xyzw">The input <see cref="UInt4"/> value to cast.</param>
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
public static implicit operator Double4(UInt4 xyzw) => default;
}
}
+1 -1
ファイルの表示
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace System.Diagnostics.CodeAnalysis;
+1 -1
ファイルの表示
@@ -1,4 +1,4 @@
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
namespace ComputeSharp.D2D1.NetStandard.System.Buffers;
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+2 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
namespace ComputeSharp.D2D1.NetStandard.System;
@@ -21,7 +21,7 @@ internal static class Math
{
return min;
}
if (value > max)
{
return max;
+5 -2
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.InteropServices;
namespace ComputeSharp.D2D1.NetStandard.System.Runtime.CompilerServices;
@@ -14,5 +14,8 @@ internal static class RuntimeHelpers
/// <param name="type">The type to associate the memory to.</param>
/// <param name="size">The size in byte of the memory to allocate.</param>
/// <returns>A pointer to the allocated memory.</returns>
public static IntPtr AllocateTypeAssociatedMemory(Type type, int size) => Marshal.AllocHGlobal(size);
public static IntPtr AllocateTypeAssociatedMemory(Type type, int size)
{
return Marshal.AllocHGlobal(size);
}
}
+1 -1
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.InteropServices;
using System.Text;
913ファイル中100ファイルを読み込みました。 変更されたファイルが多すぎるため、それ以降のファイルは表示していません。 さらに表示