Merge pull request #102 from Sergio0694/dev

ComputeSharp 2.0 initial preview
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2021-03-07 16:03:00 +01:00
コミット 95ced31298
379ファイル変更
+83579 -35538

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

+155
ファイルの表示
@@ -0,0 +1,155 @@
name: .NET
on: [push, pull_request]
jobs:
# Build the ComputeSharp project directly. This is the project that
# would be built when running any of the local samples or unit tests.
build-project:
runs-on: windows-latest
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Create local NuGet feed
run: mkdir src\ComputeSharp.Package\bin\Release
shell: cmd
- name: Build
run: dotnet build src\ComputeSharp\ComputeSharp.csproj -c Release
shell: cmd
# Run all the unit tests referencing the ComputeSharp project directly.
run-tests:
if: success()
needs: [build-project]
runs-on: windows-latest
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Create local NuGet feed
run: mkdir src\ComputeSharp.Package\bin\Release
shell: cmd
- name: Run ComputeSharp.Tests
run: dotnet test tests\ComputeSharp.Tests\ComputeSharp.Tests.csproj -v n -l "console;verbosity=detailed"
shell: cmd
- name: Run ComputeSharp.Tests.Internals
run: dotnet test tests\ComputeSharp.Tests.Internals\ComputeSharp.Tests.Internals.csproj -v n -l "console;verbosity=detailed"
shell: cmd
- name: Run ComputeSharp.Tests.Internals.SourceGenerators
run: dotnet test tests\ComputeSharp.Tests.Internals.SourceGenerators\ComputeSharp.Tests.Internals.SourceGenerators.csproj -v n -l "console;verbosity=detailed"
shell: cmd
# Run all the local samples to ensure they build and run with no errors.
run-samples:
if: success()
needs: [run-tests]
runs-on: windows-latest
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Create local NuGet feed
run: mkdir src\ComputeSharp.Package\bin\Release
shell: cmd
- name: Build ComputeSharp.Sample.Local
run: dotnet build samples\ComputeSharp.Sample.Local\ComputeSharp.Sample.Local.csproj -c Release
shell: cmd
- name: Run ComputeSharp.Sample.Local
run: dotnet samples\ComputeSharp.Sample.Local\bin\Release\net5.0\ComputeSharp.Sample.Local.dll
shell: cmd
- name: Build ComputeSharp.ImageProcessing.csproj
run: dotnet build samples\ComputeSharp.ImageProcessing\ComputeSharp.ImageProcessing.csproj -c Release
shell: cmd
- name: Run ComputeSharp.ImageProcessing.csproj
run: dotnet samples\ComputeSharp.ImageProcessing\bin\Release\net5.0\ComputeSharp.ImageProcessing.dll
shell: cmd
- name: Build ComputeSharp.Benchmark.csproj
run: dotnet build samples\ComputeSharp.Benchmark\ComputeSharp.Benchmark.csproj -c Release
shell: cmd
- name: Build ComputeSharp.SwapChain.csproj
run: dotnet build samples\ComputeSharp.SwapChain\ComputeSharp.SwapChain.csproj -c Release
shell: cmd
# Buils the .msbuildproj project to generate the NuGet package.
# This workflow also uploads the resulting package as an artifact.
build-package:
runs-on: windows-latest
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Create local NuGet feed
run: mkdir src\ComputeSharp.Package\bin\Release
shell: cmd
- name: Build
run: dotnet build src\ComputeSharp.Package\ComputeSharp.Package.msbuildproj -c Release
shell: cmd
- name: Upload package artifact
uses: actions/upload-artifact@v2
with:
name: ComputeSharp.nupkg
path: src\ComputeSharp.Package\bin\Release\*.nupkg
# Download the NuGet package generated in the previous job and use it
# to build and run the sample project referencing it. This is used as
# a test to ensure the NuGet package works in a consuming project.
verify-package:
if: success()
needs: [build-package]
runs-on: windows-latest
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Create local NuGet feed
run: mkdir src\ComputeSharp.Package\bin\Release
shell: cmd
- name: Download package artifact
uses: actions/download-artifact@v2
with:
name: ComputeSharp.nupkg
path: src\ComputeSharp.Package\bin\Release\ComputeSharp.nupkg
- name: Build ComputeSharp.Sample.NuGet
run: dotnet build samples\ComputeSharp.Sample.NuGet\ComputeSharp.Sample.NuGet.csproj -c Release
shell: cmd
- name: Run ComputeSharp.Sample.NuGet
run: dotnet samples\ComputeSharp.Sample.NuGet\bin\Release\net5.0\ComputeSharp.Sample.NuGet.dll
shell: cmd
# Run the extra tests to validate a number of build and publishing configurations.
# This is used to ensure the native dependencies can always be loaded correctly
# regardless of whether the app is shipping with R2R, self-contained, etc.
verify-libs:
if: success()
needs: [verify-package]
runs-on: windows-latest
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Create local NuGet feed
run: mkdir src\ComputeSharp.Package\bin\Release
shell: cmd
- name: Run ComputeSharp.Tests.NativeLibrariesResolver
run: dotnet test tests\ComputeSharp.Tests.NativeLibrariesResolver\ComputeSharp.Tests.NativeLibrariesResolver.csproj -v n -l "console;verbosity=detailed"
shell: cmd
+8 -3
ファイルの表示
@@ -24,6 +24,9 @@ bld/
[Oo]bj/
[Ll]og/
# Debug view types
!**/Resources/Debug
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
@@ -329,6 +332,8 @@ ASALocalRun/
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Sample bokeh blur image
**/*_bokeh.jpg
**/*_gaussian.jpg
# Sample images
samples/**/city_*.jpg
# XML docs files
src/**/ComputeSharp*.xml
+87 -41
ファイルの表示
@@ -5,20 +5,12 @@ VisualStudioVersion = 16.0.29201.188
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp", "src\ComputeSharp\ComputeSharp.csproj", "{314EB353-E7E3-4146-8111-685CC83EC1DE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Core", "src\ComputeSharp.Core\ComputeSharp.Core.csproj", "{9F9581FB-6EF7-418E-BFA5-0EFED874E980}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Graphics", "src\ComputeSharp.Graphics\ComputeSharp.Graphics.csproj", "{2499CC74-BC9A-4B30-A3B6-05F9C7BF9B34}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Shaders", "src\ComputeSharp.Shaders\ComputeSharp.Shaders.csproj", "{23AE6EED-79CD-4ADD-9A85-0148BD957D19}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Benchmark", "samples\ComputeSharp.Benchmark\ComputeSharp.Benchmark.csproj", "{34AFE6E6-9A4C-4C3F-AE69-DD3693086DAF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.ImageProcessing", "samples\ComputeSharp.ImageProcessing\ComputeSharp.ImageProcessing.csproj", "{524CC5DD-1DEE-4A30-9515-AB90965E5207}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Sample", "samples\ComputeSharp.Sample\ComputeSharp.Sample.csproj", "{7A48A85D-8866-4DED-A404-653ED09BF396}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Tests", "tests\ComputeSharp.Tests\ComputeSharp.Tests.csproj", "{E91F4D24-922A-4921-A8D7-9C45A143C45D}"
@@ -28,11 +20,35 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_SolutionItems", "_SolutionItems", "{1A9C4108-F61A-4ABE-B5CF-F524521EAE2D}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
global.json = global.json
LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.SourceGenerators", "src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj", "{EB52CB67-4162-4722-874B-44EA8DA5450E}"
EndProject
Project("{13B669BE-BB05-4DDF-9536-439F39A36129}") = "ComputeSharp.Package", "src\ComputeSharp.Package\ComputeSharp.Package.msbuildproj", "{0A6AE752-2A1D-40F8-B9E7-46B60F5321A3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{FB17EF84-9208-47AC-921F-680CB1DAD8BA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Sample.Local", "samples\ComputeSharp.Sample.Local\ComputeSharp.Sample.Local.csproj", "{7048DEEA-0A6F-46A0-B951-B682A8F1CB75}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Sample.NuGet", "samples\ComputeSharp.Sample.NuGet\ComputeSharp.Sample.NuGet.csproj", "{C423C061-64F7-4C12-8E5F-75C5351D6308}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ComputeSharp.Sample.Shared", "samples\ComputeSharp.Sample.Shared\ComputeSharp.Sample.Shared.shproj", "{8CEFC324-CA6C-4845-9AD9-70B92BD87057}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Tests.Internals.SourceGenerators", "tests\ComputeSharp.Tests.Internals.SourceGenerators\ComputeSharp.Tests.Internals.SourceGenerators.csproj", "{BBBD0ADD-F2F9-49A3-BD5E-D223F0735D8B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Tests.NativeLibrariesResolver", "tests\ComputeSharp.Tests.NativeLibrariesResolver\ComputeSharp.Tests.NativeLibrariesResolver.csproj", "{BF52326F-E415-49E6-8595-62762216762B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.SwapChain", "samples\ComputeSharp.SwapChain\ComputeSharp.SwapChain.csproj", "{E7C9247D-016B-4819-AF9F-0E9B3591E04B}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
samples\ComputeSharp.Sample.Shared\ComputeSharp.Sample.Shared.projitems*{7048deea-0a6f-46a0-b951-b682a8f1cb75}*SharedItemsImports = 5
samples\ComputeSharp.Sample.Shared\ComputeSharp.Sample.Shared.projitems*{8cefc324-ca6c-4845-9ad9-70b92bd87057}*SharedItemsImports = 13
samples\ComputeSharp.Sample.Shared\ComputeSharp.Sample.Shared.projitems*{c423c061-64f7-4c12-8e5f-75c5351d6308}*SharedItemsImports = 5
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
@@ -48,30 +64,6 @@ Global
{314EB353-E7E3-4146-8111-685CC83EC1DE}.Release|Any CPU.Build.0 = Release|Any CPU
{314EB353-E7E3-4146-8111-685CC83EC1DE}.Release|x64.ActiveCfg = Release|Any CPU
{314EB353-E7E3-4146-8111-685CC83EC1DE}.Release|x64.Build.0 = Release|Any CPU
{9F9581FB-6EF7-418E-BFA5-0EFED874E980}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F9581FB-6EF7-418E-BFA5-0EFED874E980}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F9581FB-6EF7-418E-BFA5-0EFED874E980}.Debug|x64.ActiveCfg = Debug|Any CPU
{9F9581FB-6EF7-418E-BFA5-0EFED874E980}.Debug|x64.Build.0 = Debug|Any CPU
{9F9581FB-6EF7-418E-BFA5-0EFED874E980}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F9581FB-6EF7-418E-BFA5-0EFED874E980}.Release|Any CPU.Build.0 = Release|Any CPU
{9F9581FB-6EF7-418E-BFA5-0EFED874E980}.Release|x64.ActiveCfg = Release|Any CPU
{9F9581FB-6EF7-418E-BFA5-0EFED874E980}.Release|x64.Build.0 = Release|Any CPU
{2499CC74-BC9A-4B30-A3B6-05F9C7BF9B34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2499CC74-BC9A-4B30-A3B6-05F9C7BF9B34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2499CC74-BC9A-4B30-A3B6-05F9C7BF9B34}.Debug|x64.ActiveCfg = Debug|Any CPU
{2499CC74-BC9A-4B30-A3B6-05F9C7BF9B34}.Debug|x64.Build.0 = Debug|Any CPU
{2499CC74-BC9A-4B30-A3B6-05F9C7BF9B34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2499CC74-BC9A-4B30-A3B6-05F9C7BF9B34}.Release|Any CPU.Build.0 = Release|Any CPU
{2499CC74-BC9A-4B30-A3B6-05F9C7BF9B34}.Release|x64.ActiveCfg = Release|Any CPU
{2499CC74-BC9A-4B30-A3B6-05F9C7BF9B34}.Release|x64.Build.0 = Release|Any CPU
{23AE6EED-79CD-4ADD-9A85-0148BD957D19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23AE6EED-79CD-4ADD-9A85-0148BD957D19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23AE6EED-79CD-4ADD-9A85-0148BD957D19}.Debug|x64.ActiveCfg = Debug|Any CPU
{23AE6EED-79CD-4ADD-9A85-0148BD957D19}.Debug|x64.Build.0 = Debug|Any CPU
{23AE6EED-79CD-4ADD-9A85-0148BD957D19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23AE6EED-79CD-4ADD-9A85-0148BD957D19}.Release|Any CPU.Build.0 = Release|Any CPU
{23AE6EED-79CD-4ADD-9A85-0148BD957D19}.Release|x64.ActiveCfg = Release|Any CPU
{23AE6EED-79CD-4ADD-9A85-0148BD957D19}.Release|x64.Build.0 = Release|Any CPU
{34AFE6E6-9A4C-4C3F-AE69-DD3693086DAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{34AFE6E6-9A4C-4C3F-AE69-DD3693086DAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34AFE6E6-9A4C-4C3F-AE69-DD3693086DAF}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -88,14 +80,6 @@ Global
{524CC5DD-1DEE-4A30-9515-AB90965E5207}.Release|Any CPU.Build.0 = Release|Any CPU
{524CC5DD-1DEE-4A30-9515-AB90965E5207}.Release|x64.ActiveCfg = Release|Any CPU
{524CC5DD-1DEE-4A30-9515-AB90965E5207}.Release|x64.Build.0 = Release|Any CPU
{7A48A85D-8866-4DED-A404-653ED09BF396}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7A48A85D-8866-4DED-A404-653ED09BF396}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A48A85D-8866-4DED-A404-653ED09BF396}.Debug|x64.ActiveCfg = Debug|Any CPU
{7A48A85D-8866-4DED-A404-653ED09BF396}.Debug|x64.Build.0 = Debug|Any CPU
{7A48A85D-8866-4DED-A404-653ED09BF396}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A48A85D-8866-4DED-A404-653ED09BF396}.Release|Any CPU.Build.0 = Release|Any CPU
{7A48A85D-8866-4DED-A404-653ED09BF396}.Release|x64.ActiveCfg = Release|Any CPU
{7A48A85D-8866-4DED-A404-653ED09BF396}.Release|x64.Build.0 = Release|Any CPU
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -112,6 +96,62 @@ Global
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Release|Any CPU.Build.0 = Release|Any CPU
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Release|x64.ActiveCfg = Release|Any CPU
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Release|x64.Build.0 = Release|Any CPU
{EB52CB67-4162-4722-874B-44EA8DA5450E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB52CB67-4162-4722-874B-44EA8DA5450E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB52CB67-4162-4722-874B-44EA8DA5450E}.Debug|x64.ActiveCfg = Debug|Any CPU
{EB52CB67-4162-4722-874B-44EA8DA5450E}.Debug|x64.Build.0 = Debug|Any CPU
{EB52CB67-4162-4722-874B-44EA8DA5450E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB52CB67-4162-4722-874B-44EA8DA5450E}.Release|Any CPU.Build.0 = Release|Any CPU
{EB52CB67-4162-4722-874B-44EA8DA5450E}.Release|x64.ActiveCfg = Release|Any CPU
{EB52CB67-4162-4722-874B-44EA8DA5450E}.Release|x64.Build.0 = Release|Any CPU
{0A6AE752-2A1D-40F8-B9E7-46B60F5321A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A6AE752-2A1D-40F8-B9E7-46B60F5321A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A6AE752-2A1D-40F8-B9E7-46B60F5321A3}.Debug|x64.ActiveCfg = Debug|Any CPU
{0A6AE752-2A1D-40F8-B9E7-46B60F5321A3}.Debug|x64.Build.0 = Debug|Any CPU
{0A6AE752-2A1D-40F8-B9E7-46B60F5321A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A6AE752-2A1D-40F8-B9E7-46B60F5321A3}.Release|Any CPU.Build.0 = Release|Any CPU
{0A6AE752-2A1D-40F8-B9E7-46B60F5321A3}.Release|x64.ActiveCfg = Release|Any CPU
{0A6AE752-2A1D-40F8-B9E7-46B60F5321A3}.Release|x64.Build.0 = Release|Any CPU
{7048DEEA-0A6F-46A0-B951-B682A8F1CB75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7048DEEA-0A6F-46A0-B951-B682A8F1CB75}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7048DEEA-0A6F-46A0-B951-B682A8F1CB75}.Debug|x64.ActiveCfg = Debug|Any CPU
{7048DEEA-0A6F-46A0-B951-B682A8F1CB75}.Debug|x64.Build.0 = Debug|Any CPU
{7048DEEA-0A6F-46A0-B951-B682A8F1CB75}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7048DEEA-0A6F-46A0-B951-B682A8F1CB75}.Release|Any CPU.Build.0 = Release|Any CPU
{7048DEEA-0A6F-46A0-B951-B682A8F1CB75}.Release|x64.ActiveCfg = Release|Any CPU
{7048DEEA-0A6F-46A0-B951-B682A8F1CB75}.Release|x64.Build.0 = Release|Any CPU
{C423C061-64F7-4C12-8E5F-75C5351D6308}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C423C061-64F7-4C12-8E5F-75C5351D6308}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C423C061-64F7-4C12-8E5F-75C5351D6308}.Debug|x64.ActiveCfg = Debug|Any CPU
{C423C061-64F7-4C12-8E5F-75C5351D6308}.Debug|x64.Build.0 = Debug|Any CPU
{C423C061-64F7-4C12-8E5F-75C5351D6308}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C423C061-64F7-4C12-8E5F-75C5351D6308}.Release|Any CPU.Build.0 = Release|Any CPU
{C423C061-64F7-4C12-8E5F-75C5351D6308}.Release|x64.ActiveCfg = Release|Any CPU
{C423C061-64F7-4C12-8E5F-75C5351D6308}.Release|x64.Build.0 = Release|Any CPU
{BBBD0ADD-F2F9-49A3-BD5E-D223F0735D8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BBBD0ADD-F2F9-49A3-BD5E-D223F0735D8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BBBD0ADD-F2F9-49A3-BD5E-D223F0735D8B}.Debug|x64.ActiveCfg = Debug|Any CPU
{BBBD0ADD-F2F9-49A3-BD5E-D223F0735D8B}.Debug|x64.Build.0 = Debug|Any CPU
{BBBD0ADD-F2F9-49A3-BD5E-D223F0735D8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BBBD0ADD-F2F9-49A3-BD5E-D223F0735D8B}.Release|Any CPU.Build.0 = Release|Any CPU
{BBBD0ADD-F2F9-49A3-BD5E-D223F0735D8B}.Release|x64.ActiveCfg = Release|Any CPU
{BBBD0ADD-F2F9-49A3-BD5E-D223F0735D8B}.Release|x64.Build.0 = Release|Any CPU
{BF52326F-E415-49E6-8595-62762216762B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BF52326F-E415-49E6-8595-62762216762B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF52326F-E415-49E6-8595-62762216762B}.Debug|x64.ActiveCfg = Debug|Any CPU
{BF52326F-E415-49E6-8595-62762216762B}.Debug|x64.Build.0 = Debug|Any CPU
{BF52326F-E415-49E6-8595-62762216762B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF52326F-E415-49E6-8595-62762216762B}.Release|Any CPU.Build.0 = Release|Any CPU
{BF52326F-E415-49E6-8595-62762216762B}.Release|x64.ActiveCfg = Release|Any CPU
{BF52326F-E415-49E6-8595-62762216762B}.Release|x64.Build.0 = Release|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Debug|x64.ActiveCfg = Debug|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Debug|x64.Build.0 = Debug|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|Any CPU.Build.0 = Release|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|x64.ActiveCfg = Release|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -119,9 +159,15 @@ Global
GlobalSection(NestedProjects) = preSolution
{34AFE6E6-9A4C-4C3F-AE69-DD3693086DAF} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}
{524CC5DD-1DEE-4A30-9515-AB90965E5207} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}
{7A48A85D-8866-4DED-A404-653ED09BF396} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}
{E91F4D24-922A-4921-A8D7-9C45A143C45D} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}
{0A6AE752-2A1D-40F8-B9E7-46B60F5321A3} = {FB17EF84-9208-47AC-921F-680CB1DAD8BA}
{7048DEEA-0A6F-46A0-B951-B682A8F1CB75} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}
{C423C061-64F7-4C12-8E5F-75C5351D6308} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}
{8CEFC324-CA6C-4845-9AD9-70B92BD87057} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}
{BBBD0ADD-F2F9-49A3-BD5E-D223F0735D8B} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}
{BF52326F-E415-49E6-8595-62762216762B} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}
{E7C9247D-016B-4819-AF9F-0E9B3591E04B} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4664C5E3-0340-4E22-BCFD-98AAEDF5F2DC}
+10
ファイルの表示
@@ -0,0 +1,10 @@
<Project>
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Company>Sergio Pedri</Company>
<Copyright>Copyright (c) 2021 Sergio Pedri</Copyright>
</PropertyGroup>
</Project>
+196 -80
ファイルの表示
@@ -1,23 +1,22 @@
![](https://i.imgur.com/ufWcoO6.png)
[![NuGet](https://img.shields.io/nuget/v/ComputeSharp.svg)](https://www.nuget.org/packages/ComputeSharp/) [![NuGet](https://img.shields.io/nuget/dt/ComputeSharp.svg)](https://www.nuget.org/stats/packages/ComputeSharp?groupby=Version)
## Major update in the works! 🚀
The currently available NuGet package refers to the `1.x` version of **ComputeSharp**, with the codebase from the `master` branch. I'm currently working on a new major update targeting .NET 5, featuring a completely rewritten backend using native DirectX bindings and the use of C# source generators to prepare the shader code. This will greatly improve the performance of the library (especially cold start performance, which is over **10x** faster already) and use much less memory at runtime. I also plan to introduce support for a number of new features, such as the ability to use custom struct types in shaders. The current status of this work can be seen from the development branches.
Thank you for the support!
![](https://user-images.githubusercontent.com/10199417/108635546-3512ea00-7480-11eb-8172-99bc59f4eb6f.png)
![.NET](https://github.com/Sergio0694/ComputeSharp/workflows/.NET/badge.svg) [![NuGet](https://img.shields.io/nuget/v/ComputeSharp.svg)](https://www.nuget.org/packages/ComputeSharp/) [![NuGet](https://img.shields.io/nuget/dt/ComputeSharp.svg)](https://www.nuget.org/stats/packages/ComputeSharp?groupby=Version)
# What is it?
**ComputeSharp** is a .NET Standard 2.1 library to run C# code in parallel on the GPU through DX12 and dynamically generated HLSL compute shaders. The available APIs let you allocate GPU buffers and write compute shaders as simple lambda expressions or local methods, with all the captured variables being handled automatically and passed to the running shader.
**ComputeSharp** is a .NET 5 library to run C# code in parallel on the GPU through DX12 and dynamically generated HLSL compute shaders. The available APIs let you access GPU devices, allocate GPU buffers and textures, move data between them and the RAM, write compute shaders entirely in C# and have them run on the GPU. The goal of this project is to make GPU computing easy to use for all .NET developers! 🚀
# Table of Contents
- [Installing from NuGet](#installing-from-nuget)
- [Quick start](#quick-start)
- [Capturing variables](#capturing-variables)
- [Advanced usage](#advanced-usage)
- [Capturing variables](#capturing-variables)
- [GPU resource types](#gpu-resource-types)
- [HLSL vector and matrix types](#hlsl-vector-and-matrix-types)
- [HLSL intrinsics](#hlsl-intrinsics)
- [Working with images](#working-with-images)
- [Shader metaprogramming](#shader-metaprogramming)
- [Requirements](#requirements)
- [Sponsors](#sponsors)
- [Special thanks](#special-thanks)
# Installing from NuGet
@@ -32,40 +31,52 @@ More details available [here](https://www.nuget.org/packages/ComputeSharp/).
# Quick start
**ComputeSharp** exposes a `Gpu` class that acts as entry point for all public APIs. It exposes the `Gpu.Default` property that lets you access the main GPU device on the current machine, which can be used to allocate buffers and perform operations.
**ComputeSharp** exposes a `Gpu` class that acts as entry point for all public APIs. The available `Gpu.Default` property that lets you access the main GPU device on the current machine, which can be used to allocate buffers and perform operations. If your machine doesn't have a supported GPU (or if it doesn't have a GPU at all), **ComputeSharp** will automatically create a [WARP device](https://docs.microsoft.com/windows/win32/direct3darticles/directx-warp) instead, which will still let you use the library normally, with shaders running on the CPU instead through an emulation layer. This means that you don't need to manually write a fallback path in case no GPU is available - **ComputeSharp** will automatically handle this for you.
The following sample shows how to allocate a writeable buffer, populate it with a compute shader, and read it back.
Let's suppose we want to run a simple compute shader that multiplies all items in a target buffer by two. The first step is to create the GPU buffer and copy our data to it:
```csharp
// Get some sample data
int[] array = Enumerable.Range(0, 100).ToArray();
// Allocate a GPU buffer and copy the data to it.
// We want the shader to modify the items in-place, so we
// can allocate a single read-write buffer to work on.
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer(array);
```
The `AllocateReadWriteBuffer` extension takes care of creating a `ReadWriteBuffer<T>` instance with the same size and contents of the input array. There are a number of overloads available as well, to create buffers of different types and with custom length.
Next, we need to define the GPU shader to run. To do this, we'll need to define a `struct` type implementing the `IComputeShader` interface. This type will contain the code we want to run on the GPU, as well as fields representing the values we want to capture and pass to the GPU (such as GPU resources, or arbitrary values we need). In this case, we only need to capture the buffer to work on, so the shader type will look like this:
```C#
// Define a simple shader
public readonly struct MyShader : IComputeShader
[AutoConstructor]
public readonly struct MultiplyByTwo : IComputeShader
{
public readonly ReadWriteBuffer<float> buffer;
public MyShader(ReadWriteBuffer<float> buffer)
public void Execute()
{
this.buffer = buffer;
}
public void Execute(ThreadIds ids)
{
buffer[ids.X] = ids.X;
buffer[ThreadIds.X] *= 2;
}
}
```
// Allocate a writeable buffer on the GPU, with the contents of the array
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(1000);
We're using the `[AutoConstructor]` attribute included in **ComputeSharp**, which creates a constructor for our type automatically. The shader body is also using a special `ThreadIds` class, which is one of the available special classes to access dispatch parameters from within a shader body. In this case, `ThreadIds` lets us access the current invocation index for the shader, just like if we were accessing the classic `i` variable from within a `for` loop.
// Run the shader
Gpu.Default.For(1000, new MyShader(buffer));
We can now finally run the GPU shader and copy the data back to our array:
```csharp
// Launch the shader
Gpu.Default.For(buffer.Length, new MyShader(buffer));
// Get the data back
float[] array = buffer.GetData();
buffer.CopyTo(array);
```
## Capturing variables
If the shader in C# is capturing some local variable, those will be automatically copied over to the GPU, so that the HLSL shader will be able to access them just like you'd expect. Additionally, **ComputeSharp** can also resolve static fields being used in a shader. The captured variables need to be convertible to valid HLSL types: either scalar types (`int`, `uint`, `float`, etc.) or known HLSL structs (eg. `Vector3`). Here is a list of the variable types currently supported by the library:
Shaders can store either GPU resources or custom values in their fields, so that they can be accessed when running on the GPU as well. This can be useful to pass some extra parameters to a shader (eg. some factor to multiply values by), that don't belong to a GPU buffer of their own. The captured variables need to be of a supported scalar or vector type so that they can be correctly used by the GPU shader in HLSL. Here is a list of the variable types currently supported by the library:
✅ .NET scalar types: `bool`, `int`, `uint`, `float`, `double`
@@ -73,85 +84,190 @@ If the shader in C# is capturing some local variable, those will be automaticall
✅ HLSL types: `Bool`, `Bool2`, `Bool3`, `Bool4`, `Float2`, `Float3`, `Float4`, `Int2`, `Int3`, `Int4`, `UInt2`, `Uint3`, etc.
✅ `static` fields of both scalar, vector or buffer types
✅ HLSL matrix types: `Float2x2`, `Float3x3`, `Float3x4`, `Float4x4`, `Float1x4`, `Float4x`, etc.
✅ `static` properties, same as with fields
✅ Custom `struct` types containing any of the types above, as well as other valid custom `struct` types
✅ `Func<T>`s or delegates with a valid HLSL signature, with the target method being `static`
## GPU resource types
✅ `Func<T>`s, local methods or delegates with no captured variables
There are a number of extension APIs for the `GraphicsDevice` class that can be used to allocate GPU resources. Here is a breakdown of the main resource types that are available:
✅ `static` fields and properties with a supported delegate type
- `ReadWriteBuffer<T>`: this type can be viewed as the equivalent of the `T[]` type, and can contain a writeable sequence of any of the supported types mentioned above. It is very flexible and works well in most situations. If you're just getting started with this library and are not sure about what kind of buffer to use, this is usually a good choice.
- `ReadOnlyBuffer<T>`: this type represents a sequence of items that the GPU cannot write to. It is particularly useful to declare intent from within a compute shader and to avoid accidentally writing to data that is not supposed to change during the execution of a shader.
- `ConstantBuffer<T>`: this type is meant to be used for small sequences of items that never change during the execution of a shader. Compared to `ReadOnlyBuffer<T>` is has more constraints, but can benefit from better caching on the GPU side (it is recommended to verify with proper benchmarking that this type is appropriate to use). Items within a `ConstantBuffer<T>` instance are packed to 16 bytes, which helps the GPU to have a particularly fast access time to them, but the total size of the buffer is limited to around 64KB. Copying to and from this buffer can also have additional overhead, as the GPU needs to account for the possible padding for each item (as the 16 bytes alignment is not present on the CPU side). If you're in doubt about which buffer type to use, just use either `ReadOnlyBuffer<T>` or `ReadWriteBuffer<T>`, depending on whether or not you also need write access to that buffer on the GPU side.
- `ReadOnlyTexture2D<T>` and `ReadWriteTexture2D<T>`: these types represent a 2D texture with elements of a specific type. Note that textures are not just 2D arrays, and have additional characteristics and limitations. Items in a texture are stored with a tiled layout instead of with the classic row-major order that .NET `T[,]` arrays have, and this allows them to be extremely fast when accessing small areas of neighbouring items (due to better cache locality). This can offer a big performance speedup in operations that have a similar memory access pattern, such as blur effect or convolutions in general. Textures also have limitations in the type of items they can contain (eg. custom `struct` types are not supported), and you can check if a specific type is supported at runtime with the `GraphicsDevice.IsReadOnlyTexture2DSupportedForType<T>()` and `IsReadWriteTexture2DSupportedForType<T>()` methods.
- `ReadOnlyTexture3D<T>` and `ReadWriteTexture3D<T>`: these are just like 2D textures, but in 3 dimensions. The same characteristics and limitations apply, with the addition of the fact that the depth axis has a much smaller limit on the size it can have. The `GraphicsDevice.IsReadOnlyTexture3DSupportedForType<T>()` and `IsReadWriteTexture3DSupportedForType<T>()` methods can be used to check for type support at runtime.
- `ReadOnlyTexture2D<T, TPixel>` and `ReadWriteTexture2D<T, TPixel>`: these texture types are particularly useful when doing image processing from a compute shader, as they allow the CPU to perform pixel format conversion automatically. The two type parameters indicate the type of items in a texture when exposed on the CPU side (as `T` items) or on the GPU side (as `TPixel` items). The type parameter `T` can be any of the existing pixel formats available in **ComputeSharp** (such as `Rgba32` and `Bgra32`), while the `TPixel` parameter represents the type of elements the GPU will be working with (for instance, `Float4` for `Rgba32`). These texture types have a number of benefits such as lower memory usage and reduced overhead on the CPU (as there is no need to manually do the pixel format conversion when copying data back and forth from the GPU).
- `ReadOnlyTexture3D<T, TPixel>` and `ReadWriteTexture3D<T, TPixel>`: these types are just like their 2D equivalent types, with the same support for automatic pixel format conversion on the GPU side.
- `UploadBuffer<T>`: this type can be used in more advanced scenarios where performance is particularly important. It represents a buffer that can be copied directly to a GPU buffer (such as a `ReadOnlyBuffer<T>`), without the need to create a temporary transfer buffer to do so. If there is a large number of copy operations being performed to GPU buffers, it can be beneficial to create a single `UploadBuffer<T>` instance to load data to copy to the GPU, and execute the copy from there.
- `ReadBackBuffer<T>`: this type is another advanced buffer type that is analogous to `UploadBuffer<T>`, but that can be used to copy data back from a GPU buffer. In particular, this buffer can also be accessed quickly by the GPU when reading or writing data from it, so it can also be used for further processing of data on the CPU side, without the need to copy the data onto another buffer first (such as a .NET array).
- `UploadTexture2D<T>`, `UploadTexture3D<T>`, `ReadBackTexture2D<T>` and `ReadBackTexture3D<T>`: these types are conceptually similar to `UploadBuffer<T>` and `ReadBackBuffer<T>`, with the main difference being that they can be used to copy data back and forth from 2D and 3D textures respectively.
## Allocating GPU buffers
> **NOTE:** although the various APIs to allocate buffers are simply generic methods with a `T : unmanaged` constrain, they should only be used with C# types that are supported (see notes above). Additionally, the `bool` type should not be used in buffers due to C#/HLSL differences: use the `Bool` type instead (or just an `int` buffer).
There are a number of extension APIs for the `GraphicsDevice` class that can be used to allocate GPU buffers of three types: `ConstantBuffer<T>`, `ReadOnlyBuffer<T>` and `ReadWriteBuffer<T>`. The first is packed to 16 bytes and provides the fastest possible access for buffer elements, but it has a limited maximum size (around 64KB) and requires additional overhead when copying data to and from it if the size of each element is not a multiple of 16. The other buffer types are tightly packed and work great for all kinds of operations, and can be thought of the HLSL equivalent of `T[]` arrays in C#. If you're in doubt about which buffer type to use, just use either `ReadOnlyBuffer<T>` or `ReadWriteBuffer<T>`, depending on whether or not you also need write access to that buffer on the GPU side.
## HLSL vector and matrix types
**NOTE:** although the APIs to allocate buffers are simply generic methods with a `T : unmanaged` constrain, they should only be used with C# types that are fully mapped to HLSL types. That means either `int`, `uint`, `float`, `double`, .NET vector types or HLSL types. The `bool` type should not be used in buffers due to C#/HLSL differences: use the `Bool` type instead.
As mentioned in the [Capturing variables](#capturing-variables) paragraph, **ComputeSharp** also exposes matrix types that can be used in compute shaders. These values store individual component values in row-major order (for consistency with .NET arrays) and can be indexed in several ways just like with HLSL vector types. One noticeable difference compared to HLSL vector types though is the lack of explicit properties to extract swizzled vectors (eg. `Float4.XZY` returns a `Float3` value with the `X`, `Z` and `Y` components). Due to the number of possible combinations being simply too high in the case of matrix types (eg. `Float4x4` alone would have had over 160k properties), the ability to extract swizzled vectors ([see here](https://docs.microsoft.com/windows/win32/direct3dhlsl/dx-graphics-hlsl-per-component-math)) can be achieved through the use of a special indexer property and values from the `MatrixIndex` type. Here is how it can be used:
## Advanced usage
```csharp
Float4x4 matrix = default;
**ComputeSharp** lets you dispatch compute shaders over thread groups from 1 to 3 dimensions, includes supports for constant and readonly buffers, and more. Additionally, most of the [HLSL intrinsic functions](https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-intrinsic-functions) are available through the `Hlsl` class. Here is a more advanced sample showcasing all these features.
// Standard indexer for rows and individual items
Float4 row = matrix[0];
float item = matrix[0][1];
```C#
// Define a class with some utility static functions
public static class Activations
// Swizzled indexers, which can be made less verbose to
// write by adding this using static directive to the file
using static ComputeSharp.MatrixIndex;
Float4 diagonal = matrix[M11, M22, M33, M44];
Float4 vertices = matrix[M11, M14, M44, M41];
```
Matrix types also include a number of built-in operators to work with vector types, and the `Hlsl` class detailed below (see [HLSL intrinsics](#hlsl-intrinsics)) also includes several overloads for the available methods to work on both matrix and vector types at the same time (eg. for row/matrix multiplication).
## HLSL intrinsics
**ComputeSharp** offers support for all HLSL intrinsics that can be used from compute shaders. These are special functions (usually representing mathematical operations) that are optimized on the GPU and can execute very efficiently. Some of them can be mapped automatically from methods in the `System.Math` type (such as `Math.Sin` and `Math.Cos`), but if you want to have direct access to all of them you can just use the methods in the `Hlsl` class from a compute shader, and **ComputeSharp** will rewrite all those calls to use the native intrinsics in the compute shaders where those are used.
Here's an example of a shader that applies the [softmax function](https://en.wikipedia.org/wiki/Rectifier_(neural_networks)) to all the items in a given buffer:
```csharp
[AutoConstructor]
public readonly struct SoftmaxActivation : IComputeShader
{
public static float Sigmoid(float x) => 1 / (1 + Hlsl.Exp(-x));
}
// Define the shader
public readonly struct ActivationShader : IComputeShader
{
private readonly int width;
public readonly ReadOnlyBuffer<float> x;
public readonly ReadWriteBuffer<float> y;
public ActivationShader(
int width,
ReadOnlyBuffer<float> x,
ReadWriteBuffer<float> y)
{
this.width = width;
this.x = x;
this.y = y;
}
public readonly ReadWriteBuffer<float> buffer;
public readonly float k;
public void Execute(ThreadIds ids)
{
int offset = ids.X + ids.Y * width;
float pow = Hlsl.Pow(x[offset], 2);
y[offset] = Activations.Sigmoid(pow);
float exp = Hlsl.Exp(k * buffer[ThreadIds.X]);
float log = Hlsl.Log(1 + exp);
buffer[ThreadIds.X] = log / k;
}
}
```
int height = 10, width = 10;
float[] x = new float[height * width]; // Array to sum to y
float[] y = new float[height * width]; // Result array (assume both had some values)
## Working with images
using ReadOnlyBuffer<float> xBuffer = Gpu.Default.AllocateReadOnlyBuffer(x);
using ReadWriteBuffer<float> yBuffer = Gpu.Default.AllocateReadWriteBuffer(y);
As mentioned in the [GPU resource types](#gpu-resource-types) paragraph, there are several texture types that are specialized to work on image pixels, such as `ReadWriteTexture2D<T, TPixel>`. Let's imagine we want to write a compute shader that applies some image processing filter: we will need to load an image (eg. using [ImageSharp](https://github.com/SixLabors/ImageSharp), or just the `System.Drawing` APIs) and then process it on the GPU, but without spending time on the CPU to convert pixels from a format such as RGBA32 to the normalized `float` values we want our shader to work on. We can do this by utilizing the `ReadWriteTexture2D<T, TPixel>` type as follows:
```csharp
// Load a bitmap from a specified path and then lock the pixel data.
// The locked pixels are in the BGRA32 format, which is the one we need.
var bitmap = new Bitmap("myImage.jpg");
var bitmapData = bitmap.LockBits(
new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadWrite,
PixelFormat.Format32bppArgb);
try
{
// Create a span over the locked pixel data, of type Bgra32 (from ComputeSharp)
var bitmapSpan = new Span<Bgra32>((Bgra32*)bitmapData.Scan0, bitmapData.Width * bitmapData.Height);
// Allocate a 2D texture by directly reading from the pixel data
using var texture = Gpu.Default.AllocateReadWriteTexture2D<Bgra32, Float4>(bitmapSpan, bitmap.Width, bitmap.Height);
// Run our shader on the texture we just created
Gpu.Default.For(bitmap.Width, bitmap.Height, new GaussianBlur(texture));
// When the shader has completed, copy the processed texture back
texture.CopyTo(bitmapSpan);
}
finally
{
bitmap.UnlockBits(bitmapData);
}
bitmap.Save("myImage.jpg");
```
With the compute shader being like this:
```csharp
[AutoConstructor]
public readonly partial struct GaussianBlur : IComputeShader
{
public readonly IReadWriteTexture2D<Float4> texture;
// Other captured resources or values here...
public void Execute()
{
// Our image processing logic here. In this example, we are just
// applying a naive grayscale effect to all pixels in the image.
Float3 rgb = texture[ThreadIds.XY].RGB;
float avg = Hlsl.Dot(rgb, new(0.0722f, 0.7152f, 0.2126f));
texture[ThreadIds.XY].RGB = avg;
}
}
```
> **NOTE:** this is just an example to illustrate how these texture types can help with automatic pixel format conversion. You're free to use any library of choice to load and save image data, as well as to how to structure your compute shaders representing image effects. This is just one of the infinite possible effects that could be achieved by using **ComputeSharp**.
## Shader metaprogramming
One of the reasons why **ComputeSharp** compiles shaders at runtime is that it allows it to support a number of dynamic scenarios, including shader metaprogramming. What this means is that it's possible to have a shader that captures an instance of a `Delegate` type (provided the signature matches the supported types mentioned above), and reuse it with different methods. The library will automatically run different variations of the shaders depending on what methods they are capturing. Here is an example:
```csharp
// Define a function we want to use in our shader. Captured functions
// need to be static methods annotated with [ShaderAttribute].
[ShaderMethod]
public static float Square(float x) => x * x;
[AutoConstructor]
public readonly struct ApplyFunction : IComputeShader
{
public readonly ReadWriteBuffer<float> buffer;
public readonly Func<float, float> function;
public void Execute()
{
buffer[ThreadIds.X] = function(buffer[ThreadIds.X]);
}
}
```
Then we can simply create a new `Func<float, float>` instance and use that to construct a new instance of the `ApplyFunction` type, to execute that shader on a target buffer. **ComputeSharp** will build or reuse a version of that shader with the supplied captured function and execute it on the GPU:
```csharp
float[] array = LoadSampleData();
// Allocate the buffer and copy data to it
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer(array);
// Run the shader
Gpu.Default.For(width, height, new ActivationShader(width, xBuffer, yBuffer));
Gpu.Default.For(width, height, new ApplyFunction(buffer, Square));
// Get the data back and write it to the y array
yBuffer.GetData(y);
// Copy the processed data back as usual
buffer.CopyTo(array);
```
# Requirements
The **ComputeSharp** library requires .NET Standard 2.1 support, and it is available for applications targeting:
- .NET Core >= 3.0
- Windows (x86 or x64)
The **ComputeSharp** library has the following requirements:
- .NET 5
- Windows x64
Additionally, you need an IDE with .NET Core 3.1 and C# 8.0 support to compile the library and samples on your PC.
Additionally, in order to compile the library or a project using it, you need a recent build of Visual Studio 2019 or another IDE that has support for Roslyn source generators, as **ComputeSharp** relies on this feature to create the HLSL shader sources and to extract other shader metadata that is necessary to setup and execute the code at runtime. You can learn more about source generators [here](https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/).
# Sponsors
Huge thanks to these sponsors for directly supporting my work on **ComputeSharp**, it means a lot! 🙌
<a href="https://github.com/xoofx"><img src="https://avatars.githubusercontent.com/u/715038" height="auto" width="80" style="border-radius:50%"></a>
<a href="https://github.com/sebastienros"><img src="https://avatars.githubusercontent.com/u/1165805" height="auto" width="80" style="border-radius:50%"></a>
<a href="https://github.com/hawkerm"><img src="https://avatars.githubusercontent.com/u/8959496" height="auto" width="80" style="border-radius:50%"></a>
# Special thanks
The **ComputeSharp** library is based on some of the code from the [DX12GameEngine](https://github.com/Aminator/DirectX12GameEngine) repository by [Amin Delavar](https://github.com/Aminator). Additionally, **ComputeSharp** uses NuGet packages from the following repositories (excluding those from Microsoft):
The **ComputeSharp** library was originally based on some of the code from the [DX12GameEngine](https://github.com/Aminator/DirectX12GameEngine) repository by [Amin Delavar](https://github.com/Aminator).
- [Vortice.Windows](https://github.com/amerkoleci/Vortice.Windows)
- [ILSpy](https://github.com/icsharpcode/ILSpy)
- [Stubble](https://github.com/StubbleOrg/Stubble)
Additionally, **ComputeSharp** uses NuGet packages from the following repositories:
- [Microsoft.Toolkit.Diagnostics](https://github.com/windows-toolkit/WindowsCommunityToolkit)
- [TerraFX.Interop.Windows](https://github.com/terrafx/terrafx.interop.windows)
- [TerraFX.Interop.D3D12MemoryAllocator](https://github.com/terrafx/terrafx.interop.d3d12memoryallocator)
+5
ファイルの表示
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "5.0.x"
}
}
+8
ファイルの表示
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="ComputeSharp-Local" value="src\ComputeSharp.Package\bin\Release" />
<add key="Toolkit-CI" value="https://pkgs.dev.azure.com/dotnet/WindowsCommunityToolkit/_packaging/WindowsCommunityToolkit-MainLatest/nuget/v3/index.json" />
<add key="dotnet6" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
</packageSources>
</configuration>
+162
ファイルの表示
@@ -0,0 +1,162 @@
using System;
using System.Buffers;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
namespace ComputeSharp.Benchmark.Blas
{
/// <summary>
/// A <see langword="class"/> that benchmarks the APIs in the <see cref="BlasHelpers"/> class, on both CPU and GPU.
/// </summary>
[SimpleJob(RunStrategy.Monitoring)]
public class BlasBenchmark : IDisposable
{
/// <summary>
/// The number of samples.
/// </summary>
private const int C = 128;
/// <summary>
/// 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)
/// </summary>
private const int M = 512;
/// <summary>
/// The number of columns in the <see cref="W"/> matrix.
/// </summary>
private const int P = 256;
/// <summary>
/// The input tensor.
/// </summary>
private float[]? X;
/// <summary>
/// The weights tensor.
/// </summary>
private float[]? W;
/// <summary>
/// The bias tensor.
/// </summary>
private float[]? B;
/// <summary>
/// The result tensor.
/// </summary>
private float[]? Y;
/// <summary>
/// The input tensor (GPU).
/// </summary>
private ReadOnlyBuffer<float>? BufferX;
/// <summary>
/// The weights tensor (GPU).
/// </summary>
private ReadOnlyBuffer<float>? BufferW;
/// <summary>
/// The bias tensor (GPU).
/// </summary>
private ReadOnlyBuffer<float>? BufferB;
/// <summary>
/// The result tensor (GPU).
/// </summary>
private ReadWriteBuffer<float>? BufferY;
/// <summary>
/// A <see cref="System.Random"/> instance to initialize the tensors.
/// </summary>
private readonly Random Random = new Random();
/// <summary>
/// Initial setup for a benchmarking session.
/// </summary>
[GlobalSetup]
public void Setup()
{
// Creates a new random normalized float[] array of a given size
float[] CreateRandomArray(int size)
{
float[] array = ArrayPool<float>.Shared.Rent(size);
foreach (ref float x in array.AsSpan())
{
x = (float)Random.NextDouble();
}
return array;
}
X = CreateRandomArray(C * N * M);
W = CreateRandomArray(M * P);
B = CreateRandomArray(P);
Y = CreateRandomArray(C * N * P);
BufferX = Gpu.Default.AllocateReadOnlyBuffer(X);
BufferW = Gpu.Default.AllocateReadOnlyBuffer(W);
BufferB = Gpu.Default.AllocateReadOnlyBuffer(B);
BufferY = Gpu.Default.AllocateReadWriteBuffer(Y);
Cpu();
GpuWithNoTemporaryBuffers();
GpuWithTemporaryBuffers();
}
/// <inheritdoc/>
[GlobalCleanup]
public void Dispose()
{
ArrayPool<float>.Shared.Return(X!);
ArrayPool<float>.Shared.Return(W!);
ArrayPool<float>.Shared.Return(B!);
ArrayPool<float>.Shared.Return(Y!);
BufferX!.Dispose();
BufferW!.Dispose();
BufferB!.Dispose();
BufferY!.Dispose();
}
/// <summary>
/// Runs a fully connected forward operation on the CPU.
/// </summary>
[Benchmark(Baseline = true)]
public void Cpu()
{
BlasHelpers.FullyConnectedForwardCpu(C, N, M, P, X!, W!, B!, Y!);
}
/// <summary>
/// Runs a fully connected forward operation on the GPU.
/// </summary>
[Benchmark]
public void GpuWithNoTemporaryBuffers()
{
BlasHelpers.FullyConnectedForwardGpu(Gpu.Default, C, N, M, P, BufferX!, BufferW!, BufferB!, BufferY!);
}
/// <summary>
/// Runs a fully connected forward operation on the GPU, creating temporary GPU buffers to perform the operations.
/// </summary>
[Benchmark]
public void GpuWithTemporaryBuffers()
{
using ReadOnlyBuffer<float> x = Gpu.Default.AllocateReadOnlyBuffer(X!);
using ReadOnlyBuffer<float> w = Gpu.Default.AllocateReadOnlyBuffer(W!);
using ReadOnlyBuffer<float> b = Gpu.Default.AllocateReadOnlyBuffer(B!);
using ReadWriteBuffer<float> y = Gpu.Default.AllocateReadWriteBuffer<float>(Y!.Length);
BlasHelpers.FullyConnectedForwardGpu(Gpu.Default, C, N, M, P, x, w, b, y);
y.CopyTo(Y);
}
}
}
@@ -1,24 +1,24 @@
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace ComputeSharp.Benchmark
namespace ComputeSharp.Benchmark.Blas
{
/// <summary>
/// A <see langword="class"/> that contains primitives to run certain operations of a neural network
/// A <see langword="class"/> that contains primitives to run certain operations of a neural network.
/// </summary>
internal static class Dnn
internal static partial class BlasHelpers
{
/// <summary>
/// Executes the forward pass on a fully connected layer on the CPU
/// Executes the forward pass on a fully connected layer on the CPU.
/// </summary>
/// <param name="c">The number of samples in the input tensor</param>
/// <param name="n">The number of rows in the input matrix</param>
/// <param name="m">The number of columns in the input matrix</param>
/// <param name="p">The number of columns in the output matrix</param>
/// <param name="x">The input tensor</param>
/// <param name="w">The weights tensor</param>
/// <param name="b">The bias tensor</param>
/// <param name="y">The result tensor</param>
/// <param name="c">The number of samples in the input tensor.</param>
/// <param name="n">The number of rows in the input matrix.</param>
/// <param name="m">The number of columns in the input matrix.</param>
/// <param name="p">The number of columns in the output matrix.</param>
/// <param name="x">The input tensor.</param>
/// <param name="w">The weights tensor.</param>
/// <param name="b">The bias tensor.</param>
/// <param name="y">The result tensor.</param>
public static void FullyConnectedForwardCpu(int c, int n, int m, int p, float[] x, float[] w, float[] b, float[] y)
{
void Kernel(int s)
@@ -51,69 +51,58 @@ namespace ComputeSharp.Benchmark
}
/// <summary>
/// Executes the forward pass on a fully connected layer on the GPU
/// Executes the forward pass on a fully connected layer on the GPU.
/// </summary>
/// <param name="c">The number of samples in the input tensor</param>
/// <param name="n">The number of rows in the input matrix</param>
/// <param name="m">The number of columns in the input matrix</param>
/// <param name="p">The number of columns in the output matrix</param>
/// <param name="x">The input tensor</param>
/// <param name="w">The weights tensor</param>
/// <param name="b">The bias tensor</param>
/// <param name="y">The result tensor</param>
/// <param name="device">The device to run the computation on.</param>
/// <param name="c">The number of samples in the input tensor.</param>
/// <param name="n">The number of rows in the input matrix.</param>
/// <param name="m">The number of columns in the input matrix.</param>
/// <param name="p">The number of columns in the output matrix.</param>
/// <param name="x">The input tensor.</param>
/// <param name="w">The weights tensor.</param>
/// <param name="b">The bias tensor.</param>
/// <param name="y">The result tensor.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void FullyConnectedForwardGpu(
int c, int n, int m, int p,
ReadOnlyBuffer<float> x, ReadOnlyBuffer<float> w, ReadOnlyBuffer<float> b, ReadWriteBuffer<float> y)
GraphicsDevice device,
int c,
int n,
int m,
int p,
ReadOnlyBuffer<float> x,
ReadOnlyBuffer<float> w,
ReadOnlyBuffer<float> b,
ReadWriteBuffer<float> y)
{
Gpu.Default.For(c, n, p, new FullyConnectedForwardKernel(n, m, p, x, w, b, y));
device.For(c, n, p, new FullyConnectedForwardKernel(n, m, p, x, w, b, y));
}
/// <summary>
/// Kernel for <see cref="FullyConnectedForwardGpu"/>
/// Kernel for <see cref="FullyConnectedForwardGpu"/>.
/// </summary>
private readonly struct FullyConnectedForwardKernel : IComputeShader
[AutoConstructor]
public readonly partial struct FullyConnectedForwardKernel : IComputeShader
{
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;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public FullyConnectedForwardKernel(
int n,
int m,
int p,
ReadOnlyBuffer<float> x,
ReadOnlyBuffer<float> w,
ReadOnlyBuffer<float> b,
ReadWriteBuffer<float> y)
{
this.n = n;
this.m = m;
this.p = p;
this.x = x;
this.w = w;
this.b = b;
this.y = y;
}
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;
/// <inheritdoc/>
public void Execute(ThreadIds ids)
public void Execute()
{
int x_offset = ids.X * n * p + ids.Y * m;
int x_offset = ThreadIds.X * n * p + ThreadIds.Y * m;
float result = 0f;
for (int k = 0; k < m; k++)
{
result += x[x_offset + k] * w[k * p + ids.Z];
result += x[x_offset + k] * w[k * p + ThreadIds.Z];
}
y[ids.X * n * p + ids.Y * p + ids.Z] = result + b[ids.Z];
y[ThreadIds.X * n * p + ThreadIds.Y * p + ThreadIds.Z] = result + b[ThreadIds.Z];
}
}
}
+19 -2
ファイルの表示
@@ -2,15 +2,32 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\ComputeSharp.ImageProcessing\Primitives\Complex64.cs" Link="Imaging\Primitives\Complex64.cs" />
<Compile Include="..\ComputeSharp.ImageProcessing\Processors\HlslBokehBlurProcessor.cs" Link="Imaging\Processors\HlslBokehBlurProcessor.cs" />
<Compile Include="..\ComputeSharp.ImageProcessing\Processors\HlslBokehBlurProcessor{TPixel}.cs" Link="Imaging\Processors\HlslBokehBlurProcessor{TPixel}.cs" />
<Compile Include="..\ComputeSharp.ImageProcessing\Processors\HlslGaussianBlurProcessor.cs" Link="Imaging\Processors\HlslGaussianBlurProcessor.cs" />
<Compile Include="..\ComputeSharp.ImageProcessing\Processors\HlslGaussianBlurProcessor{TPixel}.cs" Link="Imaging\Processors\HlslGaussianBlurProcessor{TPixel}.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="..\ComputeSharp.ImageProcessing\city.jpg" Link="Imaging\city.jpg" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp\ComputeSharp.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"
PrivateAssets="contentfiles;build" />
</ItemGroup>
</Project>
</Project>
-158
ファイルの表示
@@ -1,158 +0,0 @@
using System;
using System.Buffers;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
namespace ComputeSharp.Benchmark
{
/// <summary>
/// A <see langword="class"/> that benchmarks the APIs in the <see cref="Dnn"/> class, on both CPU and GPU
/// </summary>
public class DnnBenchmark : IDisposable
{
/// <summary>
/// The number of samples
/// </summary>
private const int C = 128;
/// <summary>
/// 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)
/// </summary>
private const int M = 512;
/// <summary>
/// The number of columns in the <see cref="W"/> matrix
/// </summary>
private const int P = 256;
/// <summary>
/// The input tensor
/// </summary>
private float[] X;
/// <summary>
/// The weights tensor
/// </summary>
private float[] W;
/// <summary>
/// The bias tensor
/// </summary>
private float[] B;
/// <summary>
/// The result tensor
/// </summary>
private float[] Y;
/// <summary>
/// The input tensor
/// </summary>
private ReadOnlyBuffer<float> BufferX;
/// <summary>
/// The weights tensor
/// </summary>
private ReadOnlyBuffer<float> BufferW;
/// <summary>
/// The bias tensor
/// </summary>
private ReadOnlyBuffer<float> BufferB;
/// <summary>
/// The result tensor
/// </summary>
private ReadWriteBuffer<float> BufferY;
/// <summary>
/// A <see cref="System.Random"/> instance to initialize the tensors
/// </summary>
private readonly Random Random = new Random();
/// <summary>
/// Initial setup for a benchmarking session
/// </summary>
[GlobalSetup]
public void Setup()
{
X = CreateRandomArray(C * N * M);
W = CreateRandomArray(M * P);
B = CreateRandomArray(P);
Y = CreateRandomArray(C * N * P);
BufferX = Gpu.Default.AllocateReadOnlyBuffer(X);
BufferW = Gpu.Default.AllocateReadOnlyBuffer(W);
BufferB = Gpu.Default.AllocateReadOnlyBuffer(B);
BufferY = Gpu.Default.AllocateReadWriteBuffer(Y);
}
/// <summary>
/// Clears the memory from the current session
/// </summary>
[GlobalCleanup]
public void Dispose()
{
ArrayPool<float>.Shared.Return(X);
ArrayPool<float>.Shared.Return(W);
ArrayPool<float>.Shared.Return(B);
ArrayPool<float>.Shared.Return(Y);
BufferX.Dispose();
BufferW.Dispose();
BufferB.Dispose();
BufferY.Dispose();
}
/// <summary>
/// Creates a new <see langword="float"/> array of the specified size
/// </summary>
/// <param name="size">The size of the new random array to create</param>
[Pure]
private float[] CreateRandomArray(int size)
{
float[] array = ArrayPool<float>.Shared.Rent(size);
ref float r = ref array[0];
for (int i = 0; i < size; i++)
{
Unsafe.Add(ref r, i) = (float)Random.NextDouble();
}
return array;
}
/// <summary>
/// Runs a fully connected forward operation on the CPU
/// </summary>
[Benchmark(Baseline = true)]
public void Cpu() => Dnn.FullyConnectedForwardCpu(C, N, M, P, X, W, B, Y);
/// <summary>
/// Runs a fully connected forward operation on the GPU
/// </summary>
[Benchmark]
public void GpuWithNoTemporaryBuffers() => Dnn.FullyConnectedForwardGpu(C, N, M, P, BufferX, BufferW, BufferB, BufferY);
/// <summary>
/// Runs a fully connected forward operation on the GPU, creating temporary GPU buffers to perform the operations
/// </summary>
[Benchmark]
public void GpuWithTemporaryBuffers()
{
using ReadOnlyBuffer<float> x = Gpu.Default.AllocateReadOnlyBuffer(X);
using ReadOnlyBuffer<float> w = Gpu.Default.AllocateReadOnlyBuffer(W);
using ReadOnlyBuffer<float> b = Gpu.Default.AllocateReadOnlyBuffer(B);
using ReadWriteBuffer<float> y = Gpu.Default.AllocateReadWriteBuffer(Y);
Dnn.FullyConnectedForwardGpu(C, N, M, P, x, w, b, y);
y.GetData(Y);
}
}
}
+91
ファイルの表示
@@ -0,0 +1,91 @@
using System;
using System.IO;
using System.Reflection;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Engines;
using ComputeSharp.BokehBlur.Processors;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Convolution;
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
namespace ComputeSharp.Benchmark.Imaging
{
/// <summary>
/// A <see langword="class"/> that benchmarks the image processors against the reference in ImageSharp.
/// </summary>
[SimpleJob(RunStrategy.Monitoring)]
[CategoriesColumn]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
public class ImagingBenchmark : IDisposable
{
/// <summary>
/// The loaded image.
/// </summary>
private Image<ImageSharpRgba32>? image;
/// <summary>
/// Initial setup for a benchmarking session.
/// </summary>
[GlobalSetup]
public void Setup()
{
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging", "city.jpg");
this.image = Image.Load<ImageSharpRgba32>(path);
Bokeh_Cpu();
Bokeh_Gpu();
Gaussian_Cpu();
Gaussian_Gpu();
}
/// <inheritdoc/>
[GlobalCleanup]
public void Dispose()
{
this.image!.Dispose();
}
/// <summary>
/// Runs a bokeh blur effect on the CPU.
/// </summary>
[Benchmark(Baseline = true)]
[BenchmarkCategory("BOKEH")]
public void Bokeh_Cpu()
{
this.image!.Mutate(c => c.ApplyProcessor(new BokehBlurProcessor(80, 2, 3)));
}
/// <summary>
/// Runs a bokeh blur effect on the GPU.
/// </summary>
[Benchmark]
[BenchmarkCategory("BOKEH")]
public void Bokeh_Gpu()
{
this.image!.Mutate(c => c.ApplyProcessor(new HlslBokehBlurProcessor(80, 2)));
}
/// <summary>
/// Runs a gaussian blur effect on the CPU.
/// </summary>
[Benchmark(Baseline = true)]
[BenchmarkCategory("GAUSSIAN")]
public void Gaussian_Cpu()
{
this.image!.Mutate(c => c.ApplyProcessor(new GaussianBlurProcessor(80)));
}
/// <summary>
/// Runs a gaussian blur effect on the GPU.
/// </summary>
[Benchmark]
[BenchmarkCategory("GAUSSIAN")]
public void Gaussian_Gpu()
{
this.image!.Mutate(c => c.ApplyProcessor(new HlslGaussianBlurProcessor(80)));
}
}
}
+8 -8
ファイルの表示
@@ -4,15 +4,15 @@ namespace ComputeSharp.Benchmark
{
public class Program
{
public static void Main()
public static void Main(string[] args)
{
/* =================
* BenchmarkDotNet
* ================
* In order to run this benchmark, compile this project in Release mode,
* then go to its bin\Release\netcoreapp3.0 folder, open a cmd prompt
* and type "dotnet ComputeSharp.Benchmark.dll */
BenchmarkRunner.Run<DnnBenchmark>();
// =================
// BenchmarkDotNet
// ================
// In order to run this benchmark, compile this project in Release mode,
// then go to its bin\Release\netcoreapp3.0 folder, open a cmd prompt
// and type "dotnet ComputeSharp.Benchmark.dll" to execute it.
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
}
}
}
+7 -9
ファイルの表示
@@ -2,25 +2,23 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Remove="city.jpg" />
<Content Include="city.jpg" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<Content Include="city.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp\ComputeSharp.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"
PrivateAssets="contentfiles;build"/>
</ItemGroup>
</Project>
+46
ファイルの表示
@@ -0,0 +1,46 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp
{
/// <summary>
/// Represents a complex number, where the real and imaginary parts are stored as <see cref="float"/> values.
/// </summary>
/// <remarks>
/// This is a more efficient version of the <see cref="Complex64"/> type.
/// </remarks>
internal readonly struct Complex64
{
/// <summary>
/// The real part of the complex number.
/// </summary>
public readonly float Real;
/// <summary>
/// The imaginary part of the complex number.
/// </summary>
public readonly float Imaginary;
/// <summary>
/// Initializes a new instance of the <see cref="Complex64"/> struct.
/// </summary>
/// <param name="real">The real part in the complex number.</param>
/// <param name="imaginary">The imaginary part in the complex number.</param>
public Complex64(float real, float imaginary)
{
this.Real = real;
this.Imaginary = imaginary;
}
/// <summary>
/// Performs the multiplication operation between a <see cref="Complex64"/> instance and a <see cref="float"/> scalar.
/// </summary>
/// <param name="value">The <see cref="Complex64"/> value to multiply.</param>
/// <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);
}
}
+49 -31
ファイルの表示
@@ -1,67 +1,85 @@
using SixLabors.ImageSharp;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Diagnostics;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
namespace ComputeSharp.BokehBlur.Processors
{
/// <summary>
/// Applies bokeh blur processing to the image
/// Applies bokeh blur processing to the image.
/// </summary>
public sealed class HlslBokehBlurProcessor : IImageProcessor
public sealed partial class HlslBokehBlurProcessor : IImageProcessor
{
/// <summary>
/// The default radius used by the parameterless constructor
/// The default radius used by the parameterless constructor.
/// </summary>
public const int DefaultRadius = 32;
/// <summary>
/// The default component count used by the parameterless constructor
/// The default component count used by the parameterless constructor.
/// </summary>
public const int DefaultComponents = 2;
/// <summary>
/// The default gamma used by the parameterless constructor
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor"/> class.
/// </summary>
public const float DefaultGamma = 3f;
/// <summary>
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor"/> class
/// </summary>
public HlslBokehBlurProcessor() : this(DefaultRadius, DefaultComponents, DefaultGamma) { }
/// <summary>
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor"/> class
/// </summary>
/// <param name="radius">The size of the area to sample</param>
/// <param name="components">The number of components to use to approximate the original 2D bokeh blur convolution kernel</param>
/// <param name="gamma">The gamma highlight factor to use to further process the image</param>
public HlslBokehBlurProcessor(int radius, int components, float gamma)
public HlslBokehBlurProcessor()
: this(Gpu.Default, DefaultRadius, DefaultComponents)
{
Radius = radius;
Components = components;
Gamma = gamma;
}
/// <summary>
/// Gets the radius
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor"/> class.
/// </summary>
/// <param name="radius">The size of the area to sample.</param>
/// <param name="components">The number of components to use to approximate the original 2D bokeh blur convolution kernel.</param>
public HlslBokehBlurProcessor(int radius, int components)
: this(Gpu.Default, radius, components)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor"/> class.
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
/// <param name="radius">The size of the area to sample.</param>
/// <param name="components">The number of components to use to approximate the original 2D bokeh blur convolution kernel.</param>
public HlslBokehBlurProcessor(GraphicsDevice device, int radius, int components)
{
GraphicsDevice = device;
Radius = radius;
Components = components;
}
/// <summary>
/// Gets the <see cref="ComputeSharp.GraphicsDevice"/> associated with the current instance.
/// </summary>
public GraphicsDevice GraphicsDevice { get; }
/// <summary>
/// Gets the radius.
/// </summary>
public int Radius { get; }
/// <summary>
/// Gets the number of components
/// Gets the number of components.
/// </summary>
public int Components { get; }
/// <summary>
/// Gets the gamma highlight factor to use when applying the effect
/// </summary>
public float Gamma { get; }
/// <inheritdoc/>
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : unmanaged, IPixel<TPixel>
{
return new HlslBokehBlurProcessor<TPixel>(this, configuration, source, sourceRectangle);
if (typeof(TPixel) != typeof(ImageSharpRgba32))
{
ThrowHelper.ThrowInvalidOperationException("This processor only supports the RGBA32 pixel format");
}
var processor = new Implementation(this, configuration, Unsafe.As<Image<ImageSharpRgba32>>(source), sourceRectangle);
return Unsafe.As<IImageProcessor<TPixel>>(processor);
}
}
}
+366 -503
ファイルの表示
@@ -1,563 +1,426 @@
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.Toolkit.Diagnostics;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
namespace ComputeSharp.BokehBlur.Processors
{
/// <summary>
/// Applies bokeh blur processing to the image
/// </summary>
/// <typeparam name="TPixel">The pixel format</typeparam>
/// <remarks>This processor is based on the code from Mike Pound, see <a href="https://github.com/mikepound/convolve">github.com/mikepound/convolve</a></remarks>
public sealed class HlslBokehBlurProcessor<TPixel> : ImageProcessor<TPixel>
where TPixel : unmanaged, IPixel<TPixel>
/// <inheritdoc/>
public sealed partial class HlslBokehBlurProcessor
{
/// <summary>
/// The kernel radius
/// Applies bokeh blur processing to the image.
/// </summary>
private readonly int Radius;
/// <summary>
/// The gamma highlight factor to use when applying the effect
/// </summary>
private readonly float Gamma;
/// <summary>
/// The maximum size of the kernel in either direction
/// </summary>
private readonly int KernelSize;
/// <summary>
/// The number of components to use when applying the bokeh blur
/// </summary>
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;
/// <summary>
/// The kernel components for the current instance
/// </summary>
private readonly Vector2[][] Kernels;
/// <summary>
/// The scaling factor for kernel values
/// </summary>
private readonly float KernelsScale;
/// <summary>
/// The mapping of initialized complex kernels and parameters, to speed up the initialization of new <see cref="HlslBokehBlurProcessor{TPixel}"/> instances
/// </summary>
private static readonly ConcurrentDictionary<(int Radius, int ComponentsCount), (Vector4[] Parameters, float Scale, Vector2[][] Kernels)> Cache = new ConcurrentDictionary<(int, int), (Vector4[], float, Vector2[][])>();
/// <summary>
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor{TPixel}"/> class
/// </summary>
/// <param name="definition">The <see cref="HlslBokehBlurProcessor"/> defining the processor parameters</param>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> instance to modify</param>
/// <param name="sourceRectangle">The source <see cref="Rectangle"/> that indicates the area to edit</param>
public HlslBokehBlurProcessor(HlslBokehBlurProcessor definition, Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle)
/// <remarks>This processor is based on the code from Mike Pound, see <a href="https://github.com/mikepound/convolve">github.com/mikepound/convolve</a>.</remarks>
public sealed partial class Implementation : ImageProcessor<ImageSharpRgba32>
{
Radius = definition.Radius;
KernelSize = Radius * 2 + 1;
ComponentsCount = definition.Components;
Gamma = definition.Gamma;
/// <summary>
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
/// </summary>
private readonly GraphicsDevice GraphicsDevice;
// Reuse the initialized values from the cache, if possible
var parameters = (Radius, ComponentsCount);
if (Cache.TryGetValue(parameters, out var info))
/// <summary>
/// The kernel radius.
/// </summary>
private readonly int Radius;
/// <summary>
/// The maximum size of the kernel in either direction.
/// </summary>
private readonly int KernelSize;
/// <summary>
/// The number of components to use when applying the bokeh blur.
/// </summary>
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;
/// <summary>
/// The kernel components for the current instance.
/// </summary>
private readonly Complex64[][] Kernels;
/// <summary>
/// The scaling factor for kernel values.
/// </summary>
private readonly float KernelsScale;
/// <summary>
/// The mapping of initialized complex kernels and parameters, to speed up the initialization of new <see cref="HlslBokehBlurProcessor{TPixel}"/> instances.
/// </summary>
private static readonly ConcurrentDictionary<(int Radius, int ComponentsCount), (Vector4[] Parameters, float Scale, Complex64[][] Kernels)> Cache = new();
/// <summary>
/// Initializes a new instance of the <see cref="Implementation"/> class.
/// </summary>
/// <param name="definition">The <see cref="HlslBokehBlurProcessor"/> defining the processor parameters.</param>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> instance to modify.</param>
/// <param name="sourceRectangle">The source <see cref="Rectangle"/> that indicates the area to edit.</param>
public Implementation(HlslBokehBlurProcessor definition, Configuration configuration, Image<ImageSharpRgba32> source, Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle)
{
KernelParameters = info.Parameters;
KernelsScale = info.Scale;
Kernels = info.Kernels;
}
else
{
// Initialize the complex kernels and parameters with the current arguments
(KernelParameters, KernelsScale) = GetParameters();
Kernels = CreateComplexKernels();
NormalizeKernels();
GraphicsDevice = definition.GraphicsDevice;
Radius = definition.Radius;
KernelSize = Radius * 2 + 1;
ComponentsCount = definition.Components;
// Store them in the cache for future use
Cache.TryAdd(parameters, (KernelParameters, KernelsScale, Kernels));
}
}
/// <summary>
/// Gets the kernel scales to adjust the component values in each kernel
/// </summary>
private static IReadOnlyList<float> KernelScales { get; } = new[] { 1.4f, 1.2f, 1.2f, 1.2f, 1.2f, 1.2f };
/// <summary>
/// Gets the available bokeh blur kernel parameters
/// </summary>
private static IReadOnlyList<Vector4[]> KernelComponents { get; } = new[]
{
// 1 component
new[] { new Vector4(0.862325f, 1.624835f, 0.767583f, 1.862321f) },
// 2 components
new[]
{
new Vector4(0.886528f, 5.268909f, 0.411259f, -0.548794f),
new Vector4(1.960518f, 1.558213f, 0.513282f, 4.56111f)
},
// 3 components
new[]
{
new Vector4(2.17649f, 5.043495f, 1.621035f, -2.105439f),
new Vector4(1.019306f, 9.027613f, -0.28086f, -0.162882f),
new Vector4(2.81511f, 1.597273f, -0.366471f, 10.300301f)
},
// 4 components
new[]
{
new Vector4(4.338459f, 1.553635f, -5.767909f, 46.164397f),
new Vector4(3.839993f, 4.693183f, 9.795391f, -15.227561f),
new Vector4(2.791880f, 8.178137f, -3.048324f, 0.302959f),
new Vector4(1.342190f, 12.328289f, 0.010001f, 0.244650f)
},
// 5 components
new[]
{
new Vector4(4.892608f, 1.685979f, -22.356787f, 85.91246f),
new Vector4(4.71187f, 4.998496f, 35.918936f, -28.875618f),
new Vector4(4.052795f, 8.244168f, -13.212253f, -1.578428f),
new Vector4(2.929212f, 11.900859f, 0.507991f, 1.816328f),
new Vector4(1.512961f, 16.116382f, 0.138051f, -0.01f)
},
// 6 components
new[]
{
new Vector4(5.143778f, 2.079813f, -82.326596f, 111.231024f),
new Vector4(5.612426f, 6.153387f, 113.878661f, 58.004879f),
new Vector4(5.982921f, 9.802895f, 39.479083f, -162.028887f),
new Vector4(6.505167f, 11.059237f, -71.286026f, 95.027069f),
new Vector4(3.869579f, 14.81052f, 1.405746f, -3.704914f),
new Vector4(2.201904f, 19.032909f, -0.152784f, -0.107988f)
}
};
/// <summary>
/// Gets the kernel parameters and scaling factor for the current count value in the current instance
/// </summary>
private (Vector4[] Parameters, float Scale) GetParameters()
{
// Prepare the kernel components
int index = Math.Max(0, Math.Min(ComponentsCount - 1, KernelComponents.Count));
return (KernelComponents[index], KernelScales[index]);
}
/// <summary>
/// Creates the collection of complex 1D kernels with the specified parameters
/// </summary>
private Vector2[][] CreateComplexKernels()
{
var kernels = new Vector2[KernelParameters.Length][];
ref Vector4 baseRef = ref MemoryMarshal.GetReference(KernelParameters.AsSpan());
for (int i = 0; i < KernelParameters.Length; i++)
{
ref Vector4 paramsRef = ref Unsafe.Add(ref baseRef, i);
kernels[i] = CreateComplex1DKernel(paramsRef.X, paramsRef.Y);
}
return kernels;
}
/// <summary>
/// Creates a complex 1D kernel with the specified parameters
/// </summary>
/// <param name="a">The exponential parameter for each complex component</param>
/// <param name="b">The angle component for each complex component</param>
private Vector2[] CreateComplex1DKernel(float a, float b)
{
var kernel = new Vector2[KernelSize];
ref Vector2 baseRef = ref MemoryMarshal.GetReference(kernel.AsSpan());
int r = Radius, n = -r;
for (int i = 0; i < KernelSize; i++, n++)
{
// Incrementally compute the range values
float value = n * KernelsScale * (1f / r);
value *= value;
// Fill in the complex kernel values
Unsafe.Add(ref baseRef, i) = new Vector2(
MathF.Exp(-a * value) * MathF.Cos(b * value),
MathF.Exp(-a * value) * MathF.Sin(b * value));
}
return kernel;
}
/// <summary>
/// Normalizes the kernels with respect to A * real + B * imaginary
/// </summary>
private void NormalizeKernels()
{
// Calculate the complex weighted sum
float total = 0;
Span<Vector2[]> kernelsSpan = Kernels.AsSpan();
ref Vector2[] baseKernelsRef = ref MemoryMarshal.GetReference(kernelsSpan);
ref Vector4 baseParamsRef = ref MemoryMarshal.GetReference(KernelParameters.AsSpan());
for (int i = 0; i < KernelParameters.Length; i++)
{
ref Vector2[] kernelRef = ref Unsafe.Add(ref baseKernelsRef, i);
int length = kernelRef.Length;
ref Vector2 valueRef = ref kernelRef[0];
ref Vector4 paramsRef = ref Unsafe.Add(ref baseParamsRef, i);
for (int j = 0; j < length; j++)
// Reuse the initialized values from the cache, if possible
var parameters = (Radius, ComponentsCount);
if (Cache.TryGetValue(parameters, out var info))
{
for (int k = 0; k < length; k++)
KernelParameters = info.Parameters;
KernelsScale = info.Scale;
Kernels = info.Kernels;
}
else
{
// Initialize the complex kernels and parameters with the current arguments
(KernelParameters, KernelsScale) = GetParameters();
Kernels = CreateComplexKernels();
NormalizeKernels();
// Store them in the cache for future use
Cache.TryAdd(parameters, (KernelParameters, KernelsScale, Kernels));
}
}
/// <summary>
/// Gets the kernel scales to adjust the component values in each kernel.
/// </summary>
private static IReadOnlyList<float> KernelScales { get; } = new[] { 1.4f, 1.2f, 1.2f, 1.2f, 1.2f, 1.2f };
/// <summary>
/// Gets the available bokeh blur kernel parameters.
/// </summary>
private static IReadOnlyList<Vector4[]> KernelComponents { get; } = new[]
{
// 1 component
new[] { new Vector4(0.862325f, 1.624835f, 0.767583f, 1.862321f) },
// 2 components
new[]
{
new Vector4(0.886528f, 5.268909f, 0.411259f, -0.548794f),
new Vector4(1.960518f, 1.558213f, 0.513282f, 4.56111f)
},
// 3 components
new[]
{
new Vector4(2.17649f, 5.043495f, 1.621035f, -2.105439f),
new Vector4(1.019306f, 9.027613f, -0.28086f, -0.162882f),
new Vector4(2.81511f, 1.597273f, -0.366471f, 10.300301f)
},
// 4 components
new[]
{
new Vector4(4.338459f, 1.553635f, -5.767909f, 46.164397f),
new Vector4(3.839993f, 4.693183f, 9.795391f, -15.227561f),
new Vector4(2.791880f, 8.178137f, -3.048324f, 0.302959f),
new Vector4(1.342190f, 12.328289f, 0.010001f, 0.244650f)
},
// 5 components
new[]
{
new Vector4(4.892608f, 1.685979f, -22.356787f, 85.91246f),
new Vector4(4.71187f, 4.998496f, 35.918936f, -28.875618f),
new Vector4(4.052795f, 8.244168f, -13.212253f, -1.578428f),
new Vector4(2.929212f, 11.900859f, 0.507991f, 1.816328f),
new Vector4(1.512961f, 16.116382f, 0.138051f, -0.01f)
},
// 6 components
new[]
{
new Vector4(5.143778f, 2.079813f, -82.326596f, 111.231024f),
new Vector4(5.612426f, 6.153387f, 113.878661f, 58.004879f),
new Vector4(5.982921f, 9.802895f, 39.479083f, -162.028887f),
new Vector4(6.505167f, 11.059237f, -71.286026f, 95.027069f),
new Vector4(3.869579f, 14.81052f, 1.405746f, -3.704914f),
new Vector4(2.201904f, 19.032909f, -0.152784f, -0.107988f)
}
};
/// <summary>
/// Gets the kernel parameters and scaling factor for the current count value in the current instance.
/// </summary>
private (Vector4[] Parameters, float Scale) GetParameters()
{
// Prepare the kernel components
int index = Math.Max(0, Math.Min(ComponentsCount - 1, KernelComponents.Count));
return (KernelComponents[index], KernelScales[index]);
}
/// <summary>
/// Creates the collection of complex 1D kernels with the specified parameters.
/// </summary>
private Complex64[][] CreateComplexKernels()
{
var kernels = new Complex64[KernelParameters.Length][];
ref Vector4 baseRef = ref MemoryMarshal.GetReference(KernelParameters.AsSpan());
for (int i = 0; i < KernelParameters.Length; i++)
{
ref Vector4 paramsRef = ref Unsafe.Add(ref baseRef, i);
kernels[i] = CreateComplex1DKernel(paramsRef.X, paramsRef.Y);
}
return kernels;
}
/// <summary>
/// Creates a complex 1D kernel with the specified parameters.
/// </summary>
/// <param name="a">The exponential parameter for each complex component.</param>
/// <param name="b">The angle component for each complex component.</param>
private Complex64[] CreateComplex1DKernel(float a, float b)
{
var kernel = new Complex64[KernelSize];
ref Complex64 baseRef = ref MemoryMarshal.GetReference(kernel.AsSpan());
int r = Radius, n = -r;
for (int i = 0; i < KernelSize; i++, n++)
{
// Incrementally compute the range values
float value = n * KernelsScale * (1f / r);
value *= value;
// Fill in the complex kernel values
Unsafe.Add(ref baseRef, i) = new Complex64(
MathF.Exp(-a * value) * MathF.Cos(b * value),
MathF.Exp(-a * value) * MathF.Sin(b * value));
}
return kernel;
}
/// <summary>
/// Normalizes the kernels with respect to A * real + B * imaginary.
/// </summary>
private void NormalizeKernels()
{
// Calculate the complex weighted sum
float total = 0;
Span<Complex64[]> kernelsSpan = Kernels.AsSpan();
ref Complex64[] baseKernelsRef = ref MemoryMarshal.GetReference(kernelsSpan);
ref Vector4 baseParamsRef = ref MemoryMarshal.GetReference(KernelParameters.AsSpan());
for (int i = 0; i < KernelParameters.Length; i++)
{
ref Complex64[] kernelRef = ref Unsafe.Add(ref baseKernelsRef, i);
int length = kernelRef.Length;
ref Complex64 valueRef = ref kernelRef[0];
ref Vector4 paramsRef = ref Unsafe.Add(ref baseParamsRef, i);
for (int j = 0; j < length; j++)
{
ref Vector2 jRef = ref Unsafe.Add(ref valueRef, j);
ref Vector2 kRef = ref Unsafe.Add(ref valueRef, k);
total +=
paramsRef.Z * (jRef.X * kRef.X - jRef.Y * kRef.Y)
+ paramsRef.W * (jRef.X * kRef.Y + jRef.Y * kRef.X);
for (int k = 0; k < length; k++)
{
ref Complex64 jRef = ref Unsafe.Add(ref valueRef, j);
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);
}
}
}
// Normalize the kernels
float scalar = 1f / MathF.Sqrt(total);
for (int i = 0; i < kernelsSpan.Length; i++)
{
ref Complex64[] kernelsRef = ref Unsafe.Add(ref baseKernelsRef, i);
int length = kernelsRef.Length;
ref Complex64 valueRef = ref kernelsRef[0];
for (int j = 0; j < length; j++)
{
Unsafe.Add(ref valueRef, j) *= scalar;
}
}
}
// Normalize the kernels
float scalar = 1f / MathF.Sqrt(total);
for (int i = 0; i < kernelsSpan.Length; i++)
/// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<ImageSharpRgba32> source)
{
ref Vector2[] kernelsRef = ref Unsafe.Add(ref baseKernelsRef, i);
int length = kernelsRef.Length;
ref Vector2 valueRef = ref kernelsRef[0];
for (int j = 0; j < length; j++)
if (!source.TryGetSinglePixelSpan(out Span<ImageSharpRgba32> pixelSpan))
{
Unsafe.Add(ref valueRef, j) *= scalar;
ThrowHelper.ThrowInvalidOperationException("Cannot process image frames wrapping discontiguous memory");
}
}
}
/// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixel> source)
{
foreach (Memory<TPixel> memory in source.GetPixelMemoryGroup())
{
Span<Rgba32> span = MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(pixelSpan);
using ReadWriteTexture2D<Rgba32, Vector4> texture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
using ReadWriteTexture2D<Vector4> temporary = GraphicsDevice.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height, AllocationMode.Clear);
using ReadWriteTexture2D<Vector4> reals = GraphicsDevice.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
using ReadWriteTexture2D<Vector4> imaginaries = GraphicsDevice.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
using ReadOnlyBuffer<Complex64> kernel = GraphicsDevice.AllocateReadOnlyBuffer<Complex64>(KernelSize);
// Preliminary gamma highlight pass
using IMemoryOwner<Vector4> source4 = GetExposedVector4Buffer(memory);
using ReadOnlyBuffer<Vector4> sourceBuffer = Gpu.Default.AllocateReadOnlyBuffer(source4.Memory.Span);
using ReadWriteBuffer<Vector4> processingBuffer = Gpu.Default.AllocateReadWriteBuffer<Vector4>(sourceBuffer.Size);
using ReadWriteBuffer<Vector4> firstPassBuffer = Gpu.Default.AllocateReadWriteBuffer<Vector4>(sourceBuffer.Size * 2);
using ReadOnlyBuffer<Vector2> kernelBuffer = Gpu.Default.AllocateReadOnlyBuffer<Vector2>(KernelSize);
ref Vector4 param0 = ref KernelParameters[0]; // Avoid bounds check to access the kernel parameters
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++)
{
kernelBuffer.SetData(Kernels[j]);
Vector4 parameters = Unsafe.Add(ref param0, j);
Vector4 parameters = KernelParameters[j];
ApplyVerticalConvolution(sourceBuffer, firstPassBuffer, kernelBuffer);
ApplyHorizontalConvolutionAndAccumulatePartials(firstPassBuffer, processingBuffer, kernelBuffer, parameters.Z, parameters.W);
kernel.CopyFrom(Kernels[j]);
GraphicsDevice.For<VerticalConvolutionProcessor>(
source.Width,
source.Height,
new(texture, reals, imaginaries, kernel));
GraphicsDevice.For<HorizontalConvolutionAndAccumulatePartialsProcessor>(
source.Width,
source.Height,
new(parameters.Z, parameters.W, reals, imaginaries, temporary, kernel));
}
// Apply the inverse gamma exposure pass
processingBuffer.GetData(source4.Memory.Span);
GraphicsDevice.For<InverseGammaHighlightProcessor>(source.Height, new(temporary, texture));
// Write the final pixel data
ApplyInverseGammaExposure(source4.Memory, memory);
texture.CopyTo(span);
}
}
/// <summary>
/// Performs a vertical 1D complex convolution with the specified parameters
/// </summary>
/// <param name="source">The source <see cref="ReadOnlyBuffer{T}"/> to read data from</param>
/// <param name="target">The target <see cref="ReadWriteBuffer{T}"/> to write the results to</param>
/// <param name="kernel">The <see cref="ReadOnlyBuffer{T}"/> with the values for the current complex kernel</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ApplyVerticalConvolution(
ReadOnlyBuffer<Vector4> source,
ReadWriteBuffer<Vector4> target,
ReadOnlyBuffer<Vector2> kernel)
{
int height = Source.Height;
int width = Source.Width;
Gpu.Default.For(width, height, new VerticalConvolutionProcessor
/// <summary>
/// Kernel for the vertical convolution pass.
/// </summary>
[AutoConstructor]
internal partial struct VerticalConvolutionProcessor : IComputeShader
{
width = width,
maxY = height - 1,
maxX = width - 1,
kernelLength = kernel.Size,
source = source,
target = target,
kernel = kernel
});
}
public IReadWriteTexture2D<Vector4> source;
public ReadWriteTexture2D<Vector4> reals;
public ReadWriteTexture2D<Vector4> imaginaries;
public ReadOnlyBuffer<Complex64> kernel;
/// <summary>
/// Kernel for <see cref="ApplyVerticalConvolution"/>
/// </summary>
private struct VerticalConvolutionProcessor : IComputeShader
{
public int width;
public int maxY;
public int maxX;
public int kernelLength;
public ReadOnlyBuffer<Vector4> source;
public ReadWriteBuffer<Vector4> target;
public ReadOnlyBuffer<Vector2> kernel;
/// <inheritdoc/>
public void Execute(ThreadIds ids)
{
Vector4 real = Vector4.Zero;
Vector4 imaginary = Vector4.Zero;
int radiusY = kernelLength >> 1;
int sourceOffsetColumnBase = ids.X;
for (int i = 0; i < kernelLength; i++)
/// <inheritdoc/>
public void Execute()
{
int offsetY = Hlsl.Clamp(ids.Y + i - radiusY, 0, maxY);
int offsetX = Hlsl.Clamp(sourceOffsetColumnBase, 0, maxX);
Vector4 color = source[offsetY * width + offsetX];
Vector2 factors = kernel[i];
Vector4 real = Vector4.Zero;
Vector4 imaginary = Vector4.Zero;
int maxY = source.Height;
int maxX = source.Width;
int kernelLength = kernel.Length;
int radiusY = kernelLength >> 1;
real += factors.X * color;
imaginary += factors.Y * color;
}
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);
Vector4 color = source[offsetX, offsetY];
Complex64 factors = kernel[i];
int offsetXY = ids.Y * width * 2 + ids.X * 2;
target[offsetXY] = real;
target[offsetXY + 1] = imaginary;
}
}
real += factors.Real * color;
imaginary += factors.Imaginary * color;
}
/// <summary>
/// Performs an horizontal 1D complex convolution with the specified parameters
/// </summary>
/// <param name="source">The source <see cref="ReadWriteBuffer{T}"/> to read data from</param>
/// <param name="target">The target <see cref="ReadWriteBuffer{T}"/> to write the results to</param>
/// <param name="kernel">The <see cref="ReadOnlyBuffer{T}"/> with the values for the current complex kernel</param>
/// <param name="z">The weight factor for the real component of the complex pixel values</param>
/// <param name="w">The weight factor for the imaginary component of the complex pixel values</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ApplyHorizontalConvolutionAndAccumulatePartials(
ReadWriteBuffer<Vector4> source,
ReadWriteBuffer<Vector4> target,
ReadOnlyBuffer<Vector2> kernel,
float z,
float w)
{
int height = Source.Height;
int width = Source.Width;
Gpu.Default.For(width, height, new HorizontalConvolutionAndAccumulatePartialsProcessor
{
width = width,
maxY = height - 1,
maxX = width - 1,
kernelLength = kernel.Size,
z = z,
w = w,
source = source,
target = target,
kernel = kernel
});
}
/// <summary>
/// Kernel for <see cref="ApplyHorizontalConvolutionAndAccumulatePartials"/>
/// </summary>
private struct HorizontalConvolutionAndAccumulatePartialsProcessor : IComputeShader
{
public int width;
public int maxY;
public int maxX;
public int kernelLength;
public float z;
public float w;
public ReadWriteBuffer<Vector4> source;
public ReadWriteBuffer<Vector4> target;
public ReadOnlyBuffer<Vector2> kernel;
/// <inheritdoc/>
public void Execute(ThreadIds ids)
{
Vector4 real = Vector4.Zero;
Vector4 imaginary = Vector4.Zero;
int radiusX = kernelLength >> 1;
int sourceOffsetColumnBase = ids.X;
int offsetY = Hlsl.Clamp(ids.Y, 0, maxY);
for (int i = 0; i < kernelLength; i++)
{
int offsetX = Hlsl.Clamp(sourceOffsetColumnBase + i - radiusX, 0, maxX);
var offsetXY = offsetY * width * 2 + offsetX * 2;
Vector4 sourceReal = source[offsetXY];
Vector4 sourceImaginary = source[offsetXY + 1];
Vector2 factors = kernel[i];
real += factors.X * sourceReal - factors.Y * sourceImaginary;
imaginary += factors.X * sourceImaginary + factors.Y * sourceReal;
}
target[ids.Y * width + ids.X] += real * z + imaginary * w;
}
}
/// <summary>
/// Applies the gamma correction/highlight to the input pixel buffer and returns an <see cref="IMemoryOwner{T}"/> instance with <see cref="Vector4"/> values.
/// </summary>
/// <param name="source">The source image</param>
[Pure]
private IMemoryOwner<Vector4> GetExposedVector4Buffer(Memory<TPixel> source)
{
IMemoryOwner<Vector4> target = Configuration.MemoryAllocator.Allocate<Vector4>(source.Length);
float exp = Gamma;
int width = Source.Width;
int height = source.Length / width;
ParallelRowIterator.IterateRows(
Configuration,
new Rectangle(0, 0, width, height),
new GetExposedVector4BufferProcessor(width, exp, source, target.Memory, Configuration));
return target;
}
/// <summary>
/// The processor for <see cref="GetExposedVector4Buffer"/>
/// </summary>
private readonly struct GetExposedVector4BufferProcessor : IRowOperation
{
private readonly int width;
private readonly float exp;
private readonly Memory<TPixel> source;
private readonly Memory<Vector4> target;
private readonly Configuration configuration;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public GetExposedVector4BufferProcessor(
int width,
float exp,
Memory<TPixel> source,
Memory<Vector4> target,
Configuration configuration)
{
this.width = width;
this.exp = exp;
this.source = source;
this.target = target;
this.configuration = configuration;
}
/// <inheritdoc/>
public void Invoke(int y)
{
int offset = y * width;
Span<TPixel> rowTPixel = source.Span.Slice(offset, width);
Span<Vector4> rowVector4 = target.Span.Slice(offset, width);
PixelOperations<TPixel>.Instance.ToVector4(configuration, rowTPixel, rowVector4);
foreach (ref Vector4 v in rowVector4)
{
v.X = MathF.Pow(v.X, exp);
v.Y = MathF.Pow(v.Y, exp);
v.Z = MathF.Pow(v.Z, exp);
reals[ThreadIds.XY] = real;
imaginaries[ThreadIds.XY] = imaginary;
}
}
}
/// <summary>
/// Applies the inverse gamma exposure pass to compute the final pixel values for a target image
/// </summary>
/// <param name="source">The source <see cref="Vector4"/> buffer to read from</param>
/// <param name="target">The target image</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ApplyInverseGammaExposure(Memory<Vector4> source, Memory<TPixel> target)
{
int width = Source.Width;
int height = source.Length / width;
float expGamma = 1 / Gamma;
ParallelRowIterator.IterateRows(
Configuration,
new Rectangle(0, 0, width, height),
new ApplyInverseGammaExposureProcessor(width, expGamma, source, target, Configuration));
}
/// <summary>
/// The processor for <see cref="ApplyInverseGammaExposure"/>
/// </summary>
private readonly struct ApplyInverseGammaExposureProcessor : IRowOperation
{
private readonly int width;
private readonly float exp;
private readonly Memory<Vector4> source;
private readonly Memory<TPixel> target;
private readonly Configuration configuration;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ApplyInverseGammaExposureProcessor(
int width,
float exp,
Memory<Vector4> source,
Memory<TPixel> target,
Configuration configuration)
/// <summary>
/// Kernel for the horizontal convolution pass.
/// </summary>
[AutoConstructor]
internal partial struct HorizontalConvolutionAndAccumulatePartialsProcessor : IComputeShader
{
this.width = width;
this.exp = exp;
this.source = source;
this.target = target;
this.configuration = configuration;
public float z;
public float w;
public ReadWriteTexture2D<Vector4> reals;
public ReadWriteTexture2D<Vector4> imaginaries;
public ReadWriteTexture2D<Vector4> target;
public ReadOnlyBuffer<Complex64> kernel;
/// <inheritdoc/>
public void Execute()
{
Vector4 real = Vector4.Zero;
Vector4 imaginary = Vector4.Zero;
int maxY = target.Height;
int maxX = target.Width;
int kernelLength = 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);
Vector4 sourceReal = reals[offsetX, offsetY];
Vector4 sourceImaginary = imaginaries[offsetX, offsetY];
Complex64 factors = kernel[i];
real += factors.Real * sourceReal - factors.Imaginary * sourceImaginary;
imaginary += factors.Real * sourceImaginary + factors.Imaginary * sourceReal;
}
target[ThreadIds.XY] += real * z + imaginary * w;
}
}
/// <inheritdoc/>
public void Invoke(int y)
/// <summary>
/// Kernel for the gamma highlight pass.
/// </summary>
[AutoConstructor]
internal readonly partial struct GammaHighlightProcessor : IComputeShader
{
int offset = y * width;
public readonly IReadWriteTexture2D<Vector4> source;
Span<Vector4> rowVector4 = source.Span.Slice(offset, width);
Span<TPixel> rowTPixel = target.Span.Slice(offset, width);
Vector4 low = Vector4.Zero;
var high = new Vector4(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
foreach (ref Vector4 v in rowVector4)
/// <inheritdoc/>
public void Execute()
{
var clamp = Vector4.Clamp(v, low, high);
v.X = MathF.Pow(clamp.X, exp);
v.Y = MathF.Pow(clamp.Y, exp);
v.Z = MathF.Pow(clamp.Z, exp);
}
int width = source.Width;
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, rowVector4, rowTPixel);
for (int i = 0; i < width; i++)
{
Float4 v = source[i, ThreadIds.X];
v.XYZ = v.XYZ * v.XYZ * v.XYZ;
source[i, ThreadIds.X] = v;
}
}
}
/// <summary>
/// Kernel for the inverse gamma highlight pass.
/// </summary>
[AutoConstructor]
internal readonly partial struct InverseGammaHighlightProcessor : IComputeShader
{
public readonly ReadWriteTexture2D<Vector4> source;
public readonly IReadWriteTexture2D<Vector4> target;
/// <inheritdoc/>
public void Execute()
{
int width = source.Width;
for (int i = 0; i < width; i++)
{
Float4 v = source[i, ThreadIds.X];
v = Hlsl.Clamp(v, 0, float.MaxValue);
v.XYZ = Hlsl.Pow(v.XYZ, 1 / 3f);
target[i, ThreadIds.X] = v;
}
}
}
}
}
+54 -21
ファイルの表示
@@ -1,13 +1,16 @@
using SixLabors.ImageSharp;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Diagnostics;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
namespace ComputeSharp.BokehBlur.Processors
{
/// <summary>
/// Defines Gaussian blur by a (Sigma, Radius) pair
/// Defines Gaussian blur by a (Sigma, Radius) pair.
/// </summary>
public sealed class HlslGaussianBlurProcessor : IImageProcessor
public sealed partial class HlslGaussianBlurProcessor : IImageProcessor
{
/// <summary>
/// The default value for <see cref="Sigma"/>.
@@ -15,34 +18,57 @@ namespace ComputeSharp.BokehBlur.Processors
public const float DefaultSigma = 3f;
/// <summary>
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
/// </summary>
public HlslGaussianBlurProcessor() : this(DefaultSigma, 9) { }
/// <summary>
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class
/// </summary>
/// <param name="radius">The radius value representing the size of the area to sample</param>
public HlslGaussianBlurProcessor(int radius) : this(radius / 3F, radius) { }
/// <summary>
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class
/// </summary>
/// <param name="sigma"> The sigma value representing the weight of the blur </param>
/// <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(float sigma, int radius)
public HlslGaussianBlurProcessor()
: this(Gpu.Default, DefaultSigma, 9)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
/// </summary>
/// <param name="radius">The radius value representing the size of the area to sample.</param>
public HlslGaussianBlurProcessor(int radius)
: this(Gpu.Default, radius / 3F, radius)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
/// <param name="radius">The radius value representing the size of the area to sample.</param>
public HlslGaussianBlurProcessor(GraphicsDevice device, int radius)
: this(device, radius / 3F, radius)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
/// <param name="sigma"> The sigma value representing the weight of the blur. </param>
/// <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;
Sigma = sigma;
Radius = radius;
}
/// <summary>
/// Gets the sigma value representing the weight of the blur
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
/// </summary>
private readonly GraphicsDevice GraphicsDevice;
/// <summary>
/// Gets the sigma value representing the weight of the blur.
/// </summary>
public float Sigma { get; }
/// <summary>
/// Gets the radius defining the size of the area to sample
/// Gets the radius defining the size of the area to sample.
/// </summary>
public int Radius { get; }
@@ -50,7 +76,14 @@ namespace ComputeSharp.BokehBlur.Processors
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : unmanaged, IPixel<TPixel>
{
return new HlslGaussianBlurProcessor<TPixel>(this, configuration, source, sourceRectangle);
if (typeof(TPixel) != typeof(ImageSharpRgba32))
{
ThrowHelper.ThrowInvalidOperationException("This processor only supports the RGBA32 pixel format");
}
var processor = new Implementation(this, configuration, Unsafe.As<Image<ImageSharpRgba32>>(source), sourceRectangle);
return Unsafe.As<IImageProcessor<TPixel>>(processor);
}
}
}
+149 -208
ファイルの表示
@@ -1,237 +1,178 @@
using System;
using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.Toolkit.Diagnostics;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
namespace ComputeSharp.BokehBlur.Processors
{
/// <summary>
/// Applies Gaussian blur processing to an image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class HlslGaussianBlurProcessor<TPixel> : ImageProcessor<TPixel>
where TPixel : unmanaged, IPixel<TPixel>
/// <inheritdoc/>
public sealed partial class HlslGaussianBlurProcessor
{
/// <summary>
/// The 1D kernel to apply
/// Applies Gaussian blur processing to an image.
/// </summary>
private readonly float[] Kernel;
/// <summary>
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class
/// </summary>
/// <param name="definition">The <see cref="HlslGaussianBlurProcessor"/> defining the processor parameters</param>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance</param>
public HlslGaussianBlurProcessor(HlslGaussianBlurProcessor definition, Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle)
internal sealed partial class Implementation : ImageProcessor<ImageSharpRgba32>
{
int kernelSize = definition.Radius * 2 + 1;
Kernel = CreateGaussianBlurKernel(kernelSize, definition.Sigma);
}
/// <summary>
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
/// </summary>
private readonly GraphicsDevice GraphicsDevice;
/// <summary>
/// Creates a 1 dimensional Gaussian kernel using the Gaussian G(x) function
/// </summary>
private static float[] CreateGaussianBlurKernel(int size, float weight)
{
float[] kernel = new float[size];
ref float rKernel = ref kernel[0];
/// <summary>
/// The 1D kernel to apply.
/// </summary>
private readonly float[] Kernel;
float sum = 0F;
float midpoint = (size - 1) / 2F;
for (int i = 0; i < size; i++)
/// <summary>
/// Initializes a new instance of the <see cref="Implementation"/> class.
/// </summary>
/// <param name="definition">The <see cref="Implementation"/> defining the processor parameters.</param>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public Implementation(HlslGaussianBlurProcessor definition, Configuration configuration, Image<ImageSharpRgba32> source, Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle)
{
float x = i - midpoint;
float gx = Gaussian(x, weight);
sum += gx;
Unsafe.Add(ref rKernel, i) = gx;
int kernelSize = definition.Radius * 2 + 1;
GraphicsDevice = definition.GraphicsDevice;
Kernel = CreateGaussianBlurKernel(kernelSize, definition.Sigma);
}
// Normalize kernel so that the sum of all weights equals 1
for (int i = 0; i < size; i++)
/// <summary>
/// Creates a 1 dimensional Gaussian kernel using the Gaussian G(x) function.
/// </summary>
private static float[] CreateGaussianBlurKernel(int size, float weight)
{
Unsafe.Add(ref rKernel, i) /= sum;
}
float[] kernel = new float[size];
ref float rKernel = ref kernel[0];
return kernel;
}
float sum = 0F;
float midpoint = (size - 1) / 2F;
/// <summary>
/// Implementation of 1D Gaussian G(x) function
/// </summary>
/// <param name="x">The x provided to G(x)</param>
/// <param name="sigma">The spread of the blur</param>
/// <returns>The Gaussian G(x)</returns>
private static float Gaussian(float x, float sigma)
{
const float Numerator = 1.0f;
float denominator = MathF.Sqrt(2 * MathF.PI) * sigma;
float exponentNumerator = -x * x;
float exponentDenominator = 2 * sigma * sigma;
float left = Numerator / denominator;
float right = MathF.Exp(exponentNumerator / exponentDenominator);
return left * right;
}
/// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixel> source)
{
foreach (Memory<TPixel> memory in source.GetPixelMemoryGroup())
{
Span<TPixel> spanTPixel = memory.Span;
using IMemoryOwner<Vector4> group4 = Configuration.MemoryAllocator.Allocate<Vector4>(spanTPixel.Length);
Span<Vector4> spanVector4 = group4.Memory.Span;
PixelOperations<TPixel>.Instance.ToVector4(Configuration, spanTPixel, spanVector4);
using ReadWriteBuffer<Vector4> sourceBuffer = Gpu.Default.AllocateReadWriteBuffer(spanVector4);
using ReadWriteBuffer<Vector4> firstPassBuffer = Gpu.Default.AllocateReadWriteBuffer<Vector4>(sourceBuffer.Size);
using ReadOnlyBuffer<float> kernelBuffer = Gpu.Default.AllocateReadOnlyBuffer(Kernel);
ApplyVerticalConvolution(sourceBuffer, firstPassBuffer, kernelBuffer);
ApplyHorizontalConvolution(firstPassBuffer, sourceBuffer, kernelBuffer);
sourceBuffer.GetData(spanVector4);
PixelOperations<TPixel>.Instance.FromVector4Destructive(Configuration, spanVector4, spanTPixel);
}
}
/// <summary>
/// Performs a vertical 1D complex convolution with the specified parameters
/// </summary>
/// <param name="source">The source <see cref="ReadWriteBuffer{T}"/> to read data from</param>
/// <param name="target">The target <see cref="ReadWriteBuffer{T}"/> to write the results to</param>
/// <param name="kernel">The <see cref="ReadOnlyBuffer{T}"/> with the values for the current complex kernel</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ApplyVerticalConvolution(
ReadWriteBuffer<Vector4> source,
ReadWriteBuffer<Vector4> target,
ReadOnlyBuffer<float> kernel)
{
int height = Source.Height;
int width = Source.Width;
Gpu.Default.For(width, height, new VerticalConvolutionProcessor
{
width = width,
maxY = height - 1,
maxX = width - 1,
kernelLength = kernel.Size,
source = source,
target = target,
kernel = kernel
});
}
/// <summary>
/// Kernel for <see cref="ApplyVerticalConvolution"/>
/// </summary>
private struct VerticalConvolutionProcessor : IComputeShader
{
public int width;
public int maxY;
public int maxX;
public int kernelLength;
public ReadWriteBuffer<Vector4> source;
public ReadWriteBuffer<Vector4> target;
public ReadOnlyBuffer<float> kernel;
/// <inheritdoc/>
public void Execute(ThreadIds ids)
{
Vector4 result = Vector4.Zero;
int radiusY = kernelLength >> 1;
int sourceOffsetColumnBase = ids.X;
for (int i = 0; i < kernelLength; i++)
for (int i = 0; i < size; i++)
{
int offsetY = Hlsl.Clamp(ids.Y + i - radiusY, 0, maxY);
int offsetX = Hlsl.Clamp(sourceOffsetColumnBase, 0, maxX);
Vector4 color = source[offsetY * width + offsetX];
result += kernel[i] * color;
float x = i - midpoint;
float gx = Gaussian(x, weight);
sum += gx;
Unsafe.Add(ref rKernel, i) = gx;
}
int offsetXY = ids.Y * width + ids.X;
target[offsetXY] = result;
}
}
/// <summary>
/// Performs an horizontal 1D complex convolution with the specified parameters
/// </summary>
/// <param name="source">The source <see cref="ReadWriteBuffer{T}"/> to read data from</param>
/// <param name="target">The target <see cref="ReadWriteBuffer{T}"/> to write the results to</param>
/// <param name="kernel">The <see cref="ReadOnlyBuffer{T}"/> with the values for the current complex kernel</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ApplyHorizontalConvolution(
ReadWriteBuffer<Vector4> source,
ReadWriteBuffer<Vector4> target,
ReadOnlyBuffer<float> kernel)
{
int height = Source.Height;
int width = Source.Width;
Gpu.Default.For(width, height, new HorizontalConvolutionProcessor
{
width = width,
maxY = height - 1,
maxX = width - 1,
kernelLength = kernel.Size,
source = source,
target = target,
kernel = kernel
});
}
/// <summary>
/// Kernel for <see cref="ApplyHorizontalConvolution"/>
/// </summary>
private struct HorizontalConvolutionProcessor : IComputeShader
{
public int width;
public int maxY;
public int maxX;
public int kernelLength;
public ReadWriteBuffer<Vector4> source;
public ReadWriteBuffer<Vector4> target;
public ReadOnlyBuffer<float> kernel;
/// <inheritdoc/>
public void Execute(ThreadIds ids)
{
Vector4 result = Vector4.Zero;
int radiusX = kernelLength >> 1;
int sourceOffsetColumnBase = ids.X;
int offsetY = Hlsl.Clamp(ids.Y, 0, maxY);
int offsetXY;
for (int i = 0; i < kernelLength; i++)
// Normalize kernel so that the sum of all weights equals 1
for (int i = 0; i < size; i++)
{
int offsetX = Hlsl.Clamp(sourceOffsetColumnBase + i - radiusX, 0, maxX);
offsetXY = offsetY * width + offsetX;
Vector4 color = source[offsetXY];
result += kernel[i] * color;
Unsafe.Add(ref rKernel, i) /= sum;
}
offsetXY = ids.Y * width + ids.X;
target[offsetXY] = result;
return kernel;
}
/// <summary>
/// Implementation of 1D Gaussian G(x) function.
/// </summary>
/// <param name="x">The x provided to G(x)</param>
/// <param name="sigma">The spread of the blur.</param>
/// <returns>The Gaussian G(x)</returns>
private static float Gaussian(float x, float sigma)
{
const float Numerator = 1.0f;
float denominator = MathF.Sqrt(2 * MathF.PI) * sigma;
float exponentNumerator = -x * x;
float exponentDenominator = 2 * sigma * sigma;
float left = Numerator / denominator;
float right = MathF.Exp(exponentNumerator / exponentDenominator);
return left * right;
}
/// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<ImageSharpRgba32> source)
{
if (!source.TryGetSinglePixelSpan(out Span<ImageSharpRgba32> pixelSpan))
{
ThrowHelper.ThrowInvalidOperationException("Cannot process image frames wrapping discontiguous memory");
}
Span<Rgba32> span = MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(pixelSpan);
using ReadWriteTexture2D<Rgba32, Vector4> sourceTexture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
using ReadWriteTexture2D<Rgba32, Vector4> firstPassTexture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, Vector4>(source.Width, source.Height);
using ReadOnlyBuffer<float> kernelBuffer = GraphicsDevice.AllocateReadOnlyBuffer(Kernel);
GraphicsDevice.For<VerticalConvolutionProcessor>(source.Width, source.Height, new(sourceTexture, firstPassTexture, kernelBuffer));
GraphicsDevice.For<HorizontalConvolutionProcessor>(source.Width, source.Height, new(firstPassTexture, sourceTexture, kernelBuffer));
sourceTexture.CopyTo(span);
}
/// <summary>
/// Kernel for the vertical convolution pass.
/// </summary>
[AutoConstructor]
internal readonly partial struct VerticalConvolutionProcessor : IComputeShader
{
public readonly IReadWriteTexture2D<Vector4> source;
public readonly IReadWriteTexture2D<Vector4> target;
public readonly ReadOnlyBuffer<float> kernel;
/// <inheritdoc/>
public void Execute()
{
Vector4 result = Vector4.Zero;
int maxY = source.Height - 1;
int maxX = source.Width - 1;
int kernelLength = 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);
Vector4 color = source[offsetX, offsetY];
result += kernel[i] * color;
}
target[ThreadIds.XY] = result;
}
}
/// <summary>
/// Kernel for the horizontal convolution pass.
/// </summary>
[AutoConstructor]
internal readonly partial struct HorizontalConvolutionProcessor : IComputeShader
{
public readonly IReadWriteTexture2D<Vector4> source;
public readonly IReadWriteTexture2D<Vector4> target;
public readonly ReadOnlyBuffer<float> kernel;
/// <inheritdoc/>
public void Execute()
{
Vector4 result = Vector4.Zero;
int maxY = source.Height - 1;
int maxX = source.Width - 1;
int kernelLength = 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);
Vector4 color = source[offsetX, offsetY];
result += kernel[i] * color;
}
target[ThreadIds.XY] = result;
}
}
}
}
+5 -4
ファイルの表示
@@ -5,6 +5,7 @@ using ComputeSharp.BokehBlur.Processors;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
namespace ComputeSharp.ImageProcessing
{
@@ -13,13 +14,13 @@ namespace ComputeSharp.ImageProcessing
static void Main()
{
Console.WriteLine(">> Loading image");
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "city.jpg");
using Image image = Image.Load(path);
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "city.jpg");
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)[]
{
("bokeh", new HlslBokehBlurProcessor(80, 2, 3)),
("bokeh", new HlslBokehBlurProcessor(80, 2)),
("gaussian", new HlslGaussianBlurProcessor(80))
})
{
@@ -28,7 +29,7 @@ namespace ComputeSharp.ImageProcessing
Console.WriteLine($">> Saving {effect.Name} to disk");
string targetPath = Path.Combine(
Path.GetRelativePath(Path.GetDirectoryName(path), @"..\..\..\"),
Path.GetRelativePath(Path.GetDirectoryName(path)!, @"..\..\..\"),
$"{Path.GetFileNameWithoutExtension(path)}_{effect.Name}{Path.GetExtension(path)}");
copy.Save(targetPath);
}
+18
ファイルの表示
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp\ComputeSharp.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"
PrivateAssets="contentfiles;build" />
</ItemGroup>
<Import Project="..\ComputeSharp.Sample.Shared\ComputeSharp.Sample.Shared.projitems" Label="Shared" />
</Project>
+14
ファイルの表示
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ComputeSharp" Version="2.0.0" />
</ItemGroup>
<Import Project="..\ComputeSharp.Sample.Shared\ComputeSharp.Sample.Shared.projitems" Label="Shared" />
</Project>
+14
ファイルの表示
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>8cefc324-ca6c-4845-9ad9-70b92bd87057</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>ComputeSharp.Sample.Shared</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Program.cs" />
</ItemGroup>
</Project>
+13
ファイルの表示
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>8cefc324-ca6c-4845-9ad9-70b92bd87057</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="ComputeSharp.Sample.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
+26 -32
ファイルの表示
@@ -5,7 +5,7 @@ using System.Runtime.CompilerServices;
namespace ComputeSharp.Sample
{
class Program
partial class Program
{
static void Main()
{
@@ -18,58 +18,50 @@ namespace ComputeSharp.Sample
array[i] = i + 1;
}
// Print the initial matrix
Console.WriteLine("===================== BEFORE =====================");
PrintMatrix(array, width, height);
Console.WriteLine("==================================================");
Console.WriteLine();
using ReadWriteBuffer<float> gpuBuffer = Gpu.Default.AllocateReadWriteBuffer(array);
// Run the shader
Gpu.Default.For(100, new MainKernel(width, gpuBuffer));
Gpu.Default.For(100, new MainKernel(gpuBuffer));
// Print the initial matrix
PrintMatrix(array, width, height, "BEFORE");
// Get the data back
gpuBuffer.GetData(array);
gpuBuffer.CopyTo(array);
// Print the updated matrix
Console.WriteLine("===================== AFTER ======================");
PrintMatrix(array, width, height);
Console.WriteLine("==================================================");
PrintMatrix(array, width, height, "AFTER");
}
/// <summary>
/// Kernel for <see cref="Main"/>
/// Kernel for <see cref="Main"/>.
/// </summary>
private readonly struct MainKernel : IComputeShader
[AutoConstructor]
internal readonly partial struct MainKernel : IComputeShader
{
private readonly int width;
private readonly ReadWriteBuffer<float> buffer;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public MainKernel(int width, ReadWriteBuffer<float> buffer)
{
this.width = width;
this.buffer = buffer;
}
public readonly ReadWriteBuffer<float> buffer;
/// <inheritdoc/>
public void Execute(ThreadIds ids)
public void Execute()
{
int offset = ids.X + ids.Y * width;
buffer[offset] *= 2;
buffer[ThreadIds.X] *= 2;
}
}
/// <summary>
/// Prints a matrix in a properly formatted way
/// Prints a matrix in a properly formatted way.
/// </summary>
/// <param name="array">The input <see langword="float"/> array representing the matrix to print</param>
/// <param name="width">The width of the array to print</param>
/// <param name="height">The height of the array to print</param>
private static void PrintMatrix(float[] array, int width, int height)
/// <param name="array">The input <see langword="float"/> array representing the matrix to print.</param>
/// <param name="width">The width of the array to print.</param>
/// <param name="height">The height of the array to print.</param>
/// <param name="name">The name of the matrix to print.</param>
private static void PrintMatrix(float[] array, int width, int height, string name)
{
int pad = 48 - name.Length;
string title = $"{new string('=', pad / 2)} {name} {new string('=', (pad + 1) / 2)}";
Console.WriteLine(title);
int length = width * height;
int numberWidth = array.Max().ToString(CultureInfo.InvariantCulture).Length;
ref float r = ref array[0];
@@ -82,6 +74,8 @@ namespace ComputeSharp.Sample
if (i < length - 1) Console.Write(", ");
if (i > 0 && (i + 1) % width == 0) Console.WriteLine();
}
Console.WriteLine(new string('=', 50));
}
}
}
-12
ファイルの表示
@@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp\ComputeSharp.csproj" />
</ItemGroup>
</Project>
+287
ファイルの表示
@@ -0,0 +1,287 @@
using System;
using System.Drawing;
using ComputeSharp.Interop;
using TerraFX.Interop;
using FX = TerraFX.Interop.Windows;
namespace ComputeSharp.SwapChain.Backend
{
internal sealed class SwapChainApplication<T> : Win32Application
where T : struct, IComputeShader
{
/// <summary>
/// The <see cref="Func{T1, T2, TResult}"/> instance used to create shaders to run.
/// </summary>
private readonly Func<IReadWriteTexture2D<Float4>, TimeSpan, T> shaderFactory;
/// <summary>
/// The <see cref="ID3D12Device"/> pointer for the device currently in use.
/// </summary>
private ComPtr<ID3D12Device> d3D12Device;
/// <summary>
/// The <see cref="ID3D12CommandQueue"/> instance to use for graphics operations.
/// </summary>
private ComPtr<ID3D12CommandQueue> d3D12CommandQueue;
/// <summary>
/// The <see cref="ID3D12Fence"/> instance used for graphics operations.
/// </summary>
private ComPtr<ID3D12Fence> d3D12Fence;
/// <summary>
/// The next fence value for graphics operations using <see cref="d3D12CommandQueue"/>.
/// </summary>
private ulong nextD3D12FenceValue = 1;
/// <summary>
/// The <see cref="ID3D12CommandAllocator"/> object to create command lists.
/// </summary>
private ComPtr<ID3D12CommandAllocator> d3D12CommandAllocator;
/// <summary>
/// The <see cref="ID3D12GraphicsCommandList"/> instance used to copy data to the back buffers.
/// </summary>
private ComPtr<ID3D12GraphicsCommandList> d3D12GraphicsCommandList;
/// <summary>
/// The <see cref="IDXGISwapChain1"/> instance used to display content onto the target window.
/// </summary>
private ComPtr<IDXGISwapChain1> dxgiSwapChain1;
/// <summary>
/// The first buffer within <see cref="dxgiSwapChain1"/>.
/// </summary>
private ComPtr<ID3D12Resource> d3D12Resource0;
/// <summary>
/// The second buffer within <see cref="dxgiSwapChain1"/>.
/// </summary>
private ComPtr<ID3D12Resource> d3D12Resource1;
/// <summary>
/// The index of the next buffer that can be used to present content.
/// </summary>
private uint currentBufferIndex;
/// <summary>
/// The <see cref="ReadWriteTexture2D{T, TPixel}"/> instance used to prepare frames to display.
/// </summary>
private ReadWriteTexture2D<Rgba32, Float4>? texture;
/// <summary>
/// Creates a new <see cref="SwapChainApplication"/> instance with the specified parameters.
/// </summary>
/// <param name="shaderFactory">The <see cref="Func{T1, T2, TResult}"/> instance used to create shaders to run.</param>
public SwapChainApplication(Func<IReadWriteTexture2D<Float4>, TimeSpan, T> shaderFactory)
{
this.shaderFactory = shaderFactory;
}
/// <inheritdoc/>
public override string Title => default(T).ToString()!;
/// <inheritdoc/>
public override unsafe void OnInitialize(Size size, HWND hwnd)
{
// Get the underlying ID3D12Device in use
fixed (ID3D12Device** d3D12Device = this.d3D12Device)
{
_ = InteropServices.TryGetID3D12Device(Gpu.Default, FX.__uuidof<ID3D12Device>(), (void**)d3D12Device);
}
// Create the direct command queue to use
fixed (ID3D12CommandQueue** d3D12CommandQueue = this.d3D12CommandQueue)
{
D3D12_COMMAND_QUEUE_DESC d3D12CommandQueueDesc;
d3D12CommandQueueDesc.Type = D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT;
d3D12CommandQueueDesc.Priority = (int)D3D12_COMMAND_QUEUE_PRIORITY.D3D12_COMMAND_QUEUE_PRIORITY_NORMAL;
d3D12CommandQueueDesc.Flags = D3D12_COMMAND_QUEUE_FLAGS.D3D12_COMMAND_QUEUE_FLAG_NONE;
d3D12CommandQueueDesc.NodeMask = 0;
_ = d3D12Device.Get()->CreateCommandQueue(
&d3D12CommandQueueDesc,
FX.__uuidof<ID3D12CommandQueue>(),
(void**)d3D12CommandQueue);
}
// Create the direct fence
fixed (ID3D12Fence** d3D12Fence = this.d3D12Fence)
{
_ = this.d3D12Device.Get()->CreateFence(
0,
D3D12_FENCE_FLAGS.D3D12_FENCE_FLAG_NONE,
FX.__uuidof<ID3D12Fence>(),
(void**)d3D12Fence);
}
// Create the swap chain to display frames
fixed (IDXGISwapChain1** dxgiSwapChain1 = this.dxgiSwapChain1)
{
using ComPtr<IDXGIFactory2> dxgiFactory2 = default;
_ = FX.CreateDXGIFactory2(FX.DXGI_CREATE_FACTORY_DEBUG, FX.__uuidof<IDXGIFactory2>(), (void**)dxgiFactory2.GetAddressOf());
DXGI_SWAP_CHAIN_DESC1 dxgiSwapChainDesc1 = default;
dxgiSwapChainDesc1.AlphaMode = DXGI_ALPHA_MODE.DXGI_ALPHA_MODE_IGNORE;
dxgiSwapChainDesc1.BufferCount = 2;
dxgiSwapChainDesc1.Flags = 0;
dxgiSwapChainDesc1.Format = DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM;
dxgiSwapChainDesc1.Width = 0;
dxgiSwapChainDesc1.Height = 0;
dxgiSwapChainDesc1.SampleDesc = new DXGI_SAMPLE_DESC(count: 1, quality: 0);
dxgiSwapChainDesc1.Scaling = DXGI_SCALING.DXGI_SCALING_STRETCH;
dxgiSwapChainDesc1.Stereo = 0;
dxgiSwapChainDesc1.SwapEffect = DXGI_SWAP_EFFECT.DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
_ = dxgiFactory2.Get()->CreateSwapChainForHwnd(
(IUnknown*)d3D12CommandQueue.Get(),
hwnd,
&dxgiSwapChainDesc1,
null,
null,
dxgiSwapChain1);
}
// Create the command allocator to use
fixed (ID3D12CommandAllocator** d3D12CommandAllocator = this.d3D12CommandAllocator)
{
this.d3D12Device.Get()->CreateCommandAllocator(
D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT,
FX.__uuidof<ID3D12CommandAllocator>(),
(void**)d3D12CommandAllocator);
}
// Create the reusable command list to copy data to the back buffers
fixed (ID3D12GraphicsCommandList** d3D12GraphicsCommandList = this.d3D12GraphicsCommandList)
{
this.d3D12Device.Get()->CreateCommandList(
0,
D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT,
d3D12CommandAllocator,
null,
FX.__uuidof<ID3D12GraphicsCommandList>(),
(void**)d3D12GraphicsCommandList);
}
// Close the command list to prepare it for future use
this.d3D12GraphicsCommandList.Get()->Close();
}
/// <inheritdoc/>
public override unsafe void OnResize(Size size)
{
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.nextD3D12FenceValue++;
// Dispose the old buffers before resizing the buffer
this.d3D12Resource0.Dispose();
this.d3D12Resource1.Dispose();
// Resize the swap chain buffers
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)
{
_ = this.dxgiSwapChain1.CopyTo(dxgiSwapChain3.GetAddressOf());
this.currentBufferIndex = dxgiSwapChain3.Get()->GetCurrentBackBufferIndex();
}
// Retrieve the back buffers for the swap chain
fixed (ID3D12Resource** d3D12Resource0 = this.d3D12Resource0)
fixed (ID3D12Resource** d3D12Resource1 = this.d3D12Resource1)
{
_ = dxgiSwapChain1.Get()->GetBuffer(0, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource0);
_ = dxgiSwapChain1.Get()->GetBuffer(1, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource1);
}
this.texture?.Dispose();
D3D12_RESOURCE_DESC d3D12Resource0Description = this.d3D12Resource0.Get()->GetDesc();
// Create the 2D texture to use to generate frames to display
this.texture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Float4>(
(int)d3D12Resource0Description.Width,
(int)d3D12Resource0Description.Height);
}
/// <inheritdoc/>
public override unsafe void OnUpdate(TimeSpan time)
{
// Generate the new frame
Gpu.Default.For(this.texture!.Width, this.texture.Height, this.shaderFactory(this.texture, time));
using ComPtr<ID3D12Resource> d3D12Resource = default;
// Get the underlying ID3D12Resource pointer for the texture
_ = InteropServices.TryGetID3D12Resource(this.texture, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
// Get the target back buffer to update
ID3D12Resource* d3D12ResourceBackBuffer = this.currentBufferIndex switch
{
0 => this.d3D12Resource0.Get(),
1 => this.d3D12Resource1.Get(),
_ => null
};
this.currentBufferIndex ^= 1;
// Reset the command list and command allocator
this.d3D12CommandAllocator.Get()->Reset();
this.d3D12GraphicsCommandList.Get()->Reset(this.d3D12CommandAllocator.Get(), null);
D3D12_RESOURCE_BARRIER* d3D12ResourceBarriers = stackalloc D3D12_RESOURCE_BARRIER[]
{
D3D12_RESOURCE_BARRIER.InitTransition(
d3D12Resource.Get(),
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_SOURCE),
D3D12_RESOURCE_BARRIER.InitTransition(
d3D12ResourceBackBuffer,
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COMMON,
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_DEST)
};
// Transition the resources to COPY_DEST and COPY_SOURCE respectively
d3D12GraphicsCommandList.Get()->ResourceBarrier(2, d3D12ResourceBarriers);
// Copy the generated frame to the target back buffer
d3D12GraphicsCommandList.Get()->CopyResource(d3D12ResourceBackBuffer, d3D12Resource.Get());
d3D12ResourceBarriers[0] = D3D12_RESOURCE_BARRIER.InitTransition(
d3D12Resource.Get(),
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_SOURCE,
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
d3D12ResourceBarriers[1] = D3D12_RESOURCE_BARRIER.InitTransition(
d3D12ResourceBackBuffer,
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_DEST,
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COMMON);
// Transition the resources back to COMMON and UNORDERED_ACCESS respectively
d3D12GraphicsCommandList.Get()->ResourceBarrier(2, d3D12ResourceBarriers);
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);
// Present the new frame
this.dxgiSwapChain1.Get()->Present(0, 0);
if (this.nextD3D12FenceValue > this.d3D12Fence.Get()->GetCompletedValue())
{
this.d3D12Fence.Get()->SetEventOnCompletion(this.nextD3D12FenceValue, default);
}
this.nextD3D12FenceValue++;
}
}
}
+36
ファイルの表示
@@ -0,0 +1,36 @@
using System;
using System.Drawing;
using TerraFX.Interop;
namespace ComputeSharp.SwapChain.Backend
{
/// <summary>
/// A class representing a simple Win32 application.
/// </summary>
internal abstract class Win32Application
{
/// <summary>
/// Gets the title of the current application.
/// </summary>
public abstract string Title { get; }
/// <summary>
/// Initializes the current application.
/// </summary>
/// <param name="size">The window size.</param>
/// <param name="hwnd">The handle for the window.</param>
public abstract void OnInitialize(Size size, HWND hwnd);
/// <summary>
/// Resizes the current application.
/// </summary>
/// <param name="size">The new window size.</param>
public abstract void OnResize(Size size);
/// <summary>
/// Updates the current application.
/// </summary>
/// <param name="time">The current time since the start of the application.</param>
public abstract void OnUpdate(TimeSpan time);
}
}
+345
ファイルの表示
@@ -0,0 +1,345 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using TerraFX.Interop;
using FX = TerraFX.Interop.Windows;
namespace ComputeSharp.SwapChain.Backend
{
/// <summary>
/// A helper class to manage the creation and execution of Win32 applications.
/// </summary>
internal unsafe static class Win32ApplicationRunner
{
/// <summary>
/// Whether or not a resize operation is in progress.
/// </summary>
private static bool isResizing = false;
/// <summary>
/// Whether or not the application is currently paused.
/// </summary>
private static bool isPaused = false;
/// <summary>
/// The <see cref="HWND"/> for the application window.
/// </summary>
private static HWND hwnd;
/// <summary>
/// The current size of the application window.
/// </summary>
private static Size windowSize;
/// <summary>
/// A <see cref="Stopwatch"/> instance used to track the elapsed time for the application.
/// </summary>
private static Stopwatch stopwatch = null!;
/// <summary>
/// The application being run.
/// </summary>
private static Win32Application application = null!;
/// <summary>
/// The number of elapsed milliseconds since the window title was last updated.
/// </summary>
private static long elapsedMillisecondsForLastTitleUpdate;
/// <summary>
/// The number of elapsed frames since the window title was last updated.
/// </summary>
private static int elapsedFramesSinceLastTitleUpdate;
/// <summary>
/// Runs a specified application and starts the main loop to update its state.
/// This is the entry point for a given application of type <typeparamref name="T"/>, and it should be
/// called as soon as the process is launched, excluding any other additional initialization needed.
/// <para>To launch an application, simply add this line to the project being used:</para>
/// <c>Win32ApplicationRunner.Run&lt;MyApplication>();</c>
/// </summary>
/// <typeparam name="T">The type of application being launched.</typeparam>
/// <returns>The exit code for the application.</returns>
public static int Run(Win32Application application)
{
Win32ApplicationRunner.application = application;
IntPtr hInstance = FX.GetModuleHandleW(null);
uint width = 1280;
uint height = 720;
fixed (char* name = Assembly.GetExecutingAssembly().FullName)
fixed (char* windowTitle = application.Title)
{
// Initialize the window class
WNDCLASSEXW windowClassEx = new()
{
cbSize = (uint)sizeof(WNDCLASSEXW),
style = FX.CS_HREDRAW | FX.CS_VREDRAW,
lpfnWndProc = &WindowProc,
hInstance = hInstance,
hCursor = FX.LoadCursorW(IntPtr.Zero, FX.MAKEINTRESOURCE(32512)),
lpszClassName = (ushort*)name
};
// Register the window class
_ = FX.RegisterClassExW(&windowClassEx);
Rectangle windowRect = new(0, 0, (int)width, (int)height);
// Set the target window size
_ = FX.AdjustWindowRect((RECT*)&windowRect, FX.WS_OVERLAPPEDWINDOW, FX.FALSE);
height = (uint)(windowRect.Bottom - windowRect.Top);
width = (uint)(windowRect.Right - windowRect.Left);
// Create the window and store a handle to it
hwnd = FX.CreateWindowExW(
0,
windowClassEx.lpszClassName,
(ushort*)windowTitle,
FX.WS_OVERLAPPEDWINDOW,
FX.CW_USEDEFAULT,
FX.CW_USEDEFAULT,
(int)width,
(int)height,
HWND.NULL,
HMENU.NULL,
hInstance,
(void*)GCHandle.ToIntPtr(GCHandle.Alloc(application))
);
MARGINS margins = default;
margins.cxLeftWidth = -1;
margins.cxRightWidth = -1;
margins.cyTopHeight = -1;
margins.cyBottomHeight = -1;
_ = FX.DwmExtendFrameIntoClientArea(hwnd, &margins);
}
windowSize = new Size((int)height, (int)width);
// Initialize the application
application.OnInitialize(windowSize, hwnd);
// Display the window
_ = FX.ShowWindow(hwnd, FX.SW_SHOWDEFAULT);
// Start the timer
stopwatch = Stopwatch.StartNew();
MSG msg = default;
// Process any messages in the queue
while (msg.message != FX.WM_QUIT)
{
if (FX.PeekMessageW(&msg, HWND.NULL, 0, 0, FX.PM_REMOVE) != 0)
{
_ = FX.TranslateMessage(&msg);
_ = FX.DispatchMessageW(&msg);
}
else if (!isPaused || true)
{
RunApp();
}
else
{
Thread.Sleep(100);
}
}
// Return this part of the WM_QUIT message to Windows
return (int)msg.wParam;
}
/// <summary>
/// The application state update method that is invoked within the main application loop.
/// </summary>
private static void RunApp()
{
// Update window title approx every second
if (stopwatch.ElapsedMilliseconds - elapsedMillisecondsForLastTitleUpdate >= 1000)
{
string title = isPaused switch
{
true => $"{application.Title} - Paused",
false => $"{application.Title} - FPS: {elapsedFramesSinceLastTitleUpdate}"
};
fixed (char* pTitle = title)
{
_ = FX.SetWindowTextW(hwnd, (ushort*)pTitle);
}
elapsedMillisecondsForLastTitleUpdate = stopwatch.ElapsedMilliseconds;
elapsedFramesSinceLastTitleUpdate = 0;
}
// Update the application state
application.OnUpdate(stopwatch.Elapsed);
elapsedFramesSinceLastTitleUpdate++;
}
/// <summary>
/// Processes incoming messages for a window.
/// </summary>
/// <param name="hwnd">A handle to the window.</param>
/// <param name="uMsg">The message.</param>
/// <param name="wParam">Additional message information (the contents depend on the value of <paramref name="uMsg"/>).</param>
/// <param name="lParam">Additional message information (the contents depend on the value of <paramref name="uMsg"/>).</param>
/// <returns>The result of the message processing for the input message.</returns>
[UnmanagedCallersOnly]
private static nint WindowProc(IntPtr hwnd, uint uMsg, nuint wParam, nint lParam)
{
switch (uMsg)
{
// Change the paused state on window activation
case FX.WM_ACTIVATE:
{
if (FX.LOWORD(wParam) == FX.WA_INACTIVE)
{
isPaused = true;
}
else
{
isPaused = false;
}
return 0;
}
// Change the paused state when ESC is pressed
case FX.WM_KEYDOWN:
{
if ((ConsoleKey)wParam == ConsoleKey.Escape)
{
if (isPaused)
{
FX.SetCapture(hwnd);
}
else
{
FX.ReleaseCapture();
}
isPaused = !isPaused;
}
return 0;
}
// Window resize started
case FX.WM_ENTERSIZEMOVE:
{
isResizing = true;
return 0;
}
// Window resize completed
case FX.WM_EXITSIZEMOVE:
{
isResizing = false;
application.OnResize(windowSize);
return 0;
}
// Size update
case FX.WM_SIZE:
{
uint size = (uint)lParam;
windowSize = new Size(FX.LOWORD(size), FX.HIWORD(size));
if (!isResizing && wParam != FX.SIZE_MINIMIZED)
{
application.OnResize(windowSize);
}
return 0;
}
// Size and position of the window (needed to enable the borderless mode)
case FX.WM_NCCALCSIZE:
{
return 0;
}
// Enable dragging the window
case FX.WM_NCHITTEST:
{
POINT point;
RECT rect;
_ = FX.GetCursorPos(&point);
_ = FX.GetWindowRect(hwnd, &rect);
bool
isAtTop = Math.Abs(point.y - rect.top) < 12,
isAtRight = Math.Abs(point.x - rect.right) < 12,
isAtBottom = Math.Abs(point.y - rect.bottom) < 12,
isAtLeft = Math.Abs(point.x - rect.left) < 12;
if (isAtTop)
{
if (isAtRight) return FX.HTTOPRIGHT;
if (isAtLeft) return FX.HTTOPLEFT;
return FX.HTTOP;
}
if (isAtRight)
{
if (isAtTop) return FX.HTTOPRIGHT;
if (isAtBottom) return FX.HTBOTTOMRIGHT;
return FX.HTRIGHT;
}
if (isAtBottom)
{
if (isAtRight) return FX.HTBOTTOMRIGHT;
if (isAtLeft) return FX.HTBOTTOMLEFT;
return FX.HTBOTTOM;
}
if (isAtLeft)
{
if (isAtTop) return FX.HTTOPLEFT;
if (isAtBottom) return FX.HTBOTTOMLEFT;
return FX.HTLEFT;
}
return FX.HTCAPTION;
}
// Restore the drop shadow
case FX.WM_DWMCOMPOSITIONCHANGED:
{
MARGINS margins = default;
margins.cxLeftWidth = -1;
margins.cxRightWidth = -1;
margins.cyTopHeight = -1;
margins.cyBottomHeight = -1;
_ = FX.DwmExtendFrameIntoClientArea(hwnd, &margins);
return 0;
}
// Shutdown
case FX.WM_DESTROY:
{
FX.PostQuitMessage(0);
return 0;
}
}
return FX.DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
}
}
+16
ファイルの表示
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp\ComputeSharp.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"
PrivateAssets="contentfiles;build" />
</ItemGroup>
</Project>
+48
ファイルの表示
@@ -0,0 +1,48 @@
using System;
using ComputeSharp.SwapChain.Backend;
using ComputeSharp.SwapChain.Shaders;
namespace ComputeSharp.SwapChain
{
class Program
{
/// <summary>
/// The mapping of available samples to choose from.
/// </summary>
private static readonly Win32Application[] Samples = new Win32Application[]
{
new SwapChainApplication<ColorfulInfinity>(static (texture, time) => new(texture, (float)time.TotalSeconds)),
new SwapChainApplication<FractalTiling>(static (texture, time) => new(texture, (float)time.TotalSeconds)),
new SwapChainApplication<TwoTiledTruchet>(static (texture, time) => new(texture, (float)time.TotalSeconds)),
new SwapChainApplication<MengerJourney>(static (texture, time) => new(texture, (float)time.TotalSeconds)),
new SwapChainApplication<Octagrams>(static (texture, time) => new(texture, (float)time.TotalSeconds)),
new SwapChainApplication<ProteanClouds>(static (texture, time) => new(texture, (float)time.TotalSeconds))
};
static void Main()
{
Console.WriteLine("Available samples:");
Console.WriteLine();
for (int i = 0; i < Samples.Length; i++)
{
Console.WriteLine($"{i}: {Samples[i].GetType().GenericTypeArguments[0].Name}");
}
Console.WriteLine();
int index;
do
{
Console.Write("Enter the index of the sample to run: ");
}
while (!int.TryParse(Console.ReadLine(), out index));
Console.WriteLine();
Console.WriteLine($"Starting {Samples[index].GetType().GenericTypeArguments[0].Name}...");
Win32ApplicationRunner.Run(Samples[index]);
}
}
}
+79
ファイルの表示
@@ -0,0 +1,79 @@
namespace ComputeSharp.SwapChain.Shaders
{
/// <summary>
/// A shader creating an abstract and colorful animation.
/// Ported from <see href="https://www.shadertoy.com/view/WtjyzR"/>.
/// <para>Created by Benoit Marini.</para>
/// <para>License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.</para>
/// </summary>
[AutoConstructor]
internal readonly partial struct ColorfulInfinity : IComputeShader
{
/// <summary>
/// The target texture.
/// </summary>
public readonly IReadWriteTexture2D<Float4> texture;
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
/// <summary>
/// The total number of layers for the final animation.
/// </summary>
private const float NumberOfLayers = 16.0f;
/// <summary>
/// The number of iterations to calculate a texel value.
/// </summary>
private const int NumberOfIterations = 23;
/// <summary>
/// Makes some magic happen.
/// </summary>
private Float4 Tex(Float3 p)
{
float t = 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) +
new Float4(0.06f * Hlsl.Cos(t * 0.1f), 0, 0, 0.14f * Hlsl.Cos(t * 0.23f));
for (int i = 0; i++ < NumberOfIterations;)
{
o.XZYW = Hlsl.Abs(o / Hlsl.Dot(o, o) - dec);
}
return o;
}
/// <inheritdoc/>
public void Execute()
{
int width = texture.Width;
int height = texture.Height;
Float2 uv = ((Float2)ThreadIds.XY - (Float2)(new Int2(width, height)) * 0.5f) / height;
Float3 col = 0;
float t = time * 0.3f;
for (float i = 0.0f; i <= 1.0f; i += 1.0f / NumberOfLayers)
{
float d = Hlsl.Frac(i + t);
float s = Hlsl.Lerp(5.0f, 0.5f, d);
float f = d * Hlsl.SmoothStep(1.0f, 0.9f, d);
col += Tex(new Float3(uv.X * s, uv.Y * s, i * 4.0f)).XYZ * f;
}
col /= NumberOfLayers;
col *= new Float3(2, 1.0f, 2.0f);
col = Hlsl.Pow(col, 0.5f);
Float4 color = new(col.X, col.Y, col.Z, 1.0f);
texture[ThreadIds.XY] = color;
}
}
}
+51
ファイルの表示
@@ -0,0 +1,51 @@
namespace ComputeSharp.SwapChain.Shaders
{
/// <summary>
/// A shader creating a fractal tiling animation.
/// Ported from <see href="https://www.shadertoy.com/view/Ml2GWy"/>.
/// <para>Created by Inigo Quilez.</para>
/// <para>License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.</para>
/// </summary>
[AutoConstructor]
internal readonly partial struct FractalTiling : IComputeShader
{
/// <summary>
/// The target texture.
/// </summary>
public readonly IReadWriteTexture2D<Float4> texture;
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
/// <inheritdoc/>
public void Execute()
{
Float2 position = ((Float2)(256 * ThreadIds.XY)) / texture.Width + time;
Float4 color = 0;
for (int i = 0; i < 6; i++)
{
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) +
new Float4(0.035f, 0.01f, 0, 0.7f))
* 13.545317f);
color.XYZ += w.XYZ *
2.0f * Hlsl.SmoothStep(0.45f, 0.55f, w.W) *
Hlsl.Sqrt(16.0f * b.X * b.Y * (1.0f - b.X) * (1.0f - b.Y));
position /= 2.0f;
color /= 2.0f;
}
color.XYZ = Hlsl.Pow(color.XYZ, new Float3(0.7f, 0.8f, 0.5f));
color.W = 1.0f;
texture[ThreadIds.XY] = color;
}
}
}
+171
ファイルの表示
@@ -0,0 +1,171 @@
namespace ComputeSharp.SwapChain.Shaders
{
/// <summary>
/// A shader creating a flythrough in a Menger system.
/// Ported from <see href="https://www.shadertoy.com/view/Mdf3z7"/>.
/// <para>Created by Syntopia.</para>
/// </summary>
[AutoConstructor]
internal readonly partial struct MengerJourney : IComputeShader
{
/// <summary>
/// The target texture.
/// </summary>
public readonly IReadWriteTexture2D<Float4> texture;
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
private const int MaxSteps = 30;
private const float MinimumDistance = 0.0009f;
private const float normalDistance = 0.0002f;
private const int Iterations = 7;
private const float Scale = 3.0f;
private const float FieldOfView = 1.0f;
private const float Jitter = 0.05f;
private const float FudgeFactor = 0.7f;
private const float NonLinearPerspective = 2.0f;
private const float Ambient = 0.32184f;
private const float Diffuse = 0.5f;
/// <summary>
/// Rotates a given <see cref="Float2"/> value by a specified amount.
/// </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);
}
/// <summary>
/// Calculates the light at a specified normal and starting color.
/// Uses two light sources and no specular lights.
/// </summary>
private static Float3 GetLight(in Float3 color, in Float3 normal)
{
Float3 lightDir = Hlsl.Normalize((Float3)1);
float diffuse = Hlsl.Max(0.0f, Hlsl.Dot(-normal, lightDir));
Float3 lightDir2 = Hlsl.Normalize(new Float3(1.0f, -1.0f, 1.0f));
float diffuse2 = Hlsl.Max(0.0f, Hlsl.Dot(-normal, lightDir2));
return
(diffuse * Diffuse) * (new Float3(1.0f, 1.0f, 0.858824f) * color) +
(diffuse2 * Diffuse) * (new Float3(0.0f, 0.333333f, 1.0f) * color);
}
/// <summary>
/// DE: Infinitely tiled Menger IFS.
/// For more info on KIFS, see <a href="http://www.fractalforums.com/3d-fractal-generation/kaleidoscopic-%28escape-time-ifs%29/"/>
/// </summary>
private float DE(Float3 z)
{
// Performs the GLSL mod function.
static Float3 Mod(Float3 x, float y)
{
return x - y * Hlsl.Floor(x / y);
}
z = Hlsl.Abs(1.0f - Mod(z, 2.0f));
float d = 1000.0f;
Float3 Offset = new(0.92858f, 0.92858f, 0.32858f);
for (int n = 0; n < Iterations; n++)
{
z.XY = Rotate(z.XY, 4.0f + 2.0f * Hlsl.Cos(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);
if (z.Z < -0.5f * Offset.Z * (Scale - 1.0))
{
z.Z += Offset.Z * (Scale - 1.0f);
}
d = Hlsl.Min(d, Hlsl.Length(z) * Hlsl.Pow(Scale, -n - 1.0f));
}
return d - 0.001f;
}
/// <summary>
/// Calculates the finite difference normal at a given position.
/// </summary>
private Float3 getNormal(in Float3 pos)
{
Float3 e = new(0.0f, normalDistance, 0.0f);
return Hlsl.Normalize(new Float3(
DE(pos + e.YXX) - DE(pos - e.YXX),
DE(pos + e.XYX) - DE(pos - e.XYX),
DE(pos + e.XXY) - DE(pos - e.XXY)));
}
/// <summary>
/// Performs a ray march operation on a specific position.
/// </summary>
private Float4 RayMarch(in Float3 from, Float3 dir, in Float2 fragCoord)
{
// Computes a pseudo-random number
static float Rand(Float2 co)
{
return Hlsl.Frac(Hlsl.Cos(Hlsl.Dot(co, new Float2(4.898f, 7.23f))) * 23421.631f);
}
float totalDistance = Jitter * Rand(fragCoord.XY + time);
Float3 dir2 = dir;
float distance = 0;
int steps = 0;
Float3 pos = 0;
for (int i = 0; i < MaxSteps; i++)
{
dir.ZY = Rotate(dir2.ZY, totalDistance * Hlsl.Cos(time / 4.0f) * NonLinearPerspective);
pos = from + totalDistance * dir;
distance = DE(pos) * FudgeFactor;
totalDistance += distance;
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);
Float3 color = 1.0f;
Float3 light = GetLight(color, normal);
color = (color * Ambient + light) * ao;
return new(color.X, color.Y, color.Z, 1.0f);
}
/// <inheritdoc/>
public void 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 camDir = Hlsl.Normalize(target - camPos);
Float3 camUp = new Float3(0.0f, 1.0f, 0.0f);
camUp = Hlsl.Normalize(camUp - Hlsl.Dot(camDir, camUp) * camDir);
Float3 camRight = Hlsl.Normalize(Hlsl.Cross(camDir, camUp));
Float2 resolution = new(texture.Width, texture.Height);
Float2 coord = -1.0f + 2.0f * (Float2)ThreadIds.XY / resolution;
coord.X *= resolution.X / resolution.Y;
Float3 rayDir = Hlsl.Normalize(camDir + (coord.X * camRight + coord.Y * camUp) * FieldOfView);
texture[ThreadIds.XY] = RayMarch(camPos, rayDir, ThreadIds.XY);
}
}
}
+129
ファイルの表示
@@ -0,0 +1,129 @@
namespace ComputeSharp.SwapChain.Shaders
{
/// <summary>
/// A shader creating an octagram animation, inspired by arabesque.
/// Ported from <see href="https://www.shadertoy.com/view/tlVGDt"/>.
/// <para>Created by whisky_shusuky.</para>
/// </summary>
[AutoConstructor]
internal readonly partial struct Octagrams : IComputeShader
{
/// <summary>
/// The target texture.
/// </summary>
public readonly IReadWriteTexture2D<Float4> texture;
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
private static Float2x2 Rotate(float a)
{
float c = Hlsl.Cos(a), s = Hlsl.Sin(a);
return new(c, s, -s, c);
}
private static float Box(Float3 pos, float scale)
{
static float SDBox(Float3 p, Float3 b)
{
Float3 q = Hlsl.Abs(p) - b;
return Hlsl.Length(Hlsl.Max(q, 0.0f)) +
Hlsl.Min(Hlsl.Max(q.X, Hlsl.Max(q.Y, q.Z)), 0.0f);
}
pos *= scale;
float b = SDBox(pos, new(0.4f, 0.4f, 0.1f)) / 1.5f;
pos.XY *= 5.0f;
pos.Y -= 3.5f;
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.75f));
return -b;
}
private static float BoxSet(Float3 pos, float gTime)
{
Float3 pos_origin = pos;
pos = pos_origin;
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);
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);
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);
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);
pos = pos_origin;
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.8f));
float box5 = Box(pos, 0.5f) * 6.0f;
pos = pos_origin;
float box6 = Box(pos, 0.5f) * 6.0f;
float result = Hlsl.Max(Hlsl.Max(Hlsl.Max(Hlsl.Max(Hlsl.Max(box1, box2), box3), box4), box5), box6);
return result;
}
/// <inheritdoc/>
public void Execute()
{
Int2 resolution = new(texture.Width, texture.Height);
Float2 p = ((Float2)ThreadIds.XY * 2.0f - resolution) / Hlsl.Min(resolution.X, resolution.Y);
Float3 ro = new(0.0f, -0.2f, 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));
float t = 0.1f;
float ac = 0.0f;
for (int i = 0; i < 99; i++)
{
static Float3 Mod(Float3 x, float y)
{
return x - y * Hlsl.Floor(x / y);
}
Float3 pos = ro + ray * t;
pos = Mod(pos - 2.0f, 4.0f) - 2.0f;
float gTime = time - i * 0.01f;
float d = BoxSet(pos, gTime);
d = Hlsl.Max(Hlsl.Abs(d), 0.01f);
ac += Hlsl.Exp(-d * 23.0f);
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)));
texture[ThreadIds.XY] = color;
}
}
}
+174
ファイルの表示
@@ -0,0 +1,174 @@
namespace ComputeSharp.SwapChain.Shaders
{
/// <summary>
/// Fully procedural 3D animated volume with three evaluations per step (for shading).
/// Ported from <see href="https://www.shadertoy.com/view/3l23Rh"/>.
/// <para>Created by nimitz (twitter: @stormoid).</para>
/// <para>License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.</para>
/// </summary>
[AutoConstructor]
internal readonly partial struct ProteanClouds : IComputeShader
{
/// <summary>
/// The target texture.
/// </summary>
public readonly IReadWriteTexture2D<Float4> texture;
/// <summary>
/// The current time Hlsl.Since the start of the application.
/// </summary>
public readonly float time;
private static Float2x2 Rotate(in float a)
{
float c = Hlsl.Cos(a), s = Hlsl.Sin(a);
return new(c, s, -s, c);
}
private static float LinStep(in float mn, in float mx, in float x)
{
return Hlsl.Clamp((x - mn) / (mx - mn), 0.0f, 1.0f);
}
private static Float2 Disp(float t)
{
return new Float2(Hlsl.Sin(t * 0.22f) * 1.0f, Hlsl.Cos(t * 0.175f) * 1.0f) * 2.0f;
}
private Float2 Map(Float3 p, float prm1, Float2 bsMo)
{
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));
float cl = Hlsl.Dot(p2.XY, p2.XY);
float d = 0.0f;
p *= 0.61f;
float z = 1.0f;
float trk = 1.0f;
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;
d -= Hlsl.Abs(Hlsl.Dot(Hlsl.Cos(p), Hlsl.Sin(p.YZX)) * z);
z *= 0.57f;
trk *= 1.4f;
Float3x3 m3 = new Float3x3(0.33338f, 0.56034f, -0.71817f, -0.87887f, 0.32651f, -0.15323f, 0.15162f, 0.69596f, 0.61339f) * 1.93f;
p = Hlsl.Mul(p, m3);
}
d = Hlsl.Abs(d + prm1 * 3.0f) + prm1 * 0.3f - 2.5f + bsMo.Y;
return new Float2(d + cl * 0.2f + 0.25f, cl);
}
private Float4 Render(Float3 ro, Float3 rd, float time, float prm1, Float2 bsMo)
{
Float4 rez = 0;
float t = 1.5f;
float fogT = 0;
for (int i = 0; i < 130; i++)
{
if (rez.A > 0.99f) break;
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);
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 *= 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);
}
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);
}
return Hlsl.Clamp(rez, 0.0f, 1.0f);
}
private static float GetSaturation(Float3 c)
{
float mi = Hlsl.Min(Hlsl.Min(c.X, c.Y), c.Z);
float ma = Hlsl.Max(Hlsl.Max(c.X, c.Y), c.Z);
return (ma - mi) / (ma + (float)1e-7);
}
private static Float3 ILerp(in Float3 a, in Float3 b, in float x)
{
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));
float lgt = Hlsl.Dot(1.0f, ic);
float ff = Hlsl.Dot(dir, Hlsl.Normalize(ic));
ic += 1.5f * dir * sd * ff * lgt;
return Hlsl.Clamp(ic, 0.0f, 1.0f);
}
/// <inheritdoc/>
public void Execute()
{
Int2 resolution = new(texture.Width, texture.Height);
Float2 q = (Float2)ThreadIds.XY / resolution;
Float2 p = (ThreadIds.XY - 0.5f * (Float2)resolution) / resolution.Y;
Float2 bsMo = -0.5f * (Float2)resolution / resolution.Y;
float scaledTime = 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);
float dspAmp = 0.85f;
ro.XY += Disp(ro.Z) * dspAmp;
float tgtDst = 3.5f;
Float3 target = Hlsl.Normalize(ro - new Float3(Disp(scaledTime + tgtDst) * dspAmp, scaledTime + tgtDst));
ro.X -= bsMo.X * 2.0f;
Float3 rightdir = Hlsl.Normalize(Hlsl.Cross(target, new Float3(0, 1, 0)));
Float3 updir = Hlsl.Normalize(Hlsl.Cross(rightdir, target));
rightdir = Hlsl.Normalize(Hlsl.Cross(updir, 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));
float prm1 = Hlsl.SmoothStep(-0.4f, 0.4f, Hlsl.Sin(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;
texture[ThreadIds.XY] = new Float4(col, 1.0f);
}
}
}
+152
ファイルの表示
@@ -0,0 +1,152 @@
namespace ComputeSharp.SwapChain.Shaders
{
/// <summary>
/// A shader creating an animated two-tiles Truchet arrangement.
/// Ported from <see href="https://www.shadertoy.com/view/tsSfWK"/>.
/// <para>Created by Shane.</para>
/// </summary>
[AutoConstructor]
internal readonly partial struct TwoTiledTruchet : IComputeShader
{
/// <summary>
/// The target texture.
/// </summary>
public readonly IReadWriteTexture2D<Float4> texture;
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
/// <summary>
/// Calculates the Truchet distance field.
/// </summary>
/// <param name="p">The input value to compute the distance field for.</param>
/// <param name="ang">The resulting Truchet angle.</param>
/// <returns>The distance field for the input value.</returns>
private Float2 DistanceField(Float2 p, out Float2 ang)
{
// Fast hash for a pair of floats
static float Hash21(Float2 p)
{
return Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new Float2(27.619f, 57.583f))) * 43758.5453f);
}
// HLSL's port of the GLSL mod intrinsic
static float Mod(float x, float y)
{
return x - y * Hlsl.Floor(x / y);
}
Float2 ip2 = Hlsl.Floor(p / 2.0f);
Float2 ip = Hlsl.Floor(p);
float rnd = Hash21(ip);
float rnd3 = Hash21(ip + 0.57f);
Float2 d = 1e5f;
p -= ip + 0.5f;
if (Mod(ip2.X + ip2.Y, 2.0f) < 0.5f)
{
d = Hlsl.Abs(p);
ang = p.YX;
if (Mod(ip.X + 1.0f, 2.0f) < 0.5f)
{
ang.X *= -1.0f;
}
if (Mod(ip.Y + 1.0f, 2.0f) > 0.5f)
{
ang.Y *= -1.0f;
}
if (rnd3 < .5)
{
d = d.YX;
ang = ang.YX;
}
ang += 0.5f;
ang *= 3.0f;
}
else
{
if (rnd < .5)
{
p = p.YX * new Float2(1, -1);
}
d.X = Hlsl.Length(p - 0.5f) - 0.5f;
d.Y = Hlsl.Length(p + 0.5f) - 0.5f;
d = Hlsl.Abs(d);
ang = 0;
ang.X = -Hlsl.Atan((p.Y - 0.5f) / (p.X - 0.5f));
ang.Y = -Hlsl.Atan((p.Y + 0.5f) / (p.X + 0.5f));
if (Mod(ip.X + ip.Y, 2.0f) < 0.5f)
{
ang *= -1.0f;
}
if (rnd < 0.5f)
{
ang *= -1.0f;
}
if (rnd3 < 0.5f)
{
d = d.YX;
ang = ang.YX;
}
ang *= 4.0f / 6.2831853f;
ang *= 2.0f;
}
ang = Hlsl.Frac(ang + time / 4.0f);
return d;
}
/// <inheritdoc/>
public void Execute()
{
int width = texture.Width;
int height = texture.Height;
Float2 uv = ((Float2)ThreadIds.XY - (Float2)(new Int2(width, height)) * 0.5f) / height;
float gSc = 7.0f;
Float2 p = uv * gSc - new Float2(-1, -0.5f) * time / 2.0f;
float sf = 2.0f / height * gSc;
float lSc = 6.0f;
float lw = 1.0f / lSc / gSc;
Float2 d = DistanceField(p, out Float2 ang) - 2.5f / lSc;
Float3 col = new Float3(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 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));
}
Float3 rgb = Hlsl.Sqrt(Hlsl.Max(col, 0.0f));
Float4 color = new(rgb.X, rgb.Y, rgb.Z, 1.0f);
texture[ThreadIds.XY] = color;
}
}
}
-11
ファイルの表示
@@ -1,11 +0,0 @@
using System;
namespace ComputeSharp.Core.Attributes
{
/// <summary>
/// An attribute to indicate that a given member has the same name when mapped to HLSL
/// </summary>
internal sealed class PreserveMemberNameAttribute : Attribute
{
}
}
-7
ファイルの表示
@@ -1,7 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
</Project>
-61
ファイルの表示
@@ -1,61 +0,0 @@
using System;
using System.Diagnostics.Contracts;
using System.Numerics;
using System.Runtime.InteropServices;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="class"/> that contains extension methods for the <see cref="Vector2"/>, <see cref="Vector3"/> and <see cref="Vector4"/> types
/// </summary>
public static class VectorExtensions
{
/// <summary>
/// Converts a <see cref="Vector2"/> array into a <see cref="Span{T}"/> with items of type <see cref="Float2"/>
/// </summary>
/// <param name="array">The input <see cref="Vector2"/> array</param>
/// <returns>A <see cref="Span{T}"/> with items of type <see cref="Float2"/>, mapping the original array</returns>
[Pure]
public static Span<Float2> AsFloat2Span(this Vector2[] array) => MemoryMarshal.Cast<Vector2, Float2>(array);
/// <summary>
/// Converts a <see cref="Vector2"/> <see cref="Span{T}"/> into a <see cref="Span{T}"/> with items of type <see cref="Float2"/>
/// </summary>
/// <param name="span">The input <see cref="Vector2"/> <see cref="Span{T}"/></param>
/// <returns>A <see cref="Span{T}"/> with items of type <see cref="Float2"/>, mapping the original <see cref="Span{T}"/></returns>
[Pure]
public static Span<Float2> AsFloat2Span(this Span<Vector2> span) => MemoryMarshal.Cast<Vector2, Float2>(span);
/// <summary>
/// Converts a <see cref="Vector3"/> array into a <see cref="Span{T}"/> with items of type <see cref="Float3"/>
/// </summary>
/// <param name="array">The input <see cref="Vector3"/> array</param>
/// <returns>A <see cref="Span{T}"/> with items of type <see cref="Float3"/>, mapping the original array</returns>
[Pure]
public static Span<Float3> AsFloat3Span(this Vector3[] array) => MemoryMarshal.Cast<Vector3, Float3>(array);
/// <summary>
/// Converts a <see cref="Vector3"/> <see cref="Span{T}"/> into a <see cref="Span{T}"/> with items of type <see cref="Float3"/>
/// </summary>
/// <param name="span">The input <see cref="Vector3"/> <see cref="Span{T}"/></param>
/// <returns>A <see cref="Span{T}"/> with items of type <see cref="Float3"/>, mapping the original <see cref="Span{T}"/></returns>
[Pure]
public static Span<Float3> AsFloat3Span(this Span<Vector3> span) => MemoryMarshal.Cast<Vector3, Float3>(span);
/// <summary>
/// Converts a <see cref="Vector4"/> array into a <see cref="Span{T}"/> with items of type <see cref="Float4"/>
/// </summary>
/// <param name="array">The input <see cref="Vector4"/> array</param>
/// <returns>A <see cref="Span{T}"/> with items of type <see cref="Float4"/>, mapping the original array</returns>
[Pure]
public static Span<Float4> AsFloat4Span(this Vector4[] array) => MemoryMarshal.Cast<Vector4, Float4>(array);
/// <summary>
/// Converts a <see cref="Vector4"/> <see cref="Span{T}"/> into a <see cref="Span{T}"/> with items of type <see cref="Float4"/>
/// </summary>
/// <param name="span">The input <see cref="Vector4"/> <see cref="Span{T}"/></param>
/// <returns>A <see cref="Span{T}"/> with items of type <see cref="Float4"/>, mapping the original <see cref="Span{T}"/></returns>
[Pure]
public static Span<Float4> AsFloat4Span(this Span<Vector4> span) => MemoryMarshal.Cast<Vector4, Float4>(span);
}
}
ファイル差分が大きすぎるため表示されません。 差分を読み込み
-159
ファイルの表示
@@ -1,159 +0,0 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using ComputeSharp.Exceptions;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="struct"/> that maps the <see langword="bool2"/> HLSL type
/// </summary>
[DebuggerDisplay("({X}, {Y})")]
[StructLayout(LayoutKind.Explicit, Size = sizeof(int) * 2)]
public struct Bool2
{
/// <summary>
/// Gets an <see cref="Bool2"/> value with all components set to <see langword="false"/>
/// </summary>
public static Bool2 False => false;
/// <summary>
/// Gets an <see cref="Bool2"/> value with all components set to <see langword="true"/>
/// </summary>
public static Bool2 True => true;
/// <summary>
/// Gets an <see cref="Bool2"/> value with the <see cref="X"/> component set to <see langword="true"/>, and the others to <see langword="false"/>
/// </summary>
public static Bool2 TrueX => new Bool2(true, false);
/// <summary>
/// Gets an <see cref="Bool2"/> value with the <see cref="Y"/> component set to <see langword="true"/>, and the others to <see langword="false"/>
/// </summary>
public static Bool2 TrueY => new Bool2(false, true);
/// <summary>
/// Creates a new <see cref="Bool2"/> instance with the specified parameters
/// </summary>
/// <param name="x">The value to assign to the first vector component</param>
/// <param name="y">The value to assign to the second vector component</param>
public Bool2(bool x, bool y)
{
_X = x;
_Y = y;
}
[FieldOffset(0)]
private bool _X;
/// <summary>
/// Gets or sets the value of the first vector component
/// </summary>
public bool X
{
get => _X;
set => _X = value;
}
[FieldOffset(4)]
private bool _Y;
/// <summary>
/// Gets or sets the value of the second vector component
/// </summary>
public bool Y
{
get => _Y;
set => _Y = value;
}
/// <summary>
/// Gets or sets the value of the first color component
/// </summary>
public bool R
{
get => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(R)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(R)}");
}
/// <summary>
/// Gets or sets the value of the second color component
/// </summary>
public bool G
{
get => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(G)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(G)}");
}
/// <summary>
/// Gets or sets a specific component in the current <see cref="Bool2"/> instance
/// </summary>
/// <param name="i">The index of the component to access</param>
public bool this[int i]
{
get => throw new InvalidExecutionContextException($"{nameof(Bool2)}[int]");
set => throw new InvalidExecutionContextException($"{nameof(Bool2)}[int]");
}
/// <summary>
/// Gets an <see cref="Bool2"/> value with the <see cref="X"/> value for all components
/// </summary>
public Bool2 XX => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(XX)}");
/// <summary>
/// Gets or sets an <see cref="Bool2"/> value with the <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Bool2 XY
{
get => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(XY)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(XY)}");
}
/// <summary>
/// Gets an <see cref="Bool2"/> value with the <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Bool2 YX
{
get => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(YX)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(YX)}");
}
/// <summary>
/// Gets an <see cref="Bool2"/> value with the <see cref="Y"/> value for all components
/// </summary>
public Bool2 YY => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(YY)}");
/// <summary>
/// Gets an <see cref="Bool2"/> value with the <see cref="R"/> value for all components
/// </summary>
public Bool2 RR => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(RR)}");
/// <summary>
/// Gets or sets an <see cref="Bool2"/> value with the <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Bool2 RG
{
get => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(RG)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(RG)}");
}
/// <summary>
/// Gets an <see cref="Bool2"/> value with the <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Bool2 GR
{
get => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(GR)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(GR)}");
}
/// <summary>
/// Gets an <see cref="Bool2"/> value with the <see cref="G"/> value for all components
/// </summary>
public Bool2 GG => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(GG)}");
/// <summary>
/// Creates a new <see cref="Bool2"/> value with the same value for all its components
/// </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 Bool2(x, x);
}
}
-587
ファイルの表示
@@ -1,587 +0,0 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using ComputeSharp.Exceptions;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="struct"/> that maps the <see langword="bool3"/> HLSL type
/// </summary>
[DebuggerDisplay("({X}, {Y}, {Z})")]
[StructLayout(LayoutKind.Explicit, Size = sizeof(int) * 3)]
public struct Bool3
{
/// <summary>
/// Gets an <see cref="Bool3"/> value with all components set to <see langword="false"/>
/// </summary>
public static Bool3 False => false;
/// <summary>
/// Gets an <see cref="Bool3"/> value with all components set to <see langword="true"/>
/// </summary>
public static Bool3 True => true;
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="X"/> component set to <see langword="true"/>, and the others to <see langword="false"/>
/// </summary>
public static Bool3 TrueX => new Bool3(true, false, false);
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="Y"/> component set to <see langword="true"/>, and the others to <see langword="false"/>
/// </summary>
public static Bool3 TrueY => new Bool3(false, true, false);
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="Z"/> component set to <see langword="true"/>, and the others to <see langword="false"/>
/// </summary>
public static Bool3 TrueZ => new Bool3(false, false, true);
/// <summary>
/// Creates a new <see cref="Bool3"/> instance with the specified parameters
/// </summary>
/// <param name="x">The value to assign to the first vector component</param>
/// <param name="y">The value to assign to the second vector component</param>
/// <param name="z">The value to assign to the third vector component</param>
public Bool3(bool x, bool y, bool z)
{
_X = x;
_Y = y;
_Z = z;
}
[FieldOffset(0)]
private bool _X;
/// <summary>
/// Gets or sets the value of the first vector component
/// </summary>
public bool X
{
get => _X;
set => _X = value;
}
[FieldOffset(4)]
private bool _Y;
/// <summary>
/// Gets or sets the value of the second vector component
/// </summary>
public bool Y
{
get => _Y;
set => _Y = value;
}
[FieldOffset(8)]
private bool _Z;
/// <summary>
/// Gets or sets the value of the third vector component
/// </summary>
public bool Z
{
get => _Z;
set => _Z = value;
}
/// <summary>
/// Gets or sets the value of the first color component
/// </summary>
public bool R
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(R)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(R)}");
}
/// <summary>
/// Gets or sets the value of the second color component
/// </summary>
public bool G
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(G)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(G)}");
}
/// <summary>
/// Gets or sets the value of the third color component
/// </summary>
public bool B
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(B)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(B)}");
}
/// <summary>
/// Gets or sets a specific component in the current <see cref="Bool3"/> instance
/// </summary>
/// <param name="i">The index of the component to access</param>
public bool this[int i]
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}[int]");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}[int]");
}
/// <summary>
/// Gets an <see cref="Bool2"/> value with the <see cref="X"/> value for all components
/// </summary>
public Bool2 XX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XX)}");
/// <summary>
/// Gets or sets an <see cref="Bool2"/> value with the <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Bool2 XY
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XY)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XY)}");
}
/// <summary>
/// Gets or sets an <see cref="Bool2"/> value with the <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public Bool2 XZ
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XZ)}");
}
/// <summary>
/// Gets or sets an <see cref="Bool2"/> value with the <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Bool2 YX
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YX)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YX)}");
}
/// <summary>
/// Gets an <see cref="Bool2"/> value with the <see cref="Y"/> value for all components
/// </summary>
public Bool2 YY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YY)}");
/// <summary>
/// Gets or sets an <see cref="Bool2"/> value with the <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public Bool2 YZ
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YZ)}");
}
/// <summary>
/// Gets or sets an <see cref="Bool2"/> value with the <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public Bool2 ZX
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZX)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZX)}");
}
/// <summary>
/// Gets or sets an <see cref="Bool2"/> value with the <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public Bool2 ZY
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZY)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZY)}");
}
/// <summary>
/// Gets an <see cref="Bool2"/> value with the <see cref="Z"/> value for all components
/// </summary>
public Bool2 ZZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZZ)}");
/// <summary>
/// Gets an <see cref="Bool2"/> value with the <see cref="R"/> value for all components
/// </summary>
public Bool2 RR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RR)}");
/// <summary>
/// Gets or sets an <see cref="Bool2"/> value with the <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Bool2 RG
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RG)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RG)}");
}
/// <summary>
/// Gets or sets an <see cref="Bool2"/> value with the <see cref="R"/> and <see cref="B"/> values
/// </summary>
public Bool2 RB
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RB)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RB)}");
}
/// <summary>
/// Gets or sets an <see cref="Bool2"/> value with the <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Bool2 GR
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GR)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GR)}");
}
/// <summary>
/// Gets an <see cref="Bool2"/> value with the <see cref="G"/> value for all components
/// </summary>
public Bool2 GG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GG)}");
/// <summary>
/// Gets or sets an <see cref="Bool2"/> value with the <see cref="G"/> and <see cref="B"/> values
/// </summary>
public Bool2 GB
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GB)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GB)}");
}
/// <summary>
/// Gets or sets an <see cref="Bool2"/> value with the <see cref="B"/> and <see cref="R"/> values
/// </summary>
public Bool2 BR
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BR)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BR)}");
}
/// <summary>
/// Gets or sets an <see cref="Bool2"/> value with the <see cref="B"/> and <see cref="G"/> values
/// </summary>
public Bool2 BG
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BG)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BG)}");
}
/// <summary>
/// Gets an <see cref="Bool2"/> value with the <see cref="B"/> value for all components
/// </summary>
public Bool2 BB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BB)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="X"/> value for all components
/// </summary>
public Bool2 XXX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XXX)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Bool2 XXY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XXY)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public Bool2 XXZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XXZ)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Bool2 XYX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XYX)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Y"/> values
/// </summary>
public Bool2 XYY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XYY)}");
/// <summary>
/// Gets or sets an <see cref="Bool3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public Bool2 XYZ
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XYZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XYZ)}");
}
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public Bool2 XZX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XZX)}");
/// <summary>
/// Gets or sets an <see cref="Bool3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public Bool2 XZY
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XZY)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XZY)}");
}
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Z"/> values
/// </summary>
public Bool2 XZZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XZZ)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="X"/> values
/// </summary>
public Bool2 YXX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YXX)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Bool2 YXY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YXY)}");
/// <summary>
/// Gets or sets an <see cref="Bool3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public Bool2 YXZ
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YXZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YXZ)}");
}
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Bool2 YYX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YYX)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="Y"/> value for all components
/// </summary>
public Bool2 YYY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YYY)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public Bool2 YYZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YYZ)}");
/// <summary>
/// Gets or sets an <see cref="Bool3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public Bool2 YZX
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YZX)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YZX)}");
}
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public Bool2 YZY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YZY)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Z"/> values
/// </summary>
public Bool2 YZZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YZZ)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Z"/> values
/// </summary>
public Bool2 ZXX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZXX)}");
/// <summary>
/// Gets or sets an <see cref="Bool3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Bool2 ZXY
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZXY)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZXY)}");
}
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public Bool2 ZXZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZXZ)}");
/// <summary>
/// Gets or sets an <see cref="Bool3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Bool2 ZYX
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZYX)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZYX)}");
}
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Y"/> values
/// </summary>
public Bool2 ZYY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZYY)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public Bool2 ZYZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZYZ)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public Bool2 ZZX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZZX)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public Bool2 ZZY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZZY)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="Z"/> value for all components
/// </summary>
public Bool2 ZZZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZZZ)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="R"/> value for all components
/// </summary>
public Bool2 RRR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RRR)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="R"/>, <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Bool2 RRG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RRG)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="R"/>, <see cref="R"/> and <see cref="B"/> values
/// </summary>
public Bool2 RRB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RRB)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="R"/>, <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Bool2 RGR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RGR)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="R"/>, <see cref="G"/> and <see cref="G"/> values
/// </summary>
public Bool2 RGG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RGG)}");
/// <summary>
/// Gets or sets an <see cref="Bool3"/> value with the <see cref="R"/>, <see cref="G"/> and <see cref="B"/> values
/// </summary>
public Bool2 RGB
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RGB)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RGB)}");
}
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="R"/>, <see cref="B"/> and <see cref="R"/> values
/// </summary>
public Bool2 RBR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RBR)}");
/// <summary>
/// Gets or sets an <see cref="Bool3"/> value with the <see cref="R"/>, <see cref="B"/> and <see cref="G"/> values
/// </summary>
public Bool2 RBG
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RBG)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RBG)}");
}
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="R"/>, <see cref="B"/> and <see cref="B"/> values
/// </summary>
public Bool2 RBB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RBB)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="G"/>, <see cref="R"/> and <see cref="R"/> values
/// </summary>
public Bool2 GRR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GRR)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="G"/>, <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Bool2 GRG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GRG)}");
/// <summary>
/// Gets or sets an <see cref="Bool3"/> value with the <see cref="G"/>, <see cref="R"/> and <see cref="B"/> values
/// </summary>
public Bool2 GRB
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GRB)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GRB)}");
}
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="G"/>, <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Bool2 GGR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GGR)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="G"/> value for all components
/// </summary>
public Bool2 GGG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GGG)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="G"/>, <see cref="G"/> and <see cref="B"/> values
/// </summary>
public Bool2 GGB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GGB)}");
/// <summary>
/// Gets or sets an <see cref="Bool3"/> value with the <see cref="G"/>, <see cref="B"/> and <see cref="R"/> values
/// </summary>
public Bool2 GBR
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GBR)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GBR)}");
}
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="G"/>, <see cref="B"/> and <see cref="G"/> values
/// </summary>
public Bool2 GBG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GBG)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="G"/>, <see cref="B"/> and <see cref="B"/> values
/// </summary>
public Bool2 GBB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GBB)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="B"/>, <see cref="B"/> and <see cref="B"/> values
/// </summary>
public Bool2 BRR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BRR)}");
/// <summary>
/// Gets or sets an <see cref="Bool3"/> value with the <see cref="B"/>, <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Bool2 BRG
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BRG)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BRG)}");
}
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="B"/>, <see cref="R"/> and <see cref="B"/> values
/// </summary>
public Bool2 BRB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BRB)}");
/// <summary>
/// Gets or sets an <see cref="Bool3"/> value with the <see cref="B"/>, <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Bool2 BGR
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BGR)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BGR)}");
}
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="B"/>, <see cref="G"/> and <see cref="G"/> values
/// </summary>
public Bool2 BGG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BGG)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="B"/>, <see cref="G"/> and <see cref="B"/> values
/// </summary>
public Bool2 BGB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BGB)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="B"/>, <see cref="B"/> and <see cref="R"/> values
/// </summary>
public Bool2 BBR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BBR)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="B"/>, <see cref="B"/> and <see cref="G"/> values
/// </summary>
public Bool2 BBG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BBG)}");
/// <summary>
/// Gets an <see cref="Bool3"/> value with the <see cref="B"/> value for all components
/// </summary>
public Bool2 BBB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BBB)}");
/// <summary>
/// Creates a new <see cref="Bool3"/> value with the same value for all its components
/// </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 Bool3(x, x, x);
}
}
ファイル差分が大きすぎるため表示されません。 差分を読み込み
-173
ファイルの表示
@@ -1,173 +0,0 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using ComputeSharp.Exceptions;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="struct"/> that maps the <see langword="double2"/> HLSL type
/// </summary>
[DebuggerDisplay("({X}, {Y})")]
[StructLayout(LayoutKind.Sequential, Size = sizeof(double) * 2)]
public struct Double2
{
/// <summary>
/// Gets an <see cref="Double2"/> value with all components set to 0
/// </summary>
public static Double2 Zero => 0;
/// <summary>
/// Gets an <see cref="Double2"/> value with all components set to 1
/// </summary>
public static Double2 One => 1;
/// <summary>
/// Gets an <see cref="Double2"/> value with the <see cref="X"/> component set to 1, and the others to 0
/// </summary>
public static Double2 UnitX => new Double2(1, 0);
/// <summary>
/// Gets an <see cref="Double2"/> value with the <see cref="Y"/> component set to 1, and the others to 0
/// </summary>
public static Double2 UnitY => new Double2(0, 1);
/// <summary>
/// Creates a new <see cref="Double2"/> instance with the specified parameters
/// </summary>
/// <param name="x">The value to assign to the first vector component</param>
/// <param name="y">The value to assign to the second vector component</param>
public Double2(double x, double y)
{
X = x;
Y = y;
}
/// <summary>
/// Gets or sets the value of the first vector component
/// </summary>
public double X { get; set; }
/// <summary>
/// Gets or sets the value of the second vector component
/// </summary>
public double Y { get; set; }
/// <summary>
/// Gets or sets the value of the first color component
/// </summary>
public double R
{
get => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(R)}");
set => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(R)}");
}
/// <summary>
/// Gets or sets the value of the second color component
/// </summary>
public double G
{
get => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(G)}");
set => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(G)}");
}
/// <summary>
/// Gets or sets a specific component in the current <see cref="Double2"/> instance
/// </summary>
/// <param name="i">The index of the component to access</param>
public double this[int i]
{
get => throw new InvalidExecutionContextException($"{nameof(Double2)}[int]");
set => throw new InvalidExecutionContextException($"{nameof(Double2)}[int]");
}
/// <summary>
/// Gets an <see cref="Double2"/> value with the <see cref="X"/> value for all components
/// </summary>
public Double2 XX => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(XX)}");
/// <summary>
/// Gets or sets an <see cref="Double2"/> value with the <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Double2 XY
{
get => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(XY)}");
set => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(XY)}");
}
/// <summary>
/// Gets an <see cref="Double2"/> value with the <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Double2 YX
{
get => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(YX)}");
set => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(YX)}");
}
/// <summary>
/// Gets an <see cref="Double2"/> value with the <see cref="Y"/> value for all components
/// </summary>
public Double2 YY => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(YY)}");
/// <summary>
/// Gets an <see cref="Double2"/> value with the <see cref="R"/> value for all components
/// </summary>
public Double2 RR => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(RR)}");
/// <summary>
/// Gets or sets an <see cref="Double2"/> value with the <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Double2 RG
{
get => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(RG)}");
set => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(RG)}");
}
/// <summary>
/// Gets an <see cref="Double2"/> value with the <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Double2 GR
{
get => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(GR)}");
set => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(GR)}");
}
/// <summary>
/// Gets an <see cref="Double2"/> value with the <see cref="G"/> value for all components
/// </summary>
public Double2 GG => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(GG)}");
/// <summary>
/// Creates a new <see cref="Double2"/> value with the same value for all its components
/// </summary>
/// <param name="x">The value to use for the components of the new <see cref="Double2"/> instance</param>
public static implicit operator Double2(double x) => new Double2(x, x);
/// <summary>
/// Sums two <see cref="Double2"/> values
/// </summary>
/// <param name="left">The first <see cref="Double2"/> value to sum</param>
/// <param name="right">The second <see cref="Double2"/> value to sum</param>
public static Double2 operator +(Double2 left, Double2 right) => throw new InvalidExecutionContextException($"{nameof(Double2)}.+");
/// <summary>
/// Divides two <see cref="Double2"/> values
/// </summary>
/// <param name="left">The first <see cref="Double2"/> value to divide</param>
/// <param name="right">The second <see cref="Double2"/> value to divide</param>
public static Double2 operator /(Double2 left, Double2 right) => throw new InvalidExecutionContextException($"{nameof(Double2)}./");
/// <summary>
/// Multiplies two <see cref="Double2"/> values
/// </summary>
/// <param name="left">The first <see cref="Double2"/> value to multiply</param>
/// <param name="right">The second <see cref="Double2"/> value to multiply</param>
public static Double2 operator *(Double2 left, Double2 right) => throw new InvalidExecutionContextException($"{nameof(Double2)}.*");
/// <summary>
/// Subtracts two <see cref="Double2"/> values
/// </summary>
/// <param name="left">The first <see cref="Double2"/> value to subtract</param>
/// <param name="right">The second <see cref="Double2"/> value to subtract</param>
public static Double2 operator -(Double2 left, Double2 right) => throw new InvalidExecutionContextException($"{nameof(Double2)}.-");
}
}
-594
ファイルの表示
@@ -1,594 +0,0 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using ComputeSharp.Exceptions;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="struct"/> that maps the <see langword="double3"/> HLSL type
/// </summary>
[DebuggerDisplay("({X}, {Y}, {Z})")]
[StructLayout(LayoutKind.Sequential, Size = sizeof(double) * 3)]
public struct Double3
{
/// <summary>
/// Gets an <see cref="Double3"/> value with all components set to 0
/// </summary>
public static Double3 Zero => 0;
/// <summary>
/// Gets an <see cref="Double3"/> value with all components set to 1
/// </summary>
public static Double3 One => 1;
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="X"/> component set to 1, and the others to 0
/// </summary>
public static Double3 UnitX => new Double3(1, 0, 0);
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="Y"/> component set to 1, and the others to 0
/// </summary>
public static Double3 UnitY => new Double3(0, 1, 0);
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="Z"/> component set to 1, and the others to 0
/// </summary>
public static Double3 UnitZ => new Double3(0, 0, 1);
/// <summary>
/// Creates a new <see cref="Double3"/> instance with the specified parameters
/// </summary>
/// <param name="x">The value to assign to the first vector component</param>
/// <param name="y">The value to assign to the second vector component</param>
/// <param name="z">The value to assign to the third vector component</param>
public Double3(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}
/// <summary>
/// Gets or sets the value of the first vector component
/// </summary>
public double X { get; set; }
/// <summary>
/// Gets or sets the value of the second vector component
/// </summary>
public double Y { get; set; }
/// <summary>
/// Gets or sets the value of the third vector component
/// </summary>
public double Z { get; set; }
/// <summary>
/// Gets or sets the value of the first color component
/// </summary>
public double R
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(R)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(R)}");
}
/// <summary>
/// Gets or sets the value of the second color component
/// </summary>
public double G
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(G)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(G)}");
}
/// <summary>
/// Gets or sets the value of the third color component
/// </summary>
public double B
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(B)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(B)}");
}
/// <summary>
/// Gets or sets a specific component in the current <see cref="Double3"/> instance
/// </summary>
/// <param name="i">The index of the component to access</param>
public double this[int i]
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}[int]");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}[int]");
}
/// <summary>
/// Gets an <see cref="Double2"/> value with the <see cref="X"/> value for all components
/// </summary>
public Double2 XX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XX)}");
/// <summary>
/// Gets or sets an <see cref="Double2"/> value with the <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Double2 XY
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XY)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XY)}");
}
/// <summary>
/// Gets or sets an <see cref="Double2"/> value with the <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public Double2 XZ
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XZ)}");
}
/// <summary>
/// Gets or sets an <see cref="Double2"/> value with the <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Double2 YX
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YX)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YX)}");
}
/// <summary>
/// Gets an <see cref="Double2"/> value with the <see cref="Y"/> value for all components
/// </summary>
public Double2 YY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YY)}");
/// <summary>
/// Gets or sets an <see cref="Double2"/> value with the <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public Double2 YZ
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YZ)}");
}
/// <summary>
/// Gets or sets an <see cref="Double2"/> value with the <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public Double2 ZX
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZX)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZX)}");
}
/// <summary>
/// Gets or sets an <see cref="Double2"/> value with the <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public Double2 ZY
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZY)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZY)}");
}
/// <summary>
/// Gets an <see cref="Double2"/> value with the <see cref="Z"/> value for all components
/// </summary>
public Double2 ZZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZZ)}");
/// <summary>
/// Gets an <see cref="Double2"/> value with the <see cref="R"/> value for all components
/// </summary>
public Double2 RR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RR)}");
/// <summary>
/// Gets or sets an <see cref="Double2"/> value with the <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Double2 RG
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RG)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RG)}");
}
/// <summary>
/// Gets or sets an <see cref="Double2"/> value with the <see cref="R"/> and <see cref="B"/> values
/// </summary>
public Double2 RB
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RB)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RB)}");
}
/// <summary>
/// Gets or sets an <see cref="Double2"/> value with the <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Double2 GR
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GR)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GR)}");
}
/// <summary>
/// Gets an <see cref="Double2"/> value with the <see cref="G"/> value for all components
/// </summary>
public Double2 GG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GG)}");
/// <summary>
/// Gets or sets an <see cref="Double2"/> value with the <see cref="G"/> and <see cref="B"/> values
/// </summary>
public Double2 GB
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GB)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GB)}");
}
/// <summary>
/// Gets or sets an <see cref="Double2"/> value with the <see cref="B"/> and <see cref="R"/> values
/// </summary>
public Double2 BR
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BR)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BR)}");
}
/// <summary>
/// Gets or sets an <see cref="Double2"/> value with the <see cref="B"/> and <see cref="G"/> values
/// </summary>
public Double2 BG
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BG)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BG)}");
}
/// <summary>
/// Gets an <see cref="Double2"/> value with the <see cref="B"/> value for all components
/// </summary>
public Double2 BB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BB)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="X"/> value for all components
/// </summary>
public Double2 XXX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XXX)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Double2 XXY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XXY)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public Double2 XXZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XXZ)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Double2 XYX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XYX)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Y"/> values
/// </summary>
public Double2 XYY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XYY)}");
/// <summary>
/// Gets or sets an <see cref="Double3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public Double2 XYZ
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XYZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XYZ)}");
}
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public Double2 XZX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XZX)}");
/// <summary>
/// Gets or sets an <see cref="Double3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public Double2 XZY
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XZY)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XZY)}");
}
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Z"/> values
/// </summary>
public Double2 XZZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XZZ)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="X"/> values
/// </summary>
public Double2 YXX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YXX)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Double2 YXY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YXY)}");
/// <summary>
/// Gets or sets an <see cref="Double3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public Double2 YXZ
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YXZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YXZ)}");
}
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Double2 YYX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YYX)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="Y"/> value for all components
/// </summary>
public Double2 YYY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YYY)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public Double2 YYZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YYZ)}");
/// <summary>
/// Gets or sets an <see cref="Double3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public Double2 YZX
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YZX)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YZX)}");
}
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public Double2 YZY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YZY)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Z"/> values
/// </summary>
public Double2 YZZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YZZ)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Z"/> values
/// </summary>
public Double2 ZXX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZXX)}");
/// <summary>
/// Gets or sets an <see cref="Double3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Double2 ZXY
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZXY)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZXY)}");
}
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public Double2 ZXZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZXZ)}");
/// <summary>
/// Gets or sets an <see cref="Double3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Double2 ZYX
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZYX)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZYX)}");
}
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Y"/> values
/// </summary>
public Double2 ZYY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZYY)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public Double2 ZYZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZYZ)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public Double2 ZZX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZZX)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public Double2 ZZY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZZY)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="Z"/> value for all components
/// </summary>
public Double2 ZZZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZZZ)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="R"/> value for all components
/// </summary>
public Double2 RRR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RRR)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="R"/>, <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Double2 RRG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RRG)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="R"/>, <see cref="R"/> and <see cref="B"/> values
/// </summary>
public Double2 RRB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RRB)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="R"/>, <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Double2 RGR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RGR)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="R"/>, <see cref="G"/> and <see cref="G"/> values
/// </summary>
public Double2 RGG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RGG)}");
/// <summary>
/// Gets or sets an <see cref="Double3"/> value with the <see cref="R"/>, <see cref="G"/> and <see cref="B"/> values
/// </summary>
public Double2 RGB
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RGB)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RGB)}");
}
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="R"/>, <see cref="B"/> and <see cref="R"/> values
/// </summary>
public Double2 RBR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RBR)}");
/// <summary>
/// Gets or sets an <see cref="Double3"/> value with the <see cref="R"/>, <see cref="B"/> and <see cref="G"/> values
/// </summary>
public Double2 RBG
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RBG)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RBG)}");
}
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="R"/>, <see cref="B"/> and <see cref="B"/> values
/// </summary>
public Double2 RBB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RBB)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="G"/>, <see cref="R"/> and <see cref="R"/> values
/// </summary>
public Double2 GRR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GRR)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="G"/>, <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Double2 GRG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GRG)}");
/// <summary>
/// Gets or sets an <see cref="Double3"/> value with the <see cref="G"/>, <see cref="R"/> and <see cref="B"/> values
/// </summary>
public Double2 GRB
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GRB)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GRB)}");
}
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="G"/>, <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Double2 GGR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GGR)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="G"/> value for all components
/// </summary>
public Double2 GGG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GGG)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="G"/>, <see cref="G"/> and <see cref="B"/> values
/// </summary>
public Double2 GGB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GGB)}");
/// <summary>
/// Gets or sets an <see cref="Double3"/> value with the <see cref="G"/>, <see cref="B"/> and <see cref="R"/> values
/// </summary>
public Double2 GBR
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GBR)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GBR)}");
}
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="G"/>, <see cref="B"/> and <see cref="G"/> values
/// </summary>
public Double2 GBG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GBG)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="G"/>, <see cref="B"/> and <see cref="B"/> values
/// </summary>
public Double2 GBB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GBB)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="B"/>, <see cref="B"/> and <see cref="B"/> values
/// </summary>
public Double2 BRR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BRR)}");
/// <summary>
/// Gets or sets an <see cref="Double3"/> value with the <see cref="B"/>, <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Double2 BRG
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BRG)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BRG)}");
}
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="B"/>, <see cref="R"/> and <see cref="B"/> values
/// </summary>
public Double2 BRB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BRB)}");
/// <summary>
/// Gets or sets an <see cref="Double3"/> value with the <see cref="B"/>, <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Double2 BGR
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BGR)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BGR)}");
}
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="B"/>, <see cref="G"/> and <see cref="G"/> values
/// </summary>
public Double2 BGG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BGG)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="B"/>, <see cref="G"/> and <see cref="B"/> values
/// </summary>
public Double2 BGB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BGB)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="B"/>, <see cref="B"/> and <see cref="R"/> values
/// </summary>
public Double2 BBR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BBR)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="B"/>, <see cref="B"/> and <see cref="G"/> values
/// </summary>
public Double2 BBG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BBG)}");
/// <summary>
/// Gets an <see cref="Double3"/> value with the <see cref="B"/> value for all components
/// </summary>
public Double2 BBB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BBB)}");
/// <summary>
/// Creates a new <see cref="Double3"/> value with the same value for all its components
/// </summary>
/// <param name="x">The value to use for the components of the new <see cref="Double3"/> instance</param>
public static implicit operator Double3(double x) => new Double3(x, x, x);
/// <summary>
/// Sums two <see cref="Double3"/> values
/// </summary>
/// <param name="left">The first <see cref="Double3"/> value to sum</param>
/// <param name="right">The second <see cref="Double3"/> value to sum</param>
public static Double3 operator +(Double3 left, Double3 right) => throw new InvalidExecutionContextException($"{nameof(Double3)}.+");
/// <summary>
/// Divides two <see cref="Double3"/> values
/// </summary>
/// <param name="left">The first <see cref="Double3"/> value to divide</param>
/// <param name="right">The second <see cref="Double3"/> value to divide</param>
public static Double3 operator /(Double3 left, Double3 right) => throw new InvalidExecutionContextException($"{nameof(Double3)}./");
/// <summary>
/// Multiplies two <see cref="Double3"/> values
/// </summary>
/// <param name="left">The first <see cref="Double3"/> value to multiply</param>
/// <param name="right">The second <see cref="Double3"/> value to multiply</param>
public static Double3 operator *(Double3 left, Double3 right) => throw new InvalidExecutionContextException($"{nameof(Double3)}.*");
/// <summary>
/// Subtracts two <see cref="Double3"/> values
/// </summary>
/// <param name="left">The first <see cref="Double3"/> value to subtract</param>
/// <param name="right">The second <see cref="Double3"/> value to subtract</param>
public static Double3 operator -(Double3 left, Double3 right) => throw new InvalidExecutionContextException($"{nameof(Double3)}.-");
}
}
ファイル差分が大きすぎるため表示されません。 差分を読み込み
-173
ファイルの表示
@@ -1,173 +0,0 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using ComputeSharp.Exceptions;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="struct"/> that maps the <see langword="float2"/> HLSL type
/// </summary>
[DebuggerDisplay("({X}, {Y})")]
[StructLayout(LayoutKind.Sequential, Size = sizeof(float) * 2)]
public struct Float2
{
/// <summary>
/// Gets an <see cref="Float2"/> value with all components set to 0
/// </summary>
public static Float2 Zero => 0;
/// <summary>
/// Gets an <see cref="Float2"/> value with all components set to 1
/// </summary>
public static Float2 One => 1;
/// <summary>
/// Gets an <see cref="Float2"/> value with the <see cref="X"/> component set to 1, and the others to 0
/// </summary>
public static Float2 UnitX => new Float2(1, 0);
/// <summary>
/// Gets an <see cref="Float2"/> value with the <see cref="Y"/> component set to 1, and the others to 0
/// </summary>
public static Float2 UnitY => new Float2(0, 1);
/// <summary>
/// Creates a new <see cref="Float2"/> instance with the specified parameters
/// </summary>
/// <param name="x">The value to assign to the first vector component</param>
/// <param name="y">The value to assign to the second vector component</param>
public Float2(float x, float y)
{
X = x;
Y = y;
}
/// <summary>
/// Gets or sets the value of the first vector component
/// </summary>
public float X { get; set; }
/// <summary>
/// Gets or sets the value of the second vector component
/// </summary>
public float Y { get; set; }
/// <summary>
/// Gets or sets the value of the first color component
/// </summary>
public float R
{
get => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(R)}");
set => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(R)}");
}
/// <summary>
/// Gets or sets the value of the second color component
/// </summary>
public float G
{
get => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(G)}");
set => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(G)}");
}
/// <summary>
/// Gets or sets a specific component in the current <see cref="Float2"/> instance
/// </summary>
/// <param name="i">The index of the component to access</param>
public float this[int i]
{
get => throw new InvalidExecutionContextException($"{nameof(Float2)}[int]");
set => throw new InvalidExecutionContextException($"{nameof(Float2)}[int]");
}
/// <summary>
/// Gets an <see cref="Float2"/> value with the <see cref="X"/> value for all components
/// </summary>
public Float2 XX => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(XX)}");
/// <summary>
/// Gets or sets an <see cref="Float2"/> value with the <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Float2 XY
{
get => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(XY)}");
set => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(XY)}");
}
/// <summary>
/// Gets an <see cref="Float2"/> value with the <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Float2 YX
{
get => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(YX)}");
set => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(YX)}");
}
/// <summary>
/// Gets an <see cref="Float2"/> value with the <see cref="Y"/> value for all components
/// </summary>
public Float2 YY => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(YY)}");
/// <summary>
/// Gets an <see cref="Float2"/> value with the <see cref="R"/> value for all components
/// </summary>
public Float2 RR => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(RR)}");
/// <summary>
/// Gets or sets an <see cref="Float2"/> value with the <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Float2 RG
{
get => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(RG)}");
set => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(RG)}");
}
/// <summary>
/// Gets an <see cref="Float2"/> value with the <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Float2 GR
{
get => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(GR)}");
set => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(GR)}");
}
/// <summary>
/// Gets an <see cref="Float2"/> value with the <see cref="G"/> value for all components
/// </summary>
public Float2 GG => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(GG)}");
/// <summary>
/// Creates a new <see cref="Float2"/> value with the same value for all its components
/// </summary>
/// <param name="x">The value to use for the components of the new <see cref="Float2"/> instance</param>
public static implicit operator Float2(float x) => new Float2(x, x);
/// <summary>
/// Sums two <see cref="Float2"/> values
/// </summary>
/// <param name="left">The first <see cref="Float2"/> value to sum</param>
/// <param name="right">The second <see cref="Float2"/> value to sum</param>
public static Float2 operator +(Float2 left, Float2 right) => throw new InvalidExecutionContextException($"{nameof(Float2)}.+");
/// <summary>
/// Divides two <see cref="Float2"/> values
/// </summary>
/// <param name="left">The first <see cref="Float2"/> value to divide</param>
/// <param name="right">The second <see cref="Float2"/> value to divide</param>
public static Float2 operator /(Float2 left, Float2 right) => throw new InvalidExecutionContextException($"{nameof(Float2)}./");
/// <summary>
/// Multiplies two <see cref="Float2"/> values
/// </summary>
/// <param name="left">The first <see cref="Float2"/> value to multiply</param>
/// <param name="right">The second <see cref="Float2"/> value to multiply</param>
public static Float2 operator *(Float2 left, Float2 right) => throw new InvalidExecutionContextException($"{nameof(Float2)}.*");
/// <summary>
/// Subtracts two <see cref="Float2"/> values
/// </summary>
/// <param name="left">The first <see cref="Float2"/> value to subtract</param>
/// <param name="right">The second <see cref="Float2"/> value to subtract</param>
public static Float2 operator -(Float2 left, Float2 right) => throw new InvalidExecutionContextException($"{nameof(Float2)}.-");
}
}
-594
ファイルの表示
@@ -1,594 +0,0 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using ComputeSharp.Exceptions;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="struct"/> that maps the <see langword="float3"/> HLSL type
/// </summary>
[DebuggerDisplay("({X}, {Y}, {Z})")]
[StructLayout(LayoutKind.Sequential, Size = sizeof(float) * 3)]
public struct Float3
{
/// <summary>
/// Gets an <see cref="Float3"/> value with all components set to 0
/// </summary>
public static Float3 Zero => 0;
/// <summary>
/// Gets an <see cref="Float3"/> value with all components set to 1
/// </summary>
public static Float3 One => 1;
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="X"/> component set to 1, and the others to 0
/// </summary>
public static Float3 UnitX => new Float3(1, 0, 0);
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="Y"/> component set to 1, and the others to 0
/// </summary>
public static Float3 UnitY => new Float3(0, 1, 0);
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="Z"/> component set to 1, and the others to 0
/// </summary>
public static Float3 UnitZ => new Float3(0, 0, 1);
/// <summary>
/// Creates a new <see cref="Float3"/> instance with the specified parameters
/// </summary>
/// <param name="x">The value to assign to the first vector component</param>
/// <param name="y">The value to assign to the second vector component</param>
/// <param name="z">The value to assign to the third vector component</param>
public Float3(float x, float y, float z)
{
X = x;
Y = y;
Z = z;
}
/// <summary>
/// Gets or sets the value of the first vector component
/// </summary>
public float X { get; set; }
/// <summary>
/// Gets or sets the value of the second vector component
/// </summary>
public float Y { get; set; }
/// <summary>
/// Gets or sets the value of the third vector component
/// </summary>
public float Z { get; set; }
/// <summary>
/// Gets or sets the value of the first color component
/// </summary>
public float R
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(R)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(R)}");
}
/// <summary>
/// Gets or sets the value of the second color component
/// </summary>
public float G
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(G)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(G)}");
}
/// <summary>
/// Gets or sets the value of the third color component
/// </summary>
public float B
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(B)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(B)}");
}
/// <summary>
/// Gets or sets a specific component in the current <see cref="Float3"/> instance
/// </summary>
/// <param name="i">The index of the component to access</param>
public float this[int i]
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}[int]");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}[int]");
}
/// <summary>
/// Gets an <see cref="Float2"/> value with the <see cref="X"/> value for all components
/// </summary>
public Float2 XX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XX)}");
/// <summary>
/// Gets or sets an <see cref="Float2"/> value with the <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Float2 XY
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XY)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XY)}");
}
/// <summary>
/// Gets or sets an <see cref="Float2"/> value with the <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public Float2 XZ
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XZ)}");
}
/// <summary>
/// Gets or sets an <see cref="Float2"/> value with the <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Float2 YX
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YX)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YX)}");
}
/// <summary>
/// Gets an <see cref="Float2"/> value with the <see cref="Y"/> value for all components
/// </summary>
public Float2 YY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YY)}");
/// <summary>
/// Gets or sets an <see cref="Float2"/> value with the <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public Float2 YZ
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YZ)}");
}
/// <summary>
/// Gets or sets an <see cref="Float2"/> value with the <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public Float2 ZX
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZX)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZX)}");
}
/// <summary>
/// Gets or sets an <see cref="Float2"/> value with the <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public Float2 ZY
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZY)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZY)}");
}
/// <summary>
/// Gets an <see cref="Float2"/> value with the <see cref="Z"/> value for all components
/// </summary>
public Float2 ZZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZZ)}");
/// <summary>
/// Gets an <see cref="Float2"/> value with the <see cref="R"/> value for all components
/// </summary>
public Float2 RR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RR)}");
/// <summary>
/// Gets or sets an <see cref="Float2"/> value with the <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Float2 RG
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RG)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RG)}");
}
/// <summary>
/// Gets or sets an <see cref="Float2"/> value with the <see cref="R"/> and <see cref="B"/> values
/// </summary>
public Float2 RB
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RB)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RB)}");
}
/// <summary>
/// Gets or sets an <see cref="Float2"/> value with the <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Float2 GR
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GR)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GR)}");
}
/// <summary>
/// Gets an <see cref="Float2"/> value with the <see cref="G"/> value for all components
/// </summary>
public Float2 GG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GG)}");
/// <summary>
/// Gets or sets an <see cref="Float2"/> value with the <see cref="G"/> and <see cref="B"/> values
/// </summary>
public Float2 GB
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GB)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GB)}");
}
/// <summary>
/// Gets or sets an <see cref="Float2"/> value with the <see cref="B"/> and <see cref="R"/> values
/// </summary>
public Float2 BR
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BR)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BR)}");
}
/// <summary>
/// Gets or sets an <see cref="Float2"/> value with the <see cref="B"/> and <see cref="G"/> values
/// </summary>
public Float2 BG
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BG)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BG)}");
}
/// <summary>
/// Gets an <see cref="Float2"/> value with the <see cref="B"/> value for all components
/// </summary>
public Float2 BB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BB)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="X"/> value for all components
/// </summary>
public Float2 XXX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XXX)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Float2 XXY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XXY)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public Float2 XXZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XXZ)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Float2 XYX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XYX)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Y"/> values
/// </summary>
public Float2 XYY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XYY)}");
/// <summary>
/// Gets or sets an <see cref="Float3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public Float2 XYZ
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XYZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XYZ)}");
}
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public Float2 XZX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XZX)}");
/// <summary>
/// Gets or sets an <see cref="Float3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public Float2 XZY
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XZY)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XZY)}");
}
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Z"/> values
/// </summary>
public Float2 XZZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XZZ)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="X"/> values
/// </summary>
public Float2 YXX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YXX)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Float2 YXY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YXY)}");
/// <summary>
/// Gets or sets an <see cref="Float3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public Float2 YXZ
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YXZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YXZ)}");
}
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Float2 YYX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YYX)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="Y"/> value for all components
/// </summary>
public Float2 YYY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YYY)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public Float2 YYZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YYZ)}");
/// <summary>
/// Gets or sets an <see cref="Float3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public Float2 YZX
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YZX)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YZX)}");
}
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public Float2 YZY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YZY)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Z"/> values
/// </summary>
public Float2 YZZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YZZ)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Z"/> values
/// </summary>
public Float2 ZXX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZXX)}");
/// <summary>
/// Gets or sets an <see cref="Float3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Float2 ZXY
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZXY)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZXY)}");
}
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public Float2 ZXZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZXZ)}");
/// <summary>
/// Gets or sets an <see cref="Float3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Float2 ZYX
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZYX)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZYX)}");
}
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Y"/> values
/// </summary>
public Float2 ZYY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZYY)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public Float2 ZYZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZYZ)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public Float2 ZZX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZZX)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public Float2 ZZY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZZY)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="Z"/> value for all components
/// </summary>
public Float2 ZZZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZZZ)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="R"/> value for all components
/// </summary>
public Float2 RRR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RRR)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="R"/>, <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Float2 RRG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RRG)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="R"/>, <see cref="R"/> and <see cref="B"/> values
/// </summary>
public Float2 RRB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RRB)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="R"/>, <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Float2 RGR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RGR)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="R"/>, <see cref="G"/> and <see cref="G"/> values
/// </summary>
public Float2 RGG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RGG)}");
/// <summary>
/// Gets or sets an <see cref="Float3"/> value with the <see cref="R"/>, <see cref="G"/> and <see cref="B"/> values
/// </summary>
public Float2 RGB
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RGB)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RGB)}");
}
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="R"/>, <see cref="B"/> and <see cref="R"/> values
/// </summary>
public Float2 RBR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RBR)}");
/// <summary>
/// Gets or sets an <see cref="Float3"/> value with the <see cref="R"/>, <see cref="B"/> and <see cref="G"/> values
/// </summary>
public Float2 RBG
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RBG)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RBG)}");
}
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="R"/>, <see cref="B"/> and <see cref="B"/> values
/// </summary>
public Float2 RBB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RBB)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="G"/>, <see cref="R"/> and <see cref="R"/> values
/// </summary>
public Float2 GRR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GRR)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="G"/>, <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Float2 GRG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GRG)}");
/// <summary>
/// Gets or sets an <see cref="Float3"/> value with the <see cref="G"/>, <see cref="R"/> and <see cref="B"/> values
/// </summary>
public Float2 GRB
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GRB)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GRB)}");
}
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="G"/>, <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Float2 GGR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GGR)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="G"/> value for all components
/// </summary>
public Float2 GGG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GGG)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="G"/>, <see cref="G"/> and <see cref="B"/> values
/// </summary>
public Float2 GGB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GGB)}");
/// <summary>
/// Gets or sets an <see cref="Float3"/> value with the <see cref="G"/>, <see cref="B"/> and <see cref="R"/> values
/// </summary>
public Float2 GBR
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GBR)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GBR)}");
}
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="G"/>, <see cref="B"/> and <see cref="G"/> values
/// </summary>
public Float2 GBG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GBG)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="G"/>, <see cref="B"/> and <see cref="B"/> values
/// </summary>
public Float2 GBB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GBB)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="B"/>, <see cref="B"/> and <see cref="B"/> values
/// </summary>
public Float2 BRR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BRR)}");
/// <summary>
/// Gets or sets an <see cref="Float3"/> value with the <see cref="B"/>, <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Float2 BRG
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BRG)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BRG)}");
}
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="B"/>, <see cref="R"/> and <see cref="B"/> values
/// </summary>
public Float2 BRB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BRB)}");
/// <summary>
/// Gets or sets an <see cref="Float3"/> value with the <see cref="B"/>, <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Float2 BGR
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BGR)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BGR)}");
}
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="B"/>, <see cref="G"/> and <see cref="G"/> values
/// </summary>
public Float2 BGG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BGG)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="B"/>, <see cref="G"/> and <see cref="B"/> values
/// </summary>
public Float2 BGB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BGB)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="B"/>, <see cref="B"/> and <see cref="R"/> values
/// </summary>
public Float2 BBR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BBR)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="B"/>, <see cref="B"/> and <see cref="G"/> values
/// </summary>
public Float2 BBG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BBG)}");
/// <summary>
/// Gets an <see cref="Float3"/> value with the <see cref="B"/> value for all components
/// </summary>
public Float2 BBB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BBB)}");
/// <summary>
/// Creates a new <see cref="Float3"/> value with the same value for all its components
/// </summary>
/// <param name="x">The value to use for the components of the new <see cref="Float3"/> instance</param>
public static implicit operator Float3(float x) => new Float3(x, x, x);
/// <summary>
/// Sums two <see cref="Float3"/> values
/// </summary>
/// <param name="left">The first <see cref="Float3"/> value to sum</param>
/// <param name="right">The second <see cref="Float3"/> value to sum</param>
public static Float3 operator +(Float3 left, Float3 right) => throw new InvalidExecutionContextException($"{nameof(Float3)}.+");
/// <summary>
/// Divides two <see cref="Float3"/> values
/// </summary>
/// <param name="left">The first <see cref="Float3"/> value to divide</param>
/// <param name="right">The second <see cref="Float3"/> value to divide</param>
public static Float3 operator /(Float3 left, Float3 right) => throw new InvalidExecutionContextException($"{nameof(Float3)}./");
/// <summary>
/// Multiplies two <see cref="Float3"/> values
/// </summary>
/// <param name="left">The first <see cref="Float3"/> value to multiply</param>
/// <param name="right">The second <see cref="Float3"/> value to multiply</param>
public static Float3 operator *(Float3 left, Float3 right) => throw new InvalidExecutionContextException($"{nameof(Float3)}.*");
/// <summary>
/// Subtracts two <see cref="Float3"/> values
/// </summary>
/// <param name="left">The first <see cref="Float3"/> value to subtract</param>
/// <param name="right">The second <see cref="Float3"/> value to subtract</param>
public static Float3 operator -(Float3 left, Float3 right) => throw new InvalidExecutionContextException($"{nameof(Float3)}.-");
}
}
ファイル差分が大きすぎるため表示されません。 差分を読み込み
-173
ファイルの表示
@@ -1,173 +0,0 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using ComputeSharp.Exceptions;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="struct"/> that maps the <see langword="int2"/> HLSL type
/// </summary>
[DebuggerDisplay("({X}, {Y})")]
[StructLayout(LayoutKind.Sequential, Size = sizeof(int) * 2)]
public struct Int2
{
/// <summary>
/// Gets an <see cref="Int2"/> value with all components set to 0
/// </summary>
public static Int2 Zero => 0;
/// <summary>
/// Gets an <see cref="Int2"/> value with all components set to 1
/// </summary>
public static Int2 One => 1;
/// <summary>
/// Gets an <see cref="Int2"/> value with the <see cref="X"/> component set to 1, and the others to 0
/// </summary>
public static Int2 UnitX => new Int2(1, 0);
/// <summary>
/// Gets an <see cref="Int2"/> value with the <see cref="Y"/> component set to 1, and the others to 0
/// </summary>
public static Int2 UnitY => new Int2(0, 1);
/// <summary>
/// Creates a new <see cref="Int2"/> instance with the specified parameters
/// </summary>
/// <param name="x">The value to assign to the first vector component</param>
/// <param name="y">The value to assign to the second vector component</param>
public Int2(int x, int y)
{
X = x;
Y = y;
}
/// <summary>
/// Gets or sets the value of the first vector component
/// </summary>
public int X { get; set; }
/// <summary>
/// Gets or sets the value of the second vector component
/// </summary>
public int Y { get; set; }
/// <summary>
/// Gets or sets the value of the first color component
/// </summary>
public int R
{
get => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(R)}");
set => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(R)}");
}
/// <summary>
/// Gets or sets the value of the second color component
/// </summary>
public int G
{
get => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(G)}");
set => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(G)}");
}
/// <summary>
/// Gets or sets a specific component in the current <see cref="Int2"/> instance
/// </summary>
/// <param name="i">The index of the component to access</param>
public int this[int i]
{
get => throw new InvalidExecutionContextException($"{nameof(Int2)}[int]");
set => throw new InvalidExecutionContextException($"{nameof(Int2)}[int]");
}
/// <summary>
/// Gets an <see cref="Int2"/> value with the <see cref="X"/> value for all components
/// </summary>
public Int2 XX => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(XX)}");
/// <summary>
/// Gets or sets an <see cref="Int2"/> value with the <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Int2 XY
{
get => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(XY)}");
set => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(XY)}");
}
/// <summary>
/// Gets an <see cref="Int2"/> value with the <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Int2 YX
{
get => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(YX)}");
set => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(YX)}");
}
/// <summary>
/// Gets an <see cref="Int2"/> value with the <see cref="Y"/> value for all components
/// </summary>
public Int2 YY => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(YY)}");
/// <summary>
/// Gets an <see cref="Int2"/> value with the <see cref="R"/> value for all components
/// </summary>
public Int2 RR => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(RR)}");
/// <summary>
/// Gets or sets an <see cref="Int2"/> value with the <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Int2 RG
{
get => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(RG)}");
set => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(RG)}");
}
/// <summary>
/// Gets an <see cref="Int2"/> value with the <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Int2 GR
{
get => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(GR)}");
set => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(GR)}");
}
/// <summary>
/// Gets an <see cref="Int2"/> value with the <see cref="G"/> value for all components
/// </summary>
public Int2 GG => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(GG)}");
/// <summary>
/// Creates a new <see cref="Int2"/> value with the same value for all its components
/// </summary>
/// <param name="x">The value to use for the components of the new <see cref="Int2"/> instance</param>
public static implicit operator Int2(int x) => new Int2(x, x);
/// <summary>
/// Sums two <see cref="Int2"/> values
/// </summary>
/// <param name="left">The first <see cref="Int2"/> value to sum</param>
/// <param name="right">The second <see cref="Int2"/> value to sum</param>
public static Int2 operator +(Int2 left, Int2 right) => throw new InvalidExecutionContextException($"{nameof(Int2)}.+");
/// <summary>
/// Divides two <see cref="Int2"/> values
/// </summary>
/// <param name="left">The first <see cref="Int2"/> value to divide</param>
/// <param name="right">The second <see cref="Int2"/> value to divide</param>
public static Int2 operator /(Int2 left, Int2 right) => throw new InvalidExecutionContextException($"{nameof(Int2)}./");
/// <summary>
/// Multiplies two <see cref="Int2"/> values
/// </summary>
/// <param name="left">The first <see cref="Int2"/> value to multiply</param>
/// <param name="right">The second <see cref="Int2"/> value to multiply</param>
public static Int2 operator *(Int2 left, Int2 right) => throw new InvalidExecutionContextException($"{nameof(Int2)}.*");
/// <summary>
/// Subtracts two <see cref="Int2"/> values
/// </summary>
/// <param name="left">The first <see cref="Int2"/> value to subtract</param>
/// <param name="right">The second <see cref="Int2"/> value to subtract</param>
public static Int2 operator -(Int2 left, Int2 right) => throw new InvalidExecutionContextException($"{nameof(Int2)}.-");
}
}
-594
ファイルの表示
@@ -1,594 +0,0 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using ComputeSharp.Exceptions;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="struct"/> that maps the <see langword="int3"/> HLSL type
/// </summary>
[DebuggerDisplay("({X}, {Y}, {Z})")]
[StructLayout(LayoutKind.Sequential, Size = sizeof(int) * 3)]
public struct Int3
{
/// <summary>
/// Gets an <see cref="Int3"/> value with all components set to 0
/// </summary>
public static Int3 Zero => 0;
/// <summary>
/// Gets an <see cref="Int3"/> value with all components set to 1
/// </summary>
public static Int3 One => 1;
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="X"/> component set to 1, and the others to 0
/// </summary>
public static Int3 UnitX => new Int3(1, 0, 0);
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/> component set to 1, and the others to 0
/// </summary>
public static Int3 UnitY => new Int3(0, 1, 0);
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/> component set to 1, and the others to 0
/// </summary>
public static Int3 UnitZ => new Int3(0, 0, 1);
/// <summary>
/// Creates a new <see cref="Int3"/> instance with the specified parameters
/// </summary>
/// <param name="x">The value to assign to the first vector component</param>
/// <param name="y">The value to assign to the second vector component</param>
/// <param name="z">The value to assign to the third vector component</param>
public Int3(int x, int y, int z)
{
X = x;
Y = y;
Z = z;
}
/// <summary>
/// Gets or sets the value of the first vector component
/// </summary>
public int X { get; set; }
/// <summary>
/// Gets or sets the value of the second vector component
/// </summary>
public int Y { get; set; }
/// <summary>
/// Gets or sets the value of the third vector component
/// </summary>
public int Z { get; set; }
/// <summary>
/// Gets or sets the value of the first color component
/// </summary>
public int R
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(R)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(R)}");
}
/// <summary>
/// Gets or sets the value of the second color component
/// </summary>
public int G
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(G)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(G)}");
}
/// <summary>
/// Gets or sets the value of the third color component
/// </summary>
public int B
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(B)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(B)}");
}
/// <summary>
/// Gets or sets a specific component in the current <see cref="Int3"/> instance
/// </summary>
/// <param name="i">The index of the component to access</param>
public int this[int i]
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}[int]");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}[int]");
}
/// <summary>
/// Gets an <see cref="Int2"/> value with the <see cref="X"/> value for all components
/// </summary>
public Int2 XX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XX)}");
/// <summary>
/// Gets or sets an <see cref="Int2"/> value with the <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Int2 XY
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XY)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XY)}");
}
/// <summary>
/// Gets or sets an <see cref="Int2"/> value with the <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public Int2 XZ
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XZ)}");
}
/// <summary>
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Int2 YX
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YX)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YX)}");
}
/// <summary>
/// Gets an <see cref="Int2"/> value with the <see cref="Y"/> value for all components
/// </summary>
public Int2 YY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YY)}");
/// <summary>
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public Int2 YZ
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YZ)}");
}
/// <summary>
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public Int2 ZX
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZX)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZX)}");
}
/// <summary>
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public Int2 ZY
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZY)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZY)}");
}
/// <summary>
/// Gets an <see cref="Int2"/> value with the <see cref="Z"/> value for all components
/// </summary>
public Int2 ZZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZZ)}");
/// <summary>
/// Gets an <see cref="Int2"/> value with the <see cref="R"/> value for all components
/// </summary>
public Int2 RR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RR)}");
/// <summary>
/// Gets or sets an <see cref="Int2"/> value with the <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Int2 RG
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RG)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RG)}");
}
/// <summary>
/// Gets or sets an <see cref="Int2"/> value with the <see cref="R"/> and <see cref="B"/> values
/// </summary>
public Int2 RB
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RB)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RB)}");
}
/// <summary>
/// Gets or sets an <see cref="Int2"/> value with the <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Int2 GR
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GR)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GR)}");
}
/// <summary>
/// Gets an <see cref="Int2"/> value with the <see cref="G"/> value for all components
/// </summary>
public Int2 GG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GG)}");
/// <summary>
/// Gets or sets an <see cref="Int2"/> value with the <see cref="G"/> and <see cref="B"/> values
/// </summary>
public Int2 GB
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GB)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GB)}");
}
/// <summary>
/// Gets or sets an <see cref="Int2"/> value with the <see cref="B"/> and <see cref="R"/> values
/// </summary>
public Int2 BR
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BR)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BR)}");
}
/// <summary>
/// Gets or sets an <see cref="Int2"/> value with the <see cref="B"/> and <see cref="G"/> values
/// </summary>
public Int2 BG
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BG)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BG)}");
}
/// <summary>
/// Gets an <see cref="Int2"/> value with the <see cref="B"/> value for all components
/// </summary>
public Int2 BB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BB)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="X"/> value for all components
/// </summary>
public Int2 XXX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XXX)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Int2 XXY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XXY)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public Int2 XXZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XXZ)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Int2 XYX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XYX)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Y"/> values
/// </summary>
public Int2 XYY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XYY)}");
/// <summary>
/// Gets or sets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public Int2 XYZ
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XYZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XYZ)}");
}
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public Int2 XZX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XZX)}");
/// <summary>
/// Gets or sets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public Int2 XZY
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XZY)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XZY)}");
}
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Z"/> values
/// </summary>
public Int2 XZZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XZZ)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="X"/> values
/// </summary>
public Int2 YXX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YXX)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Int2 YXY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YXY)}");
/// <summary>
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public Int2 YXZ
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YXZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YXZ)}");
}
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Int2 YYX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YYX)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/> value for all components
/// </summary>
public Int2 YYY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YYY)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public Int2 YYZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YYZ)}");
/// <summary>
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public Int2 YZX
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YZX)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YZX)}");
}
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public Int2 YZY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YZY)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Z"/> values
/// </summary>
public Int2 YZZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YZZ)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Z"/> values
/// </summary>
public Int2 ZXX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZXX)}");
/// <summary>
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public Int2 ZXY
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZXY)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZXY)}");
}
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public Int2 ZXZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZXZ)}");
/// <summary>
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public Int2 ZYX
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZYX)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZYX)}");
}
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Y"/> values
/// </summary>
public Int2 ZYY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZYY)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public Int2 ZYZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZYZ)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public Int2 ZZX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZZX)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public Int2 ZZY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZZY)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/> value for all components
/// </summary>
public Int2 ZZZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZZZ)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="R"/> value for all components
/// </summary>
public Int2 RRR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RRR)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="R"/>, <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Int2 RRG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RRG)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="R"/>, <see cref="R"/> and <see cref="B"/> values
/// </summary>
public Int2 RRB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RRB)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="R"/>, <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Int2 RGR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RGR)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="R"/>, <see cref="G"/> and <see cref="G"/> values
/// </summary>
public Int2 RGG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RGG)}");
/// <summary>
/// Gets or sets an <see cref="Int3"/> value with the <see cref="R"/>, <see cref="G"/> and <see cref="B"/> values
/// </summary>
public Int2 RGB
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RGB)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RGB)}");
}
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="R"/>, <see cref="B"/> and <see cref="R"/> values
/// </summary>
public Int2 RBR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RBR)}");
/// <summary>
/// Gets or sets an <see cref="Int3"/> value with the <see cref="R"/>, <see cref="B"/> and <see cref="G"/> values
/// </summary>
public Int2 RBG
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RBG)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RBG)}");
}
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="R"/>, <see cref="B"/> and <see cref="B"/> values
/// </summary>
public Int2 RBB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RBB)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="G"/>, <see cref="R"/> and <see cref="R"/> values
/// </summary>
public Int2 GRR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GRR)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="G"/>, <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Int2 GRG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GRG)}");
/// <summary>
/// Gets or sets an <see cref="Int3"/> value with the <see cref="G"/>, <see cref="R"/> and <see cref="B"/> values
/// </summary>
public Int2 GRB
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GRB)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GRB)}");
}
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="G"/>, <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Int2 GGR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GGR)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="G"/> value for all components
/// </summary>
public Int2 GGG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GGG)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="G"/>, <see cref="G"/> and <see cref="B"/> values
/// </summary>
public Int2 GGB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GGB)}");
/// <summary>
/// Gets or sets an <see cref="Int3"/> value with the <see cref="G"/>, <see cref="B"/> and <see cref="R"/> values
/// </summary>
public Int2 GBR
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GBR)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GBR)}");
}
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="G"/>, <see cref="B"/> and <see cref="G"/> values
/// </summary>
public Int2 GBG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GBG)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="G"/>, <see cref="B"/> and <see cref="B"/> values
/// </summary>
public Int2 GBB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GBB)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="B"/>, <see cref="B"/> and <see cref="B"/> values
/// </summary>
public Int2 BRR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BRR)}");
/// <summary>
/// Gets or sets an <see cref="Int3"/> value with the <see cref="B"/>, <see cref="R"/> and <see cref="G"/> values
/// </summary>
public Int2 BRG
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BRG)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BRG)}");
}
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="B"/>, <see cref="R"/> and <see cref="B"/> values
/// </summary>
public Int2 BRB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BRB)}");
/// <summary>
/// Gets or sets an <see cref="Int3"/> value with the <see cref="B"/>, <see cref="G"/> and <see cref="R"/> values
/// </summary>
public Int2 BGR
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BGR)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BGR)}");
}
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="B"/>, <see cref="G"/> and <see cref="G"/> values
/// </summary>
public Int2 BGG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BGG)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="B"/>, <see cref="G"/> and <see cref="B"/> values
/// </summary>
public Int2 BGB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BGB)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="B"/>, <see cref="B"/> and <see cref="R"/> values
/// </summary>
public Int2 BBR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BBR)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="B"/>, <see cref="B"/> and <see cref="G"/> values
/// </summary>
public Int2 BBG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BBG)}");
/// <summary>
/// Gets an <see cref="Int3"/> value with the <see cref="B"/> value for all components
/// </summary>
public Int2 BBB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BBB)}");
/// <summary>
/// Creates a new <see cref="Int3"/> value with the same value for all its components
/// </summary>
/// <param name="x">The value to use for the components of the new <see cref="Int3"/> instance</param>
public static implicit operator Int3(int x) => new Int3(x, x, x);
/// <summary>
/// Sums two <see cref="Int3"/> values
/// </summary>
/// <param name="left">The first <see cref="Int3"/> value to sum</param>
/// <param name="right">The second <see cref="Int3"/> value to sum</param>
public static Int3 operator +(Int3 left, Int3 right) => throw new InvalidExecutionContextException($"{nameof(Int3)}.+");
/// <summary>
/// Divides two <see cref="Int3"/> values
/// </summary>
/// <param name="left">The first <see cref="Int3"/> value to divide</param>
/// <param name="right">The second <see cref="Int3"/> value to divide</param>
public static Int3 operator /(Int3 left, Int3 right) => throw new InvalidExecutionContextException($"{nameof(Int3)}./");
/// <summary>
/// Multiplies two <see cref="Int3"/> values
/// </summary>
/// <param name="left">The first <see cref="Int3"/> value to multiply</param>
/// <param name="right">The second <see cref="Int3"/> value to multiply</param>
public static Int3 operator *(Int3 left, Int3 right) => throw new InvalidExecutionContextException($"{nameof(Int3)}.*");
/// <summary>
/// Subtracts two <see cref="Int3"/> values
/// </summary>
/// <param name="left">The first <see cref="Int3"/> value to subtract</param>
/// <param name="right">The second <see cref="Int3"/> value to subtract</param>
public static Int3 operator -(Int3 left, Int3 right) => throw new InvalidExecutionContextException($"{nameof(Int3)}.-");
}
}
ファイル差分が大きすぎるため表示されません。 差分を読み込み
-25
ファイルの表示
@@ -1,25 +0,0 @@
using ComputeSharp.Exceptions;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="struct"/> that indicates the ids of a given GPU thread running a compute shader
/// </summary>
public readonly struct ThreadIds
{
/// <summary>
/// Gets the X id of the current thread
/// </summary>
public int X => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(X)}");
/// <summary>
/// Gets the Y id of the current thread
/// </summary>
public int Y => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(Y)}");
/// <summary>
/// Gets the Z id of the current thread
/// </summary>
public int Z => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(Z)}");
}
}
-173
ファイルの表示
@@ -1,173 +0,0 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using ComputeSharp.Exceptions;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="struct"/> that maps the <see langword="uint2"/> HLSL type
/// </summary>
[DebuggerDisplay("({X}, {Y})")]
[StructLayout(LayoutKind.Sequential, Size = sizeof(uint) * 2)]
public struct UInt2
{
/// <summary>
/// Gets an <see cref="UInt2"/> value with all components set to 0
/// </summary>
public static UInt2 Zero => 0;
/// <summary>
/// Gets an <see cref="UInt2"/> value with all components set to 1
/// </summary>
public static UInt2 One => 1;
/// <summary>
/// Gets an <see cref="UInt2"/> value with the <see cref="X"/> component set to 1, and the others to 0
/// </summary>
public static UInt2 UnitX => new UInt2(1, 0);
/// <summary>
/// Gets an <see cref="UInt2"/> value with the <see cref="Y"/> component set to 1, and the others to 0
/// </summary>
public static UInt2 UnitY => new UInt2(0, 1);
/// <summary>
/// Creates a new <see cref="UInt2"/> instance with the specified parameters
/// </summary>
/// <param name="x">The value to assign to the first vector component</param>
/// <param name="y">The value to assign to the second vector component</param>
public UInt2(uint x, uint y)
{
X = x;
Y = y;
}
/// <summary>
/// Gets or sets the value of the first vector component
/// </summary>
public uint X { get; set; }
/// <summary>
/// Gets or sets the value of the second vector component
/// </summary>
public uint Y { get; set; }
/// <summary>
/// Gets or sets the value of the first color component
/// </summary>
public uint R
{
get => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(R)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(R)}");
}
/// <summary>
/// Gets or sets the value of the second color component
/// </summary>
public uint G
{
get => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(G)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(G)}");
}
/// <summary>
/// Gets or sets a specific component in the current <see cref="UInt2"/> instance
/// </summary>
/// <param name="i">The index of the component to access</param>
public float this[int i]
{
get => throw new InvalidExecutionContextException($"{nameof(UInt2)}[int]");
set => throw new InvalidExecutionContextException($"{nameof(UInt2)}[int]");
}
/// <summary>
/// Gets an <see cref="UInt2"/> value with the <see cref="X"/> value for all components
/// </summary>
public UInt2 XX => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(XX)}");
/// <summary>
/// Gets or sets an <see cref="UInt2"/> value with the <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public UInt2 XY
{
get => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(XY)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(XY)}");
}
/// <summary>
/// Gets an <see cref="UInt2"/> value with the <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public UInt2 YX
{
get => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(YX)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(YX)}");
}
/// <summary>
/// Gets an <see cref="UInt2"/> value with the <see cref="Y"/> value for all components
/// </summary>
public UInt2 YY => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(YY)}");
/// <summary>
/// Gets an <see cref="UInt2"/> value with the <see cref="R"/> value for all components
/// </summary>
public UInt2 RR => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(RR)}");
/// <summary>
/// Gets or sets an <see cref="UInt2"/> value with the <see cref="R"/> and <see cref="G"/> values
/// </summary>
public UInt2 RG
{
get => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(RG)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(RG)}");
}
/// <summary>
/// Gets an <see cref="UInt2"/> value with the <see cref="G"/> and <see cref="R"/> values
/// </summary>
public UInt2 GR
{
get => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(GR)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(GR)}");
}
/// <summary>
/// Gets an <see cref="UInt2"/> value with the <see cref="G"/> value for all components
/// </summary>
public UInt2 GG => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(GG)}");
/// <summary>
/// Creates a new <see cref="UInt2"/> value with the same value for all its components
/// </summary>
/// <param name="x">The value to use for the components of the new <see cref="UInt2"/> instance</param>
public static implicit operator UInt2(uint x) => new UInt2(x, x);
/// <summary>
/// Sums two <see cref="UInt2"/> values
/// </summary>
/// <param name="left">The first <see cref="UInt2"/> value to sum</param>
/// <param name="right">The second <see cref="UInt2"/> value to sum</param>
public static UInt2 operator +(UInt2 left, UInt2 right) => throw new InvalidExecutionContextException($"{nameof(UInt2)}.+");
/// <summary>
/// Divides two <see cref="UInt2"/> values
/// </summary>
/// <param name="left">The first <see cref="UInt2"/> value to divide</param>
/// <param name="right">The second <see cref="UInt2"/> value to divide</param>
public static UInt2 operator /(UInt2 left, UInt2 right) => throw new InvalidExecutionContextException($"{nameof(UInt2)}./");
/// <summary>
/// Multiplies two <see cref="UInt2"/> values
/// </summary>
/// <param name="left">The first <see cref="UInt2"/> value to multiply</param>
/// <param name="right">The second <see cref="UInt2"/> value to multiply</param>
public static UInt2 operator *(UInt2 left, UInt2 right) => throw new InvalidExecutionContextException($"{nameof(UInt2)}.*");
/// <summary>
/// Subtracts two <see cref="UInt2"/> values
/// </summary>
/// <param name="left">The first <see cref="UInt2"/> value to subtract</param>
/// <param name="right">The second <see cref="UInt2"/> value to subtract</param>
public static UInt2 operator -(UInt2 left, UInt2 right) => throw new InvalidExecutionContextException($"{nameof(UInt2)}.-");
}
}
-594
ファイルの表示
@@ -1,594 +0,0 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using ComputeSharp.Exceptions;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="struct"/> that maps the <see langword="uint3"/> HLSL type
/// </summary>
[DebuggerDisplay("({X}, {Y}, {Z})")]
[StructLayout(LayoutKind.Sequential, Size = sizeof(uint) * 3)]
public struct UInt3
{
/// <summary>
/// Gets an <see cref="UInt3"/> value with all components set to 0
/// </summary>
public static UInt3 Zero => 0;
/// <summary>
/// Gets an <see cref="UInt3"/> value with all components set to 1
/// </summary>
public static UInt3 One => 1;
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="X"/> component set to 1, and the others to 0
/// </summary>
public static UInt3 UnitX => new UInt3(1, 0, 0);
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="Y"/> component set to 1, and the others to 0
/// </summary>
public static UInt3 UnitY => new UInt3(0, 1, 0);
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="Z"/> component set to 1, and the others to 0
/// </summary>
public static UInt3 UnitZ => new UInt3(0, 0, 1);
/// <summary>
/// Creates a new <see cref="UInt3"/> instance with the specified parameters
/// </summary>
/// <param name="x">The value to assign to the first vector component</param>
/// <param name="y">The value to assign to the second vector component</param>
/// <param name="z">The value to assign to the third vector component</param>
public UInt3(uint x, uint y, uint z)
{
X = x;
Y = y;
Z = z;
}
/// <summary>
/// Gets or sets the value of the first vector component
/// </summary>
public uint X { get; set; }
/// <summary>
/// Gets or sets the value of the second vector component
/// </summary>
public uint Y { get; set; }
/// <summary>
/// Gets or sets the value of the third vector component
/// </summary>
public uint Z { get; set; }
/// <summary>
/// Gets or sets the value of the first color component
/// </summary>
public uint R
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(R)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(R)}");
}
/// <summary>
/// Gets or sets the value of the second color component
/// </summary>
public uint G
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(G)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(G)}");
}
/// <summary>
/// Gets or sets the value of the third color component
/// </summary>
public uint B
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(B)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(B)}");
}
/// <summary>
/// Gets or sets a specific component in the current <see cref="UInt3"/> instance
/// </summary>
/// <param name="i">The index of the component to access</param>
public uint this[int i]
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}[int]");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}[int]");
}
/// <summary>
/// Gets an <see cref="UInt2"/> value with the <see cref="X"/> value for all components
/// </summary>
public UInt2 XX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XX)}");
/// <summary>
/// Gets or sets an <see cref="UInt2"/> value with the <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public UInt2 XY
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XY)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XY)}");
}
/// <summary>
/// Gets or sets an <see cref="UInt2"/> value with the <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public UInt2 XZ
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XZ)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XZ)}");
}
/// <summary>
/// Gets or sets an <see cref="UInt2"/> value with the <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public UInt2 YX
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YX)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YX)}");
}
/// <summary>
/// Gets an <see cref="UInt2"/> value with the <see cref="Y"/> value for all components
/// </summary>
public UInt2 YY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YY)}");
/// <summary>
/// Gets or sets an <see cref="UInt2"/> value with the <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public UInt2 YZ
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YZ)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YZ)}");
}
/// <summary>
/// Gets or sets an <see cref="UInt2"/> value with the <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public UInt2 ZX
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZX)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZX)}");
}
/// <summary>
/// Gets or sets an <see cref="UInt2"/> value with the <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public UInt2 ZY
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZY)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZY)}");
}
/// <summary>
/// Gets an <see cref="UInt2"/> value with the <see cref="Z"/> value for all components
/// </summary>
public UInt2 ZZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZZ)}");
/// <summary>
/// Gets an <see cref="UInt2"/> value with the <see cref="R"/> value for all components
/// </summary>
public UInt2 RR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RR)}");
/// <summary>
/// Gets or sets an <see cref="UInt2"/> value with the <see cref="R"/> and <see cref="G"/> values
/// </summary>
public UInt2 RG
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RG)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RG)}");
}
/// <summary>
/// Gets or sets an <see cref="UInt2"/> value with the <see cref="R"/> and <see cref="B"/> values
/// </summary>
public UInt2 RB
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RB)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RB)}");
}
/// <summary>
/// Gets or sets an <see cref="UInt2"/> value with the <see cref="G"/> and <see cref="R"/> values
/// </summary>
public UInt2 GR
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GR)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GR)}");
}
/// <summary>
/// Gets an <see cref="UInt2"/> value with the <see cref="G"/> value for all components
/// </summary>
public UInt2 GG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GG)}");
/// <summary>
/// Gets or sets an <see cref="UInt2"/> value with the <see cref="G"/> and <see cref="B"/> values
/// </summary>
public UInt2 GB
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GB)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GB)}");
}
/// <summary>
/// Gets or sets an <see cref="UInt2"/> value with the <see cref="B"/> and <see cref="R"/> values
/// </summary>
public UInt2 BR
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BR)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BR)}");
}
/// <summary>
/// Gets or sets an <see cref="UInt2"/> value with the <see cref="B"/> and <see cref="G"/> values
/// </summary>
public UInt2 BG
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BG)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BG)}");
}
/// <summary>
/// Gets an <see cref="UInt2"/> value with the <see cref="B"/> value for all components
/// </summary>
public UInt2 BB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BB)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="X"/> value for all components
/// </summary>
public UInt2 XXX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XXX)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public UInt2 XXY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XXY)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public UInt2 XXZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XXZ)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public UInt2 XYX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XYX)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Y"/> values
/// </summary>
public UInt2 XYY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XYY)}");
/// <summary>
/// Gets or sets an <see cref="UInt3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public UInt2 XYZ
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XYZ)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XYZ)}");
}
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public UInt2 XZX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XZX)}");
/// <summary>
/// Gets or sets an <see cref="UInt3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public UInt2 XZY
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XZY)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XZY)}");
}
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Z"/> values
/// </summary>
public UInt2 XZZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XZZ)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="X"/> values
/// </summary>
public UInt2 YXX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YXX)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public UInt2 YXY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YXY)}");
/// <summary>
/// Gets or sets an <see cref="UInt3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public UInt2 YXZ
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YXZ)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YXZ)}");
}
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public UInt2 YYX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YYX)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="Y"/> value for all components
/// </summary>
public UInt2 YYY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YYY)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public UInt2 YYZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YYZ)}");
/// <summary>
/// Gets or sets an <see cref="UInt3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public UInt2 YZX
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YZX)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YZX)}");
}
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public UInt2 YZY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YZY)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Z"/> values
/// </summary>
public UInt2 YZZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YZZ)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Z"/> values
/// </summary>
public UInt2 ZXX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZXX)}");
/// <summary>
/// Gets or sets an <see cref="UInt3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Y"/> values
/// </summary>
public UInt2 ZXY
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZXY)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZXY)}");
}
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Z"/> values
/// </summary>
public UInt2 ZXZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZXZ)}");
/// <summary>
/// Gets or sets an <see cref="UInt3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="X"/> values
/// </summary>
public UInt2 ZYX
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZYX)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZYX)}");
}
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Y"/> values
/// </summary>
public UInt2 ZYY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZYY)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Z"/> values
/// </summary>
public UInt2 ZYZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZYZ)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="X"/> values
/// </summary>
public UInt2 ZZX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZZX)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Y"/> values
/// </summary>
public UInt2 ZZY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZZY)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="Z"/> value for all components
/// </summary>
public UInt2 ZZZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZZZ)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="R"/> value for all components
/// </summary>
public UInt2 RRR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RRR)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="R"/>, <see cref="R"/> and <see cref="G"/> values
/// </summary>
public UInt2 RRG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RRG)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="R"/>, <see cref="R"/> and <see cref="B"/> values
/// </summary>
public UInt2 RRB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RRB)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="R"/>, <see cref="G"/> and <see cref="R"/> values
/// </summary>
public UInt2 RGR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RGR)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="R"/>, <see cref="G"/> and <see cref="G"/> values
/// </summary>
public UInt2 RGG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RGG)}");
/// <summary>
/// Gets or sets an <see cref="UInt3"/> value with the <see cref="R"/>, <see cref="G"/> and <see cref="B"/> values
/// </summary>
public UInt2 RGB
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RGB)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RGB)}");
}
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="R"/>, <see cref="B"/> and <see cref="R"/> values
/// </summary>
public UInt2 RBR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RBR)}");
/// <summary>
/// Gets or sets an <see cref="UInt3"/> value with the <see cref="R"/>, <see cref="B"/> and <see cref="G"/> values
/// </summary>
public UInt2 RBG
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RBG)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RBG)}");
}
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="R"/>, <see cref="B"/> and <see cref="B"/> values
/// </summary>
public UInt2 RBB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RBB)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="G"/>, <see cref="R"/> and <see cref="R"/> values
/// </summary>
public UInt2 GRR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GRR)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="G"/>, <see cref="R"/> and <see cref="G"/> values
/// </summary>
public UInt2 GRG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GRG)}");
/// <summary>
/// Gets or sets an <see cref="UInt3"/> value with the <see cref="G"/>, <see cref="R"/> and <see cref="B"/> values
/// </summary>
public UInt2 GRB
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GRB)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GRB)}");
}
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="G"/>, <see cref="G"/> and <see cref="R"/> values
/// </summary>
public UInt2 GGR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GGR)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="G"/> value for all components
/// </summary>
public UInt2 GGG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GGG)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="G"/>, <see cref="G"/> and <see cref="B"/> values
/// </summary>
public UInt2 GGB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GGB)}");
/// <summary>
/// Gets or sets an <see cref="UInt3"/> value with the <see cref="G"/>, <see cref="B"/> and <see cref="R"/> values
/// </summary>
public UInt2 GBR
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GBR)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GBR)}");
}
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="G"/>, <see cref="B"/> and <see cref="G"/> values
/// </summary>
public UInt2 GBG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GBG)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="G"/>, <see cref="B"/> and <see cref="B"/> values
/// </summary>
public UInt2 GBB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GBB)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="B"/>, <see cref="B"/> and <see cref="B"/> values
/// </summary>
public UInt2 BRR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BRR)}");
/// <summary>
/// Gets or sets an <see cref="UInt3"/> value with the <see cref="B"/>, <see cref="R"/> and <see cref="G"/> values
/// </summary>
public UInt2 BRG
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BRG)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BRG)}");
}
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="B"/>, <see cref="R"/> and <see cref="B"/> values
/// </summary>
public UInt2 BRB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BRB)}");
/// <summary>
/// Gets or sets an <see cref="UInt3"/> value with the <see cref="B"/>, <see cref="G"/> and <see cref="R"/> values
/// </summary>
public UInt2 BGR
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BGR)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BGR)}");
}
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="B"/>, <see cref="G"/> and <see cref="G"/> values
/// </summary>
public UInt2 BGG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BGG)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="B"/>, <see cref="G"/> and <see cref="B"/> values
/// </summary>
public UInt2 BGB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BGB)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="B"/>, <see cref="B"/> and <see cref="R"/> values
/// </summary>
public UInt2 BBR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BBR)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="B"/>, <see cref="B"/> and <see cref="G"/> values
/// </summary>
public UInt2 BBG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BBG)}");
/// <summary>
/// Gets an <see cref="UInt3"/> value with the <see cref="B"/> value for all components
/// </summary>
public UInt2 BBB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BBB)}");
/// <summary>
/// Creates a new <see cref="UInt3"/> value with the same value for all its components
/// </summary>
/// <param name="x">The value to use for the components of the new <see cref="UInt3"/> instance</param>
public static implicit operator UInt3(uint x) => new UInt3(x, x, x);
/// <summary>
/// Sums two <see cref="UInt3"/> values
/// </summary>
/// <param name="left">The first <see cref="UInt3"/> value to sum</param>
/// <param name="right">The second <see cref="UInt3"/> value to sum</param>
public static UInt3 operator +(UInt3 left, UInt3 right) => throw new InvalidExecutionContextException($"{nameof(UInt3)}.+");
/// <summary>
/// Divides two <see cref="UInt3"/> values
/// </summary>
/// <param name="left">The first <see cref="UInt3"/> value to divide</param>
/// <param name="right">The second <see cref="UInt3"/> value to divide</param>
public static UInt3 operator /(UInt3 left, UInt3 right) => throw new InvalidExecutionContextException($"{nameof(UInt3)}./");
/// <summary>
/// Multiplies two <see cref="UInt3"/> values
/// </summary>
/// <param name="left">The first <see cref="UInt3"/> value to multiply</param>
/// <param name="right">The second <see cref="UInt3"/> value to multiply</param>
public static UInt3 operator *(UInt3 left, UInt3 right) => throw new InvalidExecutionContextException($"{nameof(UInt3)}.*");
/// <summary>
/// Subtracts two <see cref="UInt3"/> values
/// </summary>
/// <param name="left">The first <see cref="UInt3"/> value to subtract</param>
/// <param name="right">The second <see cref="UInt3"/> value to subtract</param>
public static UInt3 operator -(UInt3 left, UInt3 right) => throw new InvalidExecutionContextException($"{nameof(UInt3)}.-");
}
}
ファイル差分が大きすぎるため表示されません。 差分を読み込み
-4
ファイルの表示
@@ -1,4 +0,0 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("ComputeSharp.Graphics")]
[assembly: InternalsVisibleTo("ComputeSharp.Shaders")]
-90
ファイルの表示
@@ -1,90 +0,0 @@
using System;
using System.Runtime.CompilerServices;
using Vortice.Direct3D12;
namespace ComputeSharp.Graphics.Buffers.Abstract
{
/// <summary>
/// An abstract <see langword="class"/> that represents a graphics resource object
/// </summary>
public abstract class GraphicsResource : IDisposable
{
/// <summary>
/// Creates a new <see cref="GraphicsResource"/> instance with the specified parameters
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance</param>
protected GraphicsResource(GraphicsDevice device)
{
GraphicsDevice = device;
}
/// <summary>
/// Gets the <see cref="GraphicsDevice"/> associated with the current instance
/// </summary>
public GraphicsDevice GraphicsDevice { get; }
/// <summary>
/// Gets the <see cref="ID3D12Resource"/> object currently mapped
/// </summary>
protected internal ID3D12Resource? NativeResource { get; set; }
/// <summary>
/// Gets the <see cref="CpuDescriptorHandle"/> instance for the current resource
/// </summary>
protected internal CpuDescriptorHandle? NativeCpuDescriptorHandle { get; protected set; }
/// <summary>
/// Gets the <see cref="GpuDescriptorHandle"/> instance for the current resource
/// </summary>
protected internal GpuDescriptorHandle? NativeGpuDescriptorHandle { get; protected set; }
/// <summary>
/// Maps the current resource to a specified subresource
/// </summary>
/// <returns>A <see cref="MappedResource"/> instance representing the mapped resource</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal MappedResource MapResource()
{
var resource = NativeResource ?? throw new InvalidOperationException("Missing resource");
return new MappedResource(resource);
}
/// <inheritdoc/>
public virtual void Dispose() => NativeResource?.Dispose();
/// <summary>
/// A type representing a mapped memory resource
/// </summary>
internal readonly ref struct MappedResource
{
/// <summary>
/// The target <see cref="ID3D12Resource"/> to map
/// </summary>
private readonly ID3D12Resource Resource;
/// <summary>
/// The pointer to the mapped resource
/// </summary>
public readonly IntPtr Pointer;
/// <summary>
/// Creates a new <see cref="MappedResource"/> instance for a given <see cref="ID3D12Resource"/> value
/// </summary>
/// <param name="resource">The input <see cref="ID3D12Resource"/> instance to map</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public MappedResource(ID3D12Resource resource)
{
Resource = resource;
Pointer = resource.Map(0);
}
/// <inheritdoc cref="IDisposable.Dispose"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose()
{
Resource.Unmap(0);
}
}
}
}
-112
ファイルの表示
@@ -1,112 +0,0 @@
using System;
using System.Buffers;
using System.Diagnostics.Contracts;
using ComputeSharp.Graphics.Buffers.Enums;
namespace ComputeSharp.Graphics.Buffers.Abstract
{
/// <summary>
/// A <see langword="class"/> representing a typed buffer stored on GPU memory, that can be used from an HLSL shader
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer</typeparam>
public abstract class HlslBuffer<T> : Buffer<T> where T : unmanaged
{
/// <summary>
/// Creates a new <see cref="HlslBuffer{T}"/> instance with the specified parameters
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance</param>
/// <param name="size">The number of items to store in the current buffer</param>
/// <param name="sizeInBytes">The size in bytes for the current buffer</param>
/// <param name="bufferType">The buffer type for the current buffer</param>
private protected HlslBuffer(GraphicsDevice device, int size, int sizeInBytes, BufferType bufferType) : base(device, size, sizeInBytes, bufferType) { }
/// <summary>
/// Reads the contents of the current <see cref="HlslBuffer{T}"/> instance and returns an array
/// </summary>
/// <returns>A <typeparamref name="T"/> array with the contents of the current buffer</returns>
[Pure]
public T[] GetData() => GetData(0, Size);
/// <summary>
/// Reads the contents of the current <see cref="HlslBuffer{T}"/> instance in a given range and returns an array
/// </summary>
/// <param name="offset">The offset to start reading data from</param>
/// <param name="count">The number of items to read</param>
/// <returns>A <typeparamref name="T"/> array with the contents of the specified range from the current buffer</returns>
[Pure]
public T[] GetData(int offset, int count)
{
T[] data = new T[count];
GetData(data, offset, count);
return data;
}
/// <summary>
/// Reads the contents of the current <see cref="HlslBuffer{T}"/> instance and writes them into a target <see cref="Span{T}"/>
/// </summary>
/// <param name="span">The input <see cref="Span{T}"/> to write data to</param>
public void GetData(Span<T> span) => GetData(span, 0, Size);
/// <summary>
/// Reads the contents of the specified range from the current <see cref="HlslBuffer{T}"/> instance and writes them into a target <see cref="Span{T}"/>
/// </summary>
/// <param name="span">The input <see cref="Span{T}"/> to write data to</param>
/// <param name="offset">The offset to start reading data from</param>
/// <param name="count">The number of items to read</param>
public abstract void GetData(Span<T> span, int offset, int count);
/// <summary>
/// Writes the contents of a given <typeparamref name="T"/> array to the current <see cref="HlslBuffer{T}"/> instance
/// </summary>
/// <param name="array">The input <typeparamref name="T"/> array to read data from</param>
public void SetData(T[] array) => SetData(array.AsSpan());
/// <summary>
/// Writes the contents of a given <typeparamref name="T"/> array to a specified area of the current <see cref="HlslBuffer{T}"/> instance
/// </summary>
/// <param name="array">The input <typeparamref name="T"/> array to read data from</param>
/// <param name="offset">The offset to start writing data to</param>
/// <param name="count">The number of items to write</param>
public void SetData(T[] array, int offset, int count) => SetData(array.AsSpan(), offset, count);
/// <summary>
/// Writes the contents of a given <see cref="ReadOnlySpan{T}"/> to the current <see cref="HlslBuffer{T}"/> instance
/// </summary>
/// <param name="span">The input <see cref="ReadOnlySpan{T}"/> to read data from</param>
public void SetData(ReadOnlySpan<T> span) => SetData(span, 0, Size);
/// <summary>
/// Writes the contents of a given <see cref="ReadOnlySpan{T}"/> to a specified area of the current <see cref="HlslBuffer{T}"/> instance
/// </summary>
/// <param name="span">The input <see cref="ReadOnlySpan{T}"/> to read data from</param>
/// <param name="offset">The offset to start writing data to</param>
/// <param name="count">The number of items to write</param>
public abstract void SetData(ReadOnlySpan<T> span, int offset, int count);
/// <summary>
/// Writes the contents of a given <see cref="HlslBuffer{T}"/> to the current <see cref="HlslBuffer{T}"/> instance
/// </summary>
/// <param name="buffer">The input <see cref="HlslBuffer{T}"/> to read data from</param>
public abstract void SetData(HlslBuffer<T> buffer);
/// <summary>
/// Writes the contents of a given <see cref="HlslBuffer{T}"/> to the current <see cref="HlslBuffer{T}"/> instance, using a temporary CPU buffer
/// </summary>
/// <param name="buffer">The input <see cref="HlslBuffer{T}"/> to read data from</param>
protected void SetDataWithCpuBuffer(HlslBuffer<T> buffer)
{
// Create a temporary array
T[] array = ArrayPool<T>.Shared.Rent(buffer.Size);
Span<T> span = array.AsSpan(0, buffer.Size);
// Get the unpadded data from the read write buffer
buffer.GetData(span);
// Set the data, adding the padding if needed
SetData(span);
ArrayPool<T>.Shared.Return(array);
}
}
}
-70
ファイルの表示
@@ -1,70 +0,0 @@
using System;
using System.Runtime.CompilerServices;
using ComputeSharp.Graphics.Buffers.Enums;
using ComputeSharp.Graphics.Helpers;
using Vortice.Direct3D12;
using CommandList = ComputeSharp.Graphics.Commands.CommandList;
namespace ComputeSharp.Graphics.Buffers.Abstract
{
/// <summary>
/// A <see langword="class"/> representing a typed structured buffer stored on GPU memory
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer</typeparam>
public abstract class HlslStructuredBuffer<T> : HlslBuffer<T> where T : unmanaged
{
/// <summary>
/// Creates a new <see cref="HlslStructuredBuffer{T}"/> instance with the specified parameters
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance</param>
/// <param name="size">The number of items to store in the current buffer</param>
/// <param name="bufferType">The buffer type for the current buffer</param>
internal HlslStructuredBuffer(GraphicsDevice device, int size, BufferType bufferType) : base(device, size, size * Unsafe.SizeOf<T>(), bufferType) { }
/// <inheritdoc/>
public override void GetData(Span<T> span, int offset, int count)
{
using Buffer<T> transferBuffer = new Buffer<T>(GraphicsDevice, count, count * ElementSizeInBytes, BufferType.ReadBack);
using (CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy))
{
copyCommandList.CopyBufferRegion(this, offset * ElementSizeInBytes, transferBuffer, 0, count * ElementSizeInBytes);
copyCommandList.ExecuteAndWaitForCompletion();
}
using MappedResource resource = transferBuffer.MapResource();
MemoryHelper.Copy(resource.Pointer, 0, span, 0, count);
}
/// <inheritdoc/>
public override void SetData(ReadOnlySpan<T> span, int offset, int count)
{
using Buffer<T> transferBuffer = new Buffer<T>(GraphicsDevice, count, count * ElementSizeInBytes, BufferType.Transfer);
using (MappedResource resource = transferBuffer.MapResource())
{
MemoryHelper.Copy(span, resource.Pointer, 0, count);
}
using CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy);
copyCommandList.CopyBufferRegion(transferBuffer, 0, this, offset * ElementSizeInBytes, count * ElementSizeInBytes);
copyCommandList.ExecuteAndWaitForCompletion();
}
/// <inheritdoc/>
public override void SetData(HlslBuffer<T> buffer)
{
if (!buffer.IsPaddingPresent)
{
// Directly copy the input buffer
using CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy);
copyCommandList.CopyBufferRegion(buffer, 0, this, 0, SizeInBytes);
copyCommandList.ExecuteAndWaitForCompletion();
}
else SetDataWithCpuBuffer(buffer);
}
}
}
-153
ファイルの表示
@@ -1,153 +0,0 @@
using System;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Buffers.Enums;
using SharpGen.Runtime;
using Vortice.Direct3D12;
namespace ComputeSharp.Graphics.Buffers
{
/// <summary>
/// A <see langword="class"/> representing a typed buffer stored on GPU memory
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer</typeparam>
public class Buffer<T> : GraphicsResource where T : unmanaged
{
/// <summary>
/// Creates a new <see cref="Buffer{T}"/> instance with the specified parameters
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance</param>
/// <param name="size">The number of items to store in the current buffer</param>
/// <param name="sizeInBytes">The size in bytes for the current buffer</param>
/// <param name="bufferType">The buffer type for the current buffer</param>
internal Buffer(GraphicsDevice device, int size, int sizeInBytes, BufferType bufferType) : base(device)
{
Size = size;
SizeInBytes = sizeInBytes; // Not necessarily a multiple of the element size, as there could be padding
ElementSizeInBytes = Unsafe.SizeOf<T>();
BufferType = bufferType;
PaddedElementSizeInBytes = sizeInBytes / size;
// Determine the right heap type and flags
(HeapType heapType, ResourceFlags flags, ResourceStates states) = bufferType switch
{
BufferType.Constant => (HeapType.Upload, ResourceFlags.None, ResourceStates.GenericRead),
BufferType.ReadOnly => (HeapType.Default, ResourceFlags.None, ResourceStates.Common),
BufferType.ReadWrite => (HeapType.Default, ResourceFlags.AllowUnorderedAccess, ResourceStates.Common),
BufferType.ReadBack => (HeapType.Readback, ResourceFlags.None, ResourceStates.CopyDestination),
BufferType.Transfer => (HeapType.Upload, ResourceFlags.None, ResourceStates.GenericRead),
_ => throw new ArgumentException($"Invalid buffer type {bufferType}", nameof(bufferType))
};
// Create the native resource
ResourceDescription description = ResourceDescription.Buffer(sizeInBytes, flags);
Result result = GraphicsDevice.NativeDevice.CreateCommittedResource(new HeapProperties(heapType), HeapFlags.None, description, states, out ID3D12Resource? resource);
if (result.Failure)
{
throw new COMException("Failed to create the committed resource", result.Code);
}
NativeResource = resource!;
// Create the resource handles, if needed
(NativeCpuDescriptorHandle, NativeGpuDescriptorHandle) = bufferType switch
{
BufferType.Constant => CreateConstantBufferView(),
BufferType.ReadOnly => CreateShaderResourceView(),
BufferType.ReadWrite => CreateUnorderedAccessView(),
_ => default
};
}
/// <summary>
/// Gets the size of the current buffer, as in the number of <typeparamref name="T"/> values it contains
/// </summary>
public int Size { get; }
/// <summary>
/// Gets the size in bytes of the current buffer
/// </summary>
protected int SizeInBytes { get; }
/// <summary>
/// Gets the size in bytes of each <typeparamref name="T"/> value contained in the buffer
/// </summary>
protected int ElementSizeInBytes { get; }
/// <summary>
/// Gets the size in bytes of the current buffer
/// </summary>
internal int PaddedElementSizeInBytes { get; }
/// <summary>
/// Gets whether or not there is some padding between elements in the current buffer
/// </summary>
internal bool IsPaddingPresent => PaddedElementSizeInBytes > ElementSizeInBytes;
/// <summary>
/// Gets the buffer type for the current <see cref="Buffer{T}"/> instance
/// </summary>
internal BufferType BufferType { get; }
/// <summary>
/// Creates the descriptors for a constant buffer
/// </summary>
/// <returns>The CPU and GPU handles for a constant buffer</returns>
[Pure]
private (CpuDescriptorHandle, GpuDescriptorHandle) CreateConstantBufferView()
{
(CpuDescriptorHandle cpuHandle, GpuDescriptorHandle gpuHandle) = GraphicsDevice.ShaderResourceViewAllocator.Allocate();
int constantBufferSize = (SizeInBytes + 255) & ~255;
ConstantBufferViewDescription description = new ConstantBufferViewDescription
{
BufferLocation = NativeResource!.GPUVirtualAddress,
SizeInBytes = constantBufferSize
};
GraphicsDevice.NativeDevice.CreateConstantBufferView(description, cpuHandle);
return (cpuHandle, gpuHandle);
}
private (CpuDescriptorHandle, GpuDescriptorHandle) CreateShaderResourceView()
{
(CpuDescriptorHandle cpuHandle, GpuDescriptorHandle gpuHandle) = GraphicsDevice.ShaderResourceViewAllocator.Allocate();
ShaderResourceViewDescription description = new ShaderResourceViewDescription
{
Shader4ComponentMapping = 5768,
ViewDimension = ShaderResourceViewDimension.Buffer,
Buffer = { NumElements = Size, StructureByteStride = ElementSizeInBytes }
};
GraphicsDevice.NativeDevice.CreateShaderResourceView(NativeResource, description, cpuHandle);
return (cpuHandle, gpuHandle);
}
/// <summary>
/// Creates the descriptors for a read write buffer
/// </summary>
/// <returns>The CPU and GPU handles for a read write buffer</returns>
[Pure]
private (CpuDescriptorHandle, GpuDescriptorHandle) CreateUnorderedAccessView()
{
(CpuDescriptorHandle cpuHandle, GpuDescriptorHandle gpuHandle) = GraphicsDevice.ShaderResourceViewAllocator.Allocate();
UnorderedAccessViewDescription description = new UnorderedAccessViewDescription
{
ViewDimension = UnorderedAccessViewDimension.Buffer,
Buffer = { NumElements = Size, StructureByteStride = ElementSizeInBytes }
};
GraphicsDevice.NativeDevice.CreateUnorderedAccessView(NativeResource, null, description, cpuHandle);
return (cpuHandle, gpuHandle);
}
}
}
-107
ファイルの表示
@@ -1,107 +0,0 @@
using System;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Buffers.Enums;
using ComputeSharp.Graphics.Helpers;
using Vortice.Direct3D12;
using CommandList = ComputeSharp.Graphics.Commands.CommandList;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="class"/> representing a typed read write buffer stored on GPU memory
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer</typeparam>
public sealed class ConstantBuffer<T> : HlslBuffer<T> where T : unmanaged
{
/// <summary>
/// Creates a new <see cref="ConstantBuffer{T}"/> instance with the specified parameters
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance</param>
/// <param name="size">The number of items to store in the current buffer</param>
internal ConstantBuffer(GraphicsDevice device, int size) : base(device, size, size * GetPaddedSize(), BufferType.Constant) { }
/// <summary>
/// Gets the right padded size for <typeparamref name="T"/> elements to store in the current instance
/// </summary>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int GetPaddedSize()
{
int size = Unsafe.SizeOf<T>();
return (size + 15) & ~15;
}
/// <summary>
/// Gets a single <typeparamref name="T"/> value from the current constant buffer
/// </summary>
/// <param name="i">The index of the value to get</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else</remarks>
public T this[int i] => throw new InvalidExecutionContextException($"{nameof(ConstantBuffer<T>)}<T>[int]");
/// <inheritdoc/>
public override unsafe void GetData(Span<T> span, int offset, int count)
{
using MappedResource resource = MapResource();
if (IsPaddingPresent)
{
ref T spanRef = ref MemoryMarshal.GetReference(span);
ref byte resourceRef = ref Unsafe.AsRef<byte>((void*)resource.Pointer);
// Move to the initial ref
resourceRef = ref Unsafe.Add(ref resourceRef, offset * GetPaddedSize());
for (var i = 0; i < count; i++)
{
ref byte targetRef = ref Unsafe.Add(ref resourceRef, i * GetPaddedSize());
Unsafe.Add(ref spanRef, i) = Unsafe.As<byte, T>(ref targetRef);
}
}
else MemoryHelper.Copy(resource.Pointer, offset, span, 0, count);
}
/// <inheritdoc/>
public override unsafe void SetData(ReadOnlySpan<T> span, int offset, int count)
{
using MappedResource resource = MapResource();
if (IsPaddingPresent)
{
ref T spanRef = ref MemoryMarshal.GetReference(span);
ref byte resourceRef = ref Unsafe.AsRef<byte>((void*)resource.Pointer);
// Move to the initial offset
resourceRef = ref Unsafe.Add(ref resourceRef, offset * GetPaddedSize());
for (var i = 0; i < count; i++)
{
ref byte targetRef = ref Unsafe.Add(ref resourceRef, i * GetPaddedSize());
Unsafe.As<byte, T>(ref targetRef) = Unsafe.Add(ref spanRef, i);
}
}
else MemoryHelper.Copy(span, resource.Pointer, offset, count);
}
/// <inheritdoc/>
public override void SetData(HlslBuffer<T> buffer)
{
if (buffer is ConstantBuffer<T>)
{
// Directly copy the input buffer, if possible
using CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy);
copyCommandList.CopyBufferRegion(buffer, 0, this, 0, SizeInBytes);
copyCommandList.ExecuteAndWaitForCompletion();
}
else SetDataWithCpuBuffer(buffer);
}
}
}
-33
ファイルの表示
@@ -1,33 +0,0 @@
namespace ComputeSharp.Graphics.Buffers.Enums
{
/// <summary>
/// An <see langword="enum"/> that indicates the type of a given HLSL buffer
/// </summary>
internal enum BufferType
{
/// <summary>
/// A constant buffer, with items aligned to 16 bytes, used for individual values or very small arrays, mapped to <see cref="Vortice.DirectX.Direct3D12.HeapType.Upload"/>
/// </summary>
Constant,
/// <summary>
/// A readonly buffer, that can store arbitrary arrays of values, mapped to <see cref="Vortice.DirectX.Direct3D12.HeapType.Default"/>
/// </summary>
ReadOnly,
/// <summary>
/// A read write buffer, that can store arbitrary arrays with both read and write access, mapped to <see cref="Vortice.DirectX.Direct3D12.HeapType.Default"/>
/// </summary>
ReadWrite,
/// <summary>
/// A readback buffer, used as temporary buffer to read data back from buffers in the default heap, mapped to <see cref="Vortice.DirectX.Direct3D12.HeapType.Readback"/>
/// </summary>
ReadBack,
/// <summary>
/// A transfer buffer, used as a temporary buffer to set data to buffers in the default heap, mapped to <see cref="Vortice.DirectX.Direct3D12.HeapType.Upload"/>
/// </summary>
Transfer
}
}
-229
ファイルの表示
@@ -1,229 +0,0 @@
using System;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Buffers.Abstract;
using Microsoft.Toolkit.HighPerformance.Extensions;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="class"/> with extension methods for the <see cref="GraphicsDevice"/> type to allocate buffers
/// </summary>
public static class BufferExtensions
{
/// <summary>
/// Allocates a new constant buffer with the specified parameters
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer</param>
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated buffer</param>
/// <returns>A constant <see cref="ConstantBuffer{T}"/> instance with the contents of the input array</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, T[] array) where T : unmanaged
{
return device.AllocateConstantBuffer(array.AsSpan());
}
/// <summary>
/// Allocates a new constant buffer with the specified parameters
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer</param>
/// <param name="array">The input 2D <typeparamref name="T"/> array with the data to copy on the allocated buffer</param>
/// <returns>A constant <see cref="ConstantBuffer{T}"/> instance with the contents of the input 2D array</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, T[,] array) where T : unmanaged
{
return device.AllocateConstantBuffer(array.AsSpan());
}
/// <summary>
/// Allocates a new constant buffer with the specified parameters
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer</param>
/// <param name="span">The input <see cref="Span{T}"/> with the data to copy on the allocated buffer</param>
/// <returns>A constant <see cref="ConstantBuffer{T}"/> instance with the contents of the input <see cref="Span{T}"/></returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, Span<T> span) where T : unmanaged
{
ConstantBuffer<T> buffer = new ConstantBuffer<T>(device, span.Length);
buffer.SetData(span);
return buffer;
}
/// <summary>
/// Allocates a new constant buffer with the specified parameters
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer</param>
/// <param name="buffer">The input <see cref="HlslBuffer{T}"/> with the data to copy on the allocated buffer</param>
/// <returns>A constant <see cref="ConstantBuffer{T}"/> instance with the contents of the input <see cref="HlslBuffer{T}"/></returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, HlslBuffer<T> buffer) where T : unmanaged
{
ConstantBuffer<T> constantBuffer = new ConstantBuffer<T>(device, buffer.Size);
constantBuffer.SetData(buffer);
return constantBuffer;
}
/// <summary>
/// Allocates a new readonly buffer with the specified parameters
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer</param>
/// <param name="size">The size of the buffer to allocate</param>
/// <returns>A zeroed <see cref="ReadOnlyBuffer{T}"/> instance of size <paramref name="size"/></returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, int size) where T : unmanaged
{
return new ReadOnlyBuffer<T>(device, size);
}
/// <summary>
/// Allocates a new readonly buffer with the specified parameters
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer</param>
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated buffer</param>
/// <returns>A read write <see cref="ReadOnlyBuffer{T}"/> instance with the contents of the input array</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, T[] array) where T : unmanaged
{
return device.AllocateReadOnlyBuffer(array.AsSpan());
}
/// <summary>
/// Allocates a new readonly buffer with the specified parameters
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer</param>
/// <param name="array">The input 2D <typeparamref name="T"/> array with the data to copy on the allocated buffer</param>
/// <returns>A read write <see cref="ReadOnlyBuffer{T}"/> instance with the contents of the input 2D array</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, T[,] array) where T : unmanaged
{
return device.AllocateReadOnlyBuffer(array.AsSpan());
}
/// <summary>
/// Allocates a new readonly buffer with the specified parameters
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer</param>
/// <param name="span">The input <see cref="Span{T}"/> with the data to copy on the allocated buffer</param>
/// <returns>A read write <see cref="ReadOnlyBuffer{T}"/> instance with the contents of the input <see cref="Span{T}"/></returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, Span<T> span) where T : unmanaged
{
ReadOnlyBuffer<T> buffer = new ReadOnlyBuffer<T>(device, span.Length);
buffer.SetData(span);
return buffer;
}
/// <summary>
/// Allocates a new readonly buffer with the specified parameters
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer</param>
/// <param name="buffer">The input <see cref="HlslBuffer{T}"/> with the data to copy on the allocated buffer</param>
/// <returns>A read write <see cref="ReadOnlyBuffer{T}"/> instance with the contents of the input <see cref="HlslBuffer{T}"/></returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, HlslBuffer<T> buffer) where T : unmanaged
{
ReadOnlyBuffer<T> readWriteBuffer = new ReadOnlyBuffer<T>(device, buffer.Size);
readWriteBuffer.SetData(buffer);
return readWriteBuffer;
}
/// <summary>
/// Allocates a new read write buffer with the specified parameters
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer</param>
/// <param name="size">The size of the buffer to allocate</param>
/// <returns>A zeroed <see cref="ReadWriteBuffer{T}"/> instance of size <paramref name="size"/></returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, int size) where T : unmanaged
{
return new ReadWriteBuffer<T>(device, size);
}
/// <summary>
/// Allocates a new read write buffer with the specified parameters
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer</param>
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated buffer</param>
/// <returns>A read write <see cref="ReadWriteBuffer{T}"/> instance with the contents of the input array</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, T[] array) where T : unmanaged
{
return device.AllocateReadWriteBuffer(array.AsSpan());
}
/// <summary>
/// Allocates a new read write buffer with the specified parameters
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer</param>
/// <param name="array">The input 2D <typeparamref name="T"/> array with the data to copy on the allocated buffer</param>
/// <returns>A read write <see cref="ReadWriteBuffer{T}"/> instance with the contents of the input 2D array</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, T[,] array) where T : unmanaged
{
return device.AllocateReadWriteBuffer(array.AsSpan());
}
/// <summary>
/// Allocates a new read write buffer with the specified parameters
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer</param>
/// <param name="span">The input <see cref="Span{T}"/> with the data to copy on the allocated buffer</param>
/// <returns>A read write <see cref="ReadWriteBuffer{T}"/> instance with the contents of the input <see cref="Span{T}"/></returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, Span<T> span) where T : unmanaged
{
ReadWriteBuffer<T> buffer = new ReadWriteBuffer<T>(device, span.Length);
buffer.SetData(span);
return buffer;
}
/// <summary>
/// Allocates a new read write buffer with the specified parameters
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer</param>
/// <param name="buffer">The input <see cref="HlslBuffer{T}"/> with the data to copy on the allocated buffer</param>
/// <returns>A read write <see cref="ReadWriteBuffer{T}"/> instance with the contents of the input <see cref="HlslBuffer{T}"/></returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, HlslBuffer<T> buffer) where T : unmanaged
{
ReadWriteBuffer<T> readWriteBuffer = new ReadWriteBuffer<T>(device, buffer.Size);
readWriteBuffer.SetData(buffer);
return readWriteBuffer;
}
}
}
-28
ファイルの表示
@@ -1,28 +0,0 @@
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Buffers.Enums;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="class"/> representing a typed readonly buffer stored on GPU memory
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer</typeparam>
public sealed class ReadOnlyBuffer<T> : HlslStructuredBuffer<T> where T : unmanaged
{
/// <summary>
/// Creates a new <see cref="ReadOnlyBuffer{T}"/> instance with the specified parameters
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance</param>
/// <param name="size">The number of items to store in the current buffer</param>
internal ReadOnlyBuffer(GraphicsDevice device, int size) : base(device, size, BufferType.ReadOnly) { }
/// <summary>
/// Gets a single <typeparamref name="T"/> value from the current read write buffer
/// </summary>
/// <param name="i">The index of the value to get</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else</remarks>
public T this[int i] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyBuffer<T>)}<T>[int]");
}
}
-28
ファイルの表示
@@ -1,28 +0,0 @@
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Buffers.Enums;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="class"/> representing a typed read write buffer stored on GPU memory
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer</typeparam>
public sealed class ReadWriteBuffer<T> : HlslStructuredBuffer<T> where T : unmanaged
{
/// <summary>
/// Creates a new <see cref="ReadWriteBuffer{T}"/> instance with the specified parameters
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance</param>
/// <param name="size">The number of items to store in the current buffer</param>
internal ReadWriteBuffer(GraphicsDevice device, int size) : base(device, size, BufferType.ReadWrite) { }
/// <summary>
/// Gets or sets a single <typeparamref name="T"/> value from the current read write buffer
/// </summary>
/// <param name="i">The index of the value to get or set</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else</remarks>
public ref T this[int i] => throw new InvalidExecutionContextException($"{nameof(ReadWriteBuffer<T>)}<T>[int]");
}
}
-35
ファイルの表示
@@ -1,35 +0,0 @@
using System;
using Vortice.Direct3D12;
namespace ComputeSharp.Graphics.Commands.Abstract
{
/// <summary>
/// A base <see langword="class"/> for an instance that deals with GPU commands in some way
/// </summary>
internal abstract class CommandController : IDisposable
{
/// <summary>
/// Creates a new <see cref="CommandAllocatorPool"/> instance with the specified parameters
/// </summary>
/// <param name="device">The input <see cref="Graphics.GraphicsDevice"/> to use to perform requested operations</param>
/// <param name="commandListType">The type of command list to use for the current instance</param>
protected CommandController(GraphicsDevice device, CommandListType commandListType)
{
GraphicsDevice = device;
CommandListType = commandListType;
}
/// <summary>
/// Gets the <see cref="Graphics.GraphicsDevice"/> object targeted by the current instance
/// </summary>
public GraphicsDevice GraphicsDevice { get; }
/// <summary>
/// Gets the command list type being used by the current instance
/// </summary>
public CommandListType CommandListType { get; }
/// <inheritdoc/>
public abstract void Dispose();
}
}
-93
ファイルの表示
@@ -1,93 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using ComputeSharp.Graphics.Commands.Abstract;
using SharpGen.Runtime;
using Vortice.Direct3D12;
namespace ComputeSharp.Graphics.Commands
{
/// <summary>
/// A <see langword="class"/> that acts as a pool to get new <see cref="ID3D12CommandAllocator"/> instances wheen needed
/// </summary>
internal sealed class CommandAllocatorPool : CommandController
{
/// <summary>
/// The queue of currently pooled <see cref="ID3D12CommandAllocator"/> instances
/// </summary>
private readonly Queue<(ID3D12CommandAllocator CommandAllocator, long FenceValue)> CommandAllocatorQueue = new Queue<(ID3D12CommandAllocator, long)>();
/// <inheritdoc/>
public CommandAllocatorPool(GraphicsDevice device, CommandListType commandListType) : base(device, commandListType) { }
/// <summary>
/// Adds a new <see cref="ID3D12CommandAllocator"/> item to the internal pool queue
/// </summary>
/// <param name="commandAllocator">The input <see cref="ID3D12CommandAllocator"/> to enqueue</param>
/// <param name="fenceValue">The fence value for the input <see cref="ID3D12CommandAllocator"/></param>
public void Enqueue(ID3D12CommandAllocator commandAllocator, long fenceValue)
{
lock (CommandAllocatorQueue)
{
CommandAllocatorQueue.Enqueue((commandAllocator, fenceValue));
}
}
/// <summary>
/// Gets a new or reused <see cref="ID3D12CommandAllocator"/> item to use to issue GPU commands
/// </summary>
[Pure]
public ID3D12CommandAllocator GetCommandAllocator()
{
lock (CommandAllocatorQueue)
{
// Reuse an existing command allocator, if one is present in the queue
if (CommandAllocatorQueue.Count > 0)
{
(ID3D12CommandAllocator commandAllocator, long fenceValue) = CommandAllocatorQueue.Peek();
long completedValue = CommandListType switch
{
CommandListType.Compute => GraphicsDevice.NativeComputeFence.CompletedValue,
CommandListType.Copy => GraphicsDevice.NativeCopyFence.CompletedValue,
CommandListType.Direct => GraphicsDevice.NativeDirectFence.CompletedValue,
_ => throw new NotSupportedException($"Unsupported command list type with value {CommandListType}")
};
if (fenceValue <= completedValue)
{
CommandAllocatorQueue.Dequeue();
commandAllocator.Reset();
return commandAllocator;
}
}
// Create a new command allocator
Result result = GraphicsDevice.NativeDevice.CreateCommandAllocator(CommandListType, out ID3D12CommandAllocator? nativeCommandAllocator);
if (result.Failure)
{
throw new COMException("Failed to create the command allocator", result.Code);
}
return nativeCommandAllocator!;
}
}
/// <inheritdoc/>
public override void Dispose()
{
lock (CommandAllocatorQueue)
{
foreach ((ID3D12CommandAllocator commandAllocator, long _) in CommandAllocatorQueue)
{
commandAllocator.Dispose();
}
CommandAllocatorQueue.Clear();
}
}
}
}
-132
ファイルの表示
@@ -1,132 +0,0 @@
using System;
using System.Runtime.InteropServices;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Commands.Abstract;
using SharpGen.Runtime;
using Vortice.Direct3D12;
namespace ComputeSharp.Graphics.Commands
{
/// <summary>
/// A <see langword="class"/> that represents a list of commands to issue to a GPU
/// </summary>
internal sealed class CommandList : CommandController
{
/// <inheritdoc/>
public CommandList(GraphicsDevice device, CommandListType commandListType) : base(device, commandListType)
{
CommandAllocator = CommandListType switch
{
CommandListType.Compute => GraphicsDevice.ComputeAllocatorPool.GetCommandAllocator(),
CommandListType.Copy => GraphicsDevice.CopyAllocatorPool.GetCommandAllocator(),
CommandListType.Direct => GraphicsDevice.DirectAllocatorPool.GetCommandAllocator(),
_ => throw new NotSupportedException($"Unsupported command list type with value {CommandListType}")
};
Result result = GraphicsDevice.NativeDevice.CreateCommandList(0, commandListType, CommandAllocator, null, out ID3D12GraphicsCommandList? nativeCommandList);
if (result.Failure)
{
throw new COMException("Failed to create the commands list", result.Code);
}
NativeCommandList = nativeCommandList!;
// Set the heap descriptor if the command list is not for copy operations
if (CommandListType != CommandListType.Copy)
{
NativeCommandList.SetDescriptorHeaps(1, new[] { GraphicsDevice.ShaderResourceViewAllocator.DescriptorHeap });
}
}
/// <summary>
/// Gets the <see cref="ID3D12CommandAllocator"/> object in use by the current instance
/// </summary>
public ID3D12CommandAllocator CommandAllocator { get; }
/// <summary>
/// Gets the <see cref="ID3D12GraphicsCommandList"/> object in use by the current instance
/// </summary>
public ID3D12GraphicsCommandList NativeCommandList { get; }
/// <summary>
/// Copies a memory region from one resource to another
/// </summary>
/// <param name="source">The source <see cref="GraphicsResource"/> to read from</param>
/// <param name="sourceOffset">The starting offset to read the source resource from</param>
/// <param name="destination">The destination <see cref="GraphicsResource"/> to write to</param>
/// <param name="destinationOffset">The starting offset to write the destination resource from</param>
/// <param name="numBytes">The total number of bytes to copy from one resource to another</param>
public void CopyBufferRegion(GraphicsResource source, long sourceOffset, GraphicsResource destination, long destinationOffset, long numBytes)
{
NativeCommandList.CopyBufferRegion(destination.NativeResource, destinationOffset, source.NativeResource, sourceOffset, numBytes);
}
/// <summary>
/// Binds an input <see cref="GraphicsResource"/> object to a specified root parameter
/// </summary>
/// <param name="rootParameterIndex">The root parameter index to bind to the input resource</param>
/// <param name="resource">The input <see cref="GraphicsResource"/> instance to bind</param>
public void SetComputeRootDescriptorTable(int rootParameterIndex, GraphicsResource resource)
{
if (resource.NativeGpuDescriptorHandle == null) throw new InvalidOperationException("Invalid graphics resource GPU descriptor");
if (resource.GraphicsDevice != GraphicsDevice) throw new GraphicsDeviceMismatchException(GraphicsDevice, resource);
NativeCommandList.SetComputeRootDescriptorTable(rootParameterIndex, resource.NativeGpuDescriptorHandle.Value);
}
/// <summary>
/// Sets a given <see cref="PipelineState"/> object ready to be executed
/// </summary>
/// <param name="pipelineState">The input <see cref="PipelineState"/> to setup</param>
public void SetPipelineState(PipelineState pipelineState)
{
NativeCommandList.SetComputeRootSignature(pipelineState.RootSignature);
NativeCommandList.SetPipelineState(pipelineState.NativePipelineState);
}
/// <summary>
/// Dispatches the pending shader using the specified thread group values
/// </summary>
/// <param name="threadGroupCountX">The number of thread groups to schedule for the X axis</param>
/// <param name="threadGroupCountY">The number of thread groups to schedule for the Y axis</param>
/// <param name="threadGroupCountZ">The number of thread groups to schedule for the Z axis</param>
public void Dispatch(int threadGroupCountX, int threadGroupCountY, int threadGroupCountZ)
{
NativeCommandList.Dispatch(threadGroupCountX, threadGroupCountY, threadGroupCountZ);
}
/// <summary>
/// Executes the commands in the current commands list, and waits for completion
/// </summary>
public void ExecuteAndWaitForCompletion()
{
NativeCommandList.Close();
GraphicsDevice.ExecuteCommandList(this);
}
/// <inheritdoc/>
public override void Dispose()
{
switch (CommandListType)
{
case CommandListType.Direct:
GraphicsDevice.DirectAllocatorPool.Enqueue(CommandAllocator, GraphicsDevice.NextDirectFenceValue - 1);
break;
case CommandListType.Compute:
GraphicsDevice.ComputeAllocatorPool.Enqueue(CommandAllocator, GraphicsDevice.NextComputeFenceValue - 1);
break;
case CommandListType.Copy:
GraphicsDevice.CopyAllocatorPool.Enqueue(CommandAllocator, GraphicsDevice.NextCopyFenceValue - 1);
break;
default:
throw new NotSupportedException($"Unsupported command list type with value {CommandListType}");
}
NativeCommandList.Dispose();
}
}
}
-29
ファイルの表示
@@ -1,29 +0,0 @@
using Vortice.Direct3D12;
namespace ComputeSharp.Graphics.Commands
{
/// <summary>
/// A <see langword="class"/> representing a custom pipeline state for a compute operation
/// </summary>
internal sealed class PipelineState : ComputePipelineStateDescription
{
/// <summary>
/// Creates a new <see cref="PipelineState"/> instance with the specified parameters
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> to use</param>
/// <param name="rootSignature">The <see cref="ID3D12RootSignature"/> value for the current shader</param>
/// <param name="computeShader">The bytecode for the compute shader to run</param>
public PipelineState(GraphicsDevice device, ID3D12RootSignature rootSignature, ShaderBytecode computeShader)
{
RootSignature = rootSignature;
ComputeShader = computeShader;
NativePipelineState = device.NativeDevice.CreateComputePipelineState<ID3D12PipelineState>(this);
}
/// <summary>
/// Gets the <see cref="ID3D12PipelineState"/> instance for the current <see cref="PipelineState"/> object
/// </summary>
public ID3D12PipelineState NativePipelineState { get; }
}
}
-19
ファイルの表示
@@ -1,19 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Toolkit.HighPerformance" Version="6.1.1" />
<PackageReference Include="Vortice.Direct3D12" Version="1.8.6" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ComputeSharp.Core\ComputeSharp.Core.csproj" />
</ItemGroup>
</Project>
-97
ファイルの表示
@@ -1,97 +0,0 @@
using System;
using Vortice.Direct3D12;
namespace ComputeSharp.Graphics
{
/// <summary>
/// A <see langword="class"/> that provides logic to create resource descriptors for a <see cref="GraphicsDevice"/> instance
/// </summary>
internal sealed class DescriptorAllocator : IDisposable
{
/// <summary>
/// The default number of available descriptors per heap
/// </summary>
private const int DescriptorsPerHeap = 4096;
/// <summary>
/// The dummy object used to handle concurrent allocation requests
/// </summary>
private readonly object Lock = new object();
/// <summary>
/// The size of each new descriptor being allocated
/// </summary>
private readonly int DescriptorSize;
/// <summary>
/// The current <see cref="CpuDescriptorHandle"/> for the <see cref="DescriptorAllocator"/> instance in use
/// </summary>
private CpuDescriptorHandle _CurrentCpuHandle;
/// <summary>
/// The current <see cref="GpuDescriptorHandle"/> for the <see cref="DescriptorAllocator"/> instance in use
/// </summary>
private GpuDescriptorHandle _CurrentGpuHandle;
/// <summary>
/// The number of remaining handles to allocate on the current heap
/// </summary>
private int _RemainingHandles;
/// <summary>
/// Creates a new <see cref="DescriptorAllocator"/> instance with the specified parameters
/// </summary>
/// <param name="device">The <see cref="ID3D12Device"/> instance to use</param>
public DescriptorAllocator(ID3D12Device device)
{
DescriptorSize = device.GetDescriptorHandleIncrementSize(DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView);
DescriptorHeapDescription descriptorHeapDescription = new DescriptorHeapDescription
{
DescriptorCount = DescriptorsPerHeap,
Flags = DescriptorHeapFlags.ShaderVisible,
Type = DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView
};
DescriptorHeap = device.CreateDescriptorHeap(descriptorHeapDescription);
_RemainingHandles = DescriptorsPerHeap;
_CurrentCpuHandle = DescriptorHeap.GetCPUDescriptorHandleForHeapStart();
_CurrentGpuHandle = DescriptorHeap.GetGPUDescriptorHandleForHeapStart();
}
/// <summary>
/// Gets the <see cref="ID3D12DescriptorHeap"/> object in use for the current <see cref="DescriptorAllocator"/> instance
/// </summary>
public ID3D12DescriptorHeap DescriptorHeap { get; }
/// <summary>
/// Allocates a new CPU and GPU handle pair to use in a memory buffer
/// </summary>
/// <returns>A pair of <see cref="CpuDescriptorHandle"/> and <see cref="GpuDescriptorHandle"/> to use</returns>
public (CpuDescriptorHandle, GpuDescriptorHandle) Allocate()
{
lock (Lock)
{
if (_RemainingHandles == 0)
{
_RemainingHandles = DescriptorHeap.Description.DescriptorCount;
_CurrentCpuHandle = DescriptorHeap.GetCPUDescriptorHandleForHeapStart();
_CurrentGpuHandle = DescriptorHeap.GetGPUDescriptorHandleForHeapStart();
}
CpuDescriptorHandle cpuDescriptorHandle = _CurrentCpuHandle;
GpuDescriptorHandle gpuDescriptorHandle = _CurrentGpuHandle;
_CurrentCpuHandle += DescriptorSize;
_CurrentGpuHandle += DescriptorSize;
_RemainingHandles -= 1;
return (cpuDescriptorHandle, gpuDescriptorHandle);
}
}
/// <inheritdoc/>
public void Dispose() => DescriptorHeap.Dispose();
}
}
-45
ファイルの表示
@@ -1,45 +0,0 @@
using System;
using System.Diagnostics.Contracts;
using System.Text;
using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Extensions;
namespace ComputeSharp.Exceptions
{
/// <summary>
/// A custom <see cref="GraphicsDeviceMismatchException"/> that indicates when mismatched devices are being used
/// </summary>
public sealed class GraphicsDeviceMismatchException : InvalidOperationException
{
/// <summary>
/// Creates a new <see cref="GraphicsDeviceMismatchException"/> instance
/// </summary>
internal GraphicsDeviceMismatchException(GraphicsDevice device, GraphicsResource resource) : base(GetExceptionMessage(device, resource)) { }
// Gets a proper exception message for a pair of device and resource
[Pure]
private static string GetExceptionMessage(GraphicsDevice device, GraphicsResource resource)
{
StringBuilder builder = new StringBuilder();
builder.AppendLine("Invalid pairing of graphics devices used to run a compute shader and allocate memory buffers.");
// Check if the device is effectively the same but with two instances pointing to the same adapter
if (device.NativeDevice.AdapterLuid == resource.GraphicsDevice.NativeDevice.AdapterLuid)
{
builder.AppendLine("The graphics devices used to allocate buffers and run the shader must be the same instance, not just be using the same physical device.");
builder.AppendLine("You can still run different shaders on different devices, but a shader run on one device must only use buffers allocated by the same device instance.");
}
else
{
// Actually different devices
builder.AppendLine($"The target device to run the compute shader is \"{device.Name}\" (id: {device.NativeDevice.AdapterLuid}).");
builder.AppendLine($"The buffer of type {resource.GetType().ToFriendlyString()} was allocated on device \"{resource.GraphicsDevice.Name}\" (id: {resource.GraphicsDevice.NativeDevice.AdapterLuid}).");
builder.AppendLine("Make sure to always allocate buffers on the same device used to actually run the code that accesses them.");
}
return builder.ToString();
}
}
}
-50
ファイルの表示
@@ -1,50 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
namespace ComputeSharp.Graphics.Extensions
{
/// <summary>
/// A <see langword="class"/> that provides extension methods for the <see cref="Type"/> type
/// </summary>
internal static class TypeExtensions
{
/// <summary>
/// The mapping of supported known types to display string
/// </summary>
private static readonly IReadOnlyDictionary<Type, string> KnownTypes = new Dictionary<Type, string>
{
[typeof(bool)] = "bool",
[typeof(int)] = "int",
[typeof(uint)] = "uint",
[typeof(float)] = "float",
[typeof(double)] = "double"
};
/// <summary>
/// Gets a friendly display <see langword="string"/> for the input type
/// </summary>
/// <param name="type">The input type to analyze</param>
[Pure]
public static string ToFriendlyString(this Type type)
{
// Array types of arbitrary rank
if (type.IsArray)
{
int rank = type.GetArrayRank();
return $"{type.GetElementType().ToFriendlyString()}[{new string(Enumerable.Repeat(',', rank - 1).ToArray())}]";
}
// Non generic types
string name;
if (type.GetGenericArguments().Length == 0) return KnownTypes.TryGetValue(type, out name) ? name : type.Name;
// Generic types
Type[] genericArguments = type.GetGenericArguments();
string typeDefeninition = KnownTypes.TryGetValue(type, out name) ? name : type.Name;
string polishedName = typeDefeninition.Substring(0, typeDefeninition.IndexOf("`"));
return $"{polishedName}<{string.Join(",", genericArguments.Select(ToFriendlyString))}>";
}
}
}
-234
ファイルの表示
@@ -1,234 +0,0 @@
using System;
using ComputeSharp.Graphics.Commands;
using Vortice.Direct3D12;
using Vortice.DXGI;
using CommandList = ComputeSharp.Graphics.Commands.CommandList;
using Direct3DFeatureLevel = Vortice.Direct3D.FeatureLevel;
namespace ComputeSharp.Graphics
{
/// <summary>
/// A <see langword="class"/> that represents a DX12.1-compatible GPU device that can be used to run compute shaders
/// </summary>
public sealed class GraphicsDevice : IDisposable
{
/// <summary>
/// Gets the <see cref="FeatureLevel"/> value that needs to be supported by GPUs mapped to a <see cref="GraphicsDevice"/> instance
/// </summary>
public const Direct3DFeatureLevel FeatureLevel = Direct3DFeatureLevel.Level_12_1;
/// <summary>
/// The <see cref="ID3D12CommandQueue"/> instance to use for compute operations
/// </summary>
private readonly ID3D12CommandQueue NativeComputeCommandQueue;
/// <summary>
/// The <see cref="ID3D12CommandQueue"/> instance to use for copy operations
/// </summary>
private readonly ID3D12CommandQueue NativeCopyCommandQueue;
/// <summary>
/// The <see cref="ID3D12CommandQueue"/> instance to use for direct operations
/// </summary>
private readonly ID3D12CommandQueue NativeDirectCommandQueue;
/// <summary>
/// Creates a new <see cref="GraphicsDevice"/> instance for the input <see cref="ID3D12Device"/>
/// </summary>
/// <param name="device">The <see cref="ID3D12Device"/> to use for the new <see cref="GraphicsDevice"/> instance</param>
/// <param name="description">The available info for the new <see cref="GraphicsDevice"/> instance</param>
public GraphicsDevice(ID3D12Device device, AdapterDescription description)
{
NativeDevice = device;
Name = description.Description;
MemorySize = description.DedicatedVideoMemory;
ComputeUnits = device.Options1.TotalLaneCount;
WavefrontSize = device.Options1.WaveLaneCountMin;
NativeComputeCommandQueue = NativeDevice.CreateCommandQueue(new CommandQueueDescription(CommandListType.Compute));
NativeCopyCommandQueue = NativeDevice.CreateCommandQueue(new CommandQueueDescription(CommandListType.Copy));
NativeDirectCommandQueue = NativeDevice.CreateCommandQueue(new CommandQueueDescription(CommandListType.Direct));
ComputeAllocatorPool = new CommandAllocatorPool(this, CommandListType.Compute);
CopyAllocatorPool = new CommandAllocatorPool(this, CommandListType.Copy);
DirectAllocatorPool = new CommandAllocatorPool(this, CommandListType.Direct);
NativeComputeFence = NativeDevice.CreateFence(0);
NativeCopyFence = NativeDevice.CreateFence(0);
NativeDirectFence = NativeDevice.CreateFence(0);
ShaderResourceViewAllocator = new DescriptorAllocator(NativeDevice);
}
/// <summary>
/// Gets the name of the current <see cref="GraphicsDevice"/> instance
/// </summary>
public string Name { get; }
/// <summary>
/// Gets the size of the dedicated video memory for the current <see cref="GraphicsDevice"/> instance
/// </summary>
public long MemorySize { get; }
/// <summary>
/// Gets the number of total lanes on the current device (eg. CUDA cores on an nVidia GPU)
/// </summary>
public int ComputeUnits { get; }
/// <summary>
/// Gets the number of lanes in a SIMD wave on the current device (also known as "wavefront size" or "warp width")
/// </summary>
public int WavefrontSize { get; }
/// <summary>
/// Gets the <see cref="ID3D12Device"/> object wrapped by the current instance
/// </summary>
internal ID3D12Device NativeDevice { get; }
/// <summary>
/// Gets the <see cref="DescriptorAllocator"/> object for the current instance, used when allocating new buffers
/// </summary>
internal DescriptorAllocator ShaderResourceViewAllocator { get; set; }
/// <summary>
/// Gets the <see cref="CommandAllocatorPool"/> instance for compute operations
/// </summary>
internal CommandAllocatorPool ComputeAllocatorPool { get; }
/// <summary>
/// Gets the <see cref="CommandAllocatorPool"/> instance for copy operations
/// </summary>
internal CommandAllocatorPool CopyAllocatorPool { get; }
/// <summary>
/// Gets the <see cref="CommandAllocatorPool"/> instance for direct operations
/// </summary>
internal CommandAllocatorPool DirectAllocatorPool { get; }
/// <summary>
/// Gets the <see cref="ID3D12Fence"/> instance used for compute operations
/// </summary>
internal ID3D12Fence NativeComputeFence { get; }
/// <summary>
/// Gets the <see cref="ID3D12Fence"/> instance used for copy operations
/// </summary>
internal ID3D12Fence NativeCopyFence { get; }
/// <summary>
/// Gets the <see cref="ID3D12Fence"/> instance used for direct operations
/// </summary>
internal ID3D12Fence NativeDirectFence { get; }
/// <summary>
/// Gets the next fence value for compute operations
/// </summary>
internal long NextComputeFenceValue { get; private set; } = 1;
/// <summary>
/// Gets the next fence value for copy operations
/// </summary>
internal long NextCopyFenceValue { get; private set; } = 1;
/// <summary>
/// Gets the next fence value for direct operations
/// </summary>
internal long NextDirectFenceValue { get; private set; } = 1;
/// <summary>
/// Creates a <see cref="ID3D12RootSignature"/> instance from a description
/// </summary>
/// <param name="rootSignatureDescription">A <see cref="VersionedRootSignatureDescription"/> instance with the info for the new <see cref="ID3D12RootSignature"/> object to create</param>
/// <returns>A new <see cref="ID3D12RootSignature"/> instance to use in a compute shader</returns>
internal ID3D12RootSignature CreateRootSignature(VersionedRootSignatureDescription rootSignatureDescription)
{
return NativeDevice.CreateRootSignature(0, rootSignatureDescription);
}
/// <summary>
/// Executes a <see cref="CommandList"/> and waits for the GPU to finish processing it
/// </summary>
/// <param name="commandList">The input <see cref="CommandList"/> to execute</param>
internal void ExecuteCommandList(CommandList commandList)
{
ID3D12Fence fence = commandList.CommandListType switch
{
CommandListType.Direct => NativeDirectFence,
CommandListType.Compute => NativeComputeFence,
CommandListType.Copy => NativeCopyFence,
_ => throw new NotSupportedException("This command list type is not supported.")
};
long fenceValue = GetFenceValueForCommandList(commandList);
if (fenceValue <= fence.CompletedValue) return;
fence.SetEventOnCompletion(fenceValue, default(IntPtr));
}
/// <summary>
/// Executes a <see cref="CommandList"/> and, signals and retrieves the following fence value
/// </summary>
/// <param name="commandList">The input <see cref="CommandList"/> to execute</param>
/// <returns>The value of the new fence to wait for</returns>
private long GetFenceValueForCommandList(CommandList commandList)
{
CommandAllocatorPool commandAllocatorPool;
ID3D12CommandQueue commandQueue;
ID3D12Fence fence;
long fenceValue;
switch (commandList.CommandListType)
{
case CommandListType.Compute:
commandAllocatorPool = ComputeAllocatorPool;
commandQueue = NativeComputeCommandQueue;
fence = NativeComputeFence;
fenceValue = NextComputeFenceValue++;
break;
case CommandListType.Copy:
commandAllocatorPool = CopyAllocatorPool;
commandQueue = NativeCopyCommandQueue;
fence = NativeCopyFence;
fenceValue = NextCopyFenceValue++;
break;
case CommandListType.Direct:
commandAllocatorPool = DirectAllocatorPool;
commandQueue = NativeDirectCommandQueue;
fence = NativeDirectFence;
fenceValue = NextDirectFenceValue++;
break;
default: throw new NotSupportedException($"Unsupported command list of type {commandList.CommandListType}");
}
commandAllocatorPool.Enqueue(commandList.CommandAllocator, fenceValue);
commandQueue.ExecuteCommandLists(commandList.NativeCommandList);
commandQueue.Signal(fence, fenceValue);
return fenceValue;
}
/// <inheritdoc/>
public void Dispose()
{
NativeDirectCommandQueue.Signal(NativeDirectFence, NextDirectFenceValue);
NativeDirectCommandQueue.Wait(NativeDirectFence, NextDirectFenceValue);
ShaderResourceViewAllocator.Dispose();
ComputeAllocatorPool.Dispose();
CopyAllocatorPool.Dispose();
DirectAllocatorPool.Dispose();
NativeComputeCommandQueue.Dispose();
NativeCopyCommandQueue.Dispose();
NativeDirectCommandQueue.Dispose();
NativeComputeFence.Dispose();
NativeDirectFence.Dispose();
NativeDirectFence.Dispose();
NativeDevice.Dispose();
}
}
}
-47
ファイルの表示
@@ -1,47 +0,0 @@
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using Vortice.Direct3D;
using Vortice.Direct3D12;
using Vortice.DXGI;
namespace ComputeSharp.Graphics.Helpers
{
/// <summary>
/// A <see langword="class"/> with methods to inspect the available devices on the current machine
/// </summary>
internal static class DeviceHelper
{
/// <summary>
/// Gets a collection of all the supported devices on the current machine
/// </summary>
/// <returns>The collection of <see cref="ID3D12Device"/> objects with support for DX12.1</returns>
[Pure]
public static IReadOnlyList<(ID3D12Device, AdapterDescription)> QueryAllSupportedDevices()
{
if (!DXGI.CreateDXGIFactory1(out IDXGIFactory1 factory).Success) return new (ID3D12Device, AdapterDescription)[0];
try
{
List<(ID3D12Device, AdapterDescription)> devices = new List<(ID3D12Device, AdapterDescription)>();
int i = 0;
while (factory.EnumAdapters1(i++, out IDXGIAdapter1? adapter).Success && !(adapter is null))
{
if (adapter.Description.DedicatedVideoMemory == 0) continue;
if (D3D12.D3D12CreateDevice(adapter, FeatureLevel.Level_12_0, out ID3D12Device device).Success)
{
devices.Add((device, adapter.Description));
}
}
return devices;
}
finally
{
// Explicit using statement
factory?.Dispose();
}
}
}
}
-44
ファイルの表示
@@ -1,44 +0,0 @@
using System;
using System.Runtime.CompilerServices;
namespace ComputeSharp.Graphics.Helpers
{
/// <summary>
/// A <see langword="class"/> with some helper methods to copy data between memory areas
/// </summary>
internal static class MemoryHelper
{
/// <summary>
/// Copies the content of a <see cref="ReadOnlySpan{T}"/> to the area pointed by an input <see cref="IntPtr"/> value
/// </summary>
/// <typeparam name="T">The type of values in the input <see cref="ReadOnlySpan{T}"/></typeparam>
/// <param name="source">The source <see cref="ReadOnlySpan{T}"/> to read</param>
/// <param name="destination">The <see cref="IntPtr"/> for the destination memory area</param>
/// <param name="destinationOffset">The destination offset to start writing data to</param>
/// <param name="count">The total number of items to copy</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void Copy<T>(ReadOnlySpan<T> source, IntPtr destination, int destinationOffset, int count) where T : unmanaged
{
T* p = (T*)destination.ToPointer() + destinationOffset;
source.CopyTo(new Span<T>(p, count));
}
/// <summary>
/// Copies a memory area pointed by an <see cref="IntPtr"/> value to a target <see cref="Span{T}"/>
/// </summary>
/// <typeparam name="T">The type of values to read</typeparam>
/// <param name="source">The <see cref="IntPtr"/> that indicates the memory area to read from</param>
/// <param name="sourceOffset">The source offset to start reading data from</param>
/// <param name="destination">The destination <see cref="Span{T}"/> to write</param>
/// <param name="destinationOffset">The destination offset to start writing data to</param>
/// <param name="count">The total number of items to copy</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void Copy<T>(IntPtr source, int sourceOffset, Span<T> destination, int destinationOffset, int count) where T : unmanaged
{
ref T rin = ref Unsafe.AsRef<T>(source.ToPointer());
void* target = Unsafe.AsPointer(ref Unsafe.Add(ref rin, sourceOffset));
new Span<T>(target, count).CopyTo(destination.Slice(destinationOffset, count));
}
}
}
-6
ファイルの表示
@@ -1,6 +0,0 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("ComputeSharp")]
[assembly: InternalsVisibleTo("ComputeSharp.Shaders")]
[assembly: InternalsVisibleTo("ComputeSharp.Tests.Internals")]
+34
ファイルの表示
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.Build.NoTargets/2.0.1" DefaultTargets="Pack">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<PackageId>ComputeSharp</PackageId>
<Title>ComputeSharp</Title>
<Description>A library to run C# code in parallel on the GPU through DX12 and dynamically generated HLSL compute shaders</Description>
<PackageVersion>2.0.0</PackageVersion>
<RepositoryUrl>https://github.com/Sergio0694/ComputeSharp.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<ProjectUrl>https://github.com/Sergio0694/ComputeSharp</ProjectUrl>
<Authors>Sergio Pedri</Authors>
<Owners>Sergio Pedri</Owners>
<Copyright>Copyright (c) 2021 Sergio Pedri</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageIcon>icon.png</PackageIcon>
<PackageIconUrl>https://user-images.githubusercontent.com/10199417/110238403-b8811080-7f41-11eb-8cfe-e47e7e58f05b.png</PackageIconUrl>
<PackageTags>dotnet net netcore netstandard csharp library graphics shader hlsl compute gpu performance parallel</PackageTags>
</PropertyGroup>
<ItemGroup>
<Content Include="icon.png" PackFolder="\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ComputeSharp\ComputeSharp.csproj" />
<ProjectReference Include="..\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj" />
</ItemGroup>
</Project>
バイナリ
ファイルの表示
バイナリファイルは表示されません。

変更後

幅:  |  高さ:  |  サイズ: 1.5 KiB

-26
ファイルの表示
@@ -1,26 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ICSharpCode.Decompiler" Version="5.0.2.5153" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.7.0" />
<PackageReference Include="Stubble.Core" Version="1.9.3" />
<PackageReference Include="Vortice.Dxc" Version="1.8.6" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ComputeSharp.Graphics\ComputeSharp.Graphics.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Renderer\Templates\ShaderTemplate.mustache">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
</Project>
-31
ファイルの表示
@@ -1,31 +0,0 @@
using System;
using System.Diagnostics.Contracts;
using System.Text;
namespace ComputeSharp.Exceptions
{
/// <summary>
/// A custom <see cref="GraphicsDeviceMismatchException"/> that indicates when mismatched devices are being used
/// </summary>
public sealed class HlslCompilationException : Exception
{
/// <summary>
/// Creates a new <see cref="GraphicsDeviceMismatchException"/> instance
/// </summary>
/// <param name="error">The error message produced by the Dxc compiler</param>
internal HlslCompilationException(string error) : base(GetExceptionMessage(error)) { }
// Gets a proper exception message for a given compilation error
[Pure]
private static string GetExceptionMessage(string error)
{
StringBuilder builder = new StringBuilder();
builder.Append("The Dxc compiler encountered an error while trying to compile the shader.");
builder.AppendLine("Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp.");
builder.AppendLine("If you're sure that your C# shader code is valid, please open an issue an include a working repro and the following error message:");
builder.AppendLine(error.TrimEnd());
return builder.ToString();
}
}
}
-63
ファイルの表示
@@ -1,63 +0,0 @@
using System.Diagnostics.Contracts;
using System.Linq;
using System.Threading;
namespace System.Reflection.Emit
{
/// <summary>
/// A <see langword="class"/> that can be used to easily (lol) create dynamic methods
/// </summary>
/// <typeparam name="T">The type of <see cref="Delegate"/> that will be used to wrap the new methods</typeparam>
internal static class DynamicMethod<T> where T : Delegate
{
/// <summary>
/// The owner type for new dynamic methods
/// </summary>
private static readonly Type OwnerType = typeof(DynamicMethod<T>);
/// <summary>
/// The return type of the <typeparamref name="T"/> <see langword="delegate"/>
/// </summary>
private static readonly Type ReturnType;
/// <summary>
/// The types of the arguments of the <typeparamref name="T"/> <see langword="delegate"/>
/// </summary>
private static readonly Type[] ParameterTypes;
/// <summary>
/// Loads all the necessary <see cref="Type"/> info for the current <typeparamref name="T"/> parameter
/// </summary>
static DynamicMethod()
{
MethodInfo method = typeof(T).GetMethod("Invoke");
ReturnType = method.ReturnType;
ParameterTypes = method.GetParameters().Select(p => p.ParameterType).ToArray();
}
/// <summary>
/// Local counter for dynamic methods of type <typeparamref name="T"/> ever generated
/// </summary>
private static int _Count;
/// <summary>
/// Creates a new <typeparamref name="T"/> <see langword="delegate"/> for the target owner
/// </summary>
/// <param name="builder">An <see cref="Action"/> that builds the IL bytecode for the new method</param>
/// <returns>A new dynamic method wrapped as a <typeparamref name="T"/> <see langword="delegate"/></returns>
[Pure]
public static T New(Action<ILGenerator> builder)
{
// Create a new dynamic method with a unique id
string id = $"__IL__{typeof(T).Name}_{Interlocked.Increment(ref _Count)}";
DynamicMethod method = new DynamicMethod(id, ReturnType, ParameterTypes, OwnerType);
// Build the IL bytecode
ILGenerator il = method.GetILGenerator();
builder(il);
// Build and delegate instance
return (T)method.CreateDelegate(typeof(T));
}
}
}
-103
ファイルの表示
@@ -1,103 +0,0 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace System.Reflection.Emit
{
/// <summary>
/// A <see langword="class"/> that provides extension methods for the <see langword="ILGenerator"/> type
/// </summary>
internal static class ILGeneratorExtensions
{
/// <summary>
/// Puts the appropriate <see langword="ldsfld"/>, <see langword="ldfld"/>, <see langword="call"/> or <see langword="callvirt"/> instruction to read a member onte the stream of instructions
/// </summary>
/// <param name="il">The input <see cref="ILGenerator"/> instance to use to emit instructions</param>
/// <param name="member">The member to read</param>
public static void EmitReadMember(this ILGenerator il, MemberInfo member)
{
switch (member)
{
case FieldInfo field:
il.Emit(field.IsStatic ? OpCodes.Ldsfld : OpCodes.Ldfld, field);
break;
case PropertyInfo property when property.CanRead:
il.EmitCall(property.GetMethod.IsStatic ? OpCodes.Call : OpCodes.Callvirt, property.GetMethod, null);
break;
default: throw new ArgumentException($"The input {member.GetType()} instance can't be read");
}
}
/// <summary>
/// Puts the appropriate <see langword="ldc.i4"/>, <see langword="conv.i"/> and <see langword="add"/> instructions to advance a reference onto the stream of instructions
/// </summary>
/// <typeparam name="T">The type of reference at the top of the stack</typeparam>
/// <param name="il">The input <see cref="ILGenerator"/> instance to use to emit instructions</param>
/// <param name="offset">The offset to use to advance the current reference on top of the execution stack</param>
public static void EmitAddOffset<T>(this ILGenerator il, int offset) => il.EmitAddOffset(Unsafe.SizeOf<T>() * offset);
/// <summary>
/// Puts the appropriate <see langword="ldc.i4"/>, <see langword="conv.i"/> and <see langword="add"/> instructions to advance a reference onto the stream of instructions
/// </summary>
/// <param name="il">The input <see cref="ILGenerator"/> instance to use to emit instructions</param>
/// <param name="offset">The offset in bytes to use to advance the current reference on top of the execution stack</param>
public static void EmitAddOffset(this ILGenerator il, int offset)
{
// Push the offset to the stack
if (offset < -128) il.Emit(OpCodes.Ldc_I4, offset);
else if (offset < 0) il.Emit(OpCodes.Ldc_I4_S, (sbyte)offset);
else if (offset <= 8)
{
il.Emit(offset switch
{
0 => OpCodes.Ldc_I4_0,
1 => OpCodes.Ldc_I4_1,
2 => OpCodes.Ldc_I4_2,
3 => OpCodes.Ldc_I4_3,
4 => OpCodes.Ldc_I4_4,
5 => OpCodes.Ldc_I4_5,
6 => OpCodes.Ldc_I4_6,
7 => OpCodes.Ldc_I4_7,
8 => OpCodes.Ldc_I4_8,
_ => throw new InvalidOperationException($"Invalid offset value [{offset}]")
});
}
else if (offset <= 127) il.Emit(OpCodes.Ldc_I4_S, (byte)offset);
else il.Emit(OpCodes.Ldc_I4, offset);
// Converts the offset to native int and adds to the address
il.Emit(OpCodes.Conv_I);
il.Emit(OpCodes.Add);
}
/// <summary>
/// Puts the appropriate <see langword="stind"/> or <see langword="stobj"/> instruction to write to a reference onto the stream of instructions
/// </summary>
/// <param name="il">The input <see cref="ILGenerator"/> instance to use to emit instructions</param>
/// <param name="type">The type of value being written to the current reference on top of the execution stack</param>
public static void EmitStoreToAddress(this ILGenerator il, Type type)
{
if (type.IsValueType)
{
// Pick the optimal opcode to set a value type
OpCode opcode = Marshal.SizeOf(type) switch
{
// Use the faster op codes for sizes <= 8
1 when type == typeof(bool) || type == typeof(byte) || type == typeof(sbyte) => OpCodes.Stind_I1,
2 when type == typeof(short) || type == typeof(ushort) => OpCodes.Stind_I2,
4 when type == typeof(float) => OpCodes.Stind_R4,
4 when type == typeof(int) || type == typeof(uint) => OpCodes.Stind_I4,
8 when type == typeof(double) => OpCodes.Stind_R8,
8 when type == typeof(long) || type == typeof(ulong) => OpCodes.Stind_I8,
// Default to stobj for all other value types
_ => OpCodes.Stobj
};
// Also pass the type token if stobj is used
if (opcode == OpCodes.Stobj) il.Emit(opcode, type);
else il.Emit(opcode);
}
else il.Emit(OpCodes.Stind_Ref);
}
}
}
-27
ファイルの表示
@@ -1,27 +0,0 @@
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text.RegularExpressions;
namespace System
{
/// <summary>
/// A <see langword="class"/> that provides extension methods for the <see langword="string"/> type
/// </summary>
internal static class StringExtensions
{
/// <summary>
/// Removes the left padding for an input multiline <see langword="string"/>
/// </summary>
/// <param name="text">The input <see langword="string"/> to process</param>
/// <returns>A left-aligned <see langword="string"/> with the same text as the input</returns>
[Pure]
public static string RemoveLeftPadding(this string text)
{
string[] lines = text.Split(Environment.NewLine);
int spaces = text.TakeWhile(c => c == ' ').Count();
Regex regex = new Regex($"^{new string(Enumerable.Repeat(' ', spaces).ToArray())}");
return lines.Aggregate(string.Empty, (result, line) => $"{result}{Environment.NewLine}{regex.Replace(line, string.Empty)}");
}
}
}
-277
ファイルの表示
@@ -1,277 +0,0 @@
using System;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
using System.Reflection;
using ComputeSharp;
using ComputeSharp.Shaders.Mappings;
using ComputeSharp.Shaders.Translation.Models;
namespace Microsoft.CodeAnalysis.CSharp.Syntax
{
/// <summary>
/// A <see langword="class"/> with some extension methods for C# syntax nodes
/// </summary>
internal static class SyntaxNodeExtensions
{
/// <summary>
/// Checks a <see cref="SyntaxNode"/> value and replaces the value type to be HLSL compatible, if needed
/// </summary>
/// <typeparam name="TRoot">The type of the input <see cref="SyntaxNode"/> instance</typeparam>
/// <param name="node">The input <see cref="SyntaxNode"/> to check and modify if needed</param>
/// <param name="type">The <see cref="TypeSyntax"/> to use for the input node</param>
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL</returns>
[Pure]
public static TRoot ReplaceType<TRoot>(this TRoot node, TypeSyntax type) where TRoot : SyntaxNode
{
string value = HlslKnownTypes.GetMappedName(type.ToString());
// If the HLSL mapped full type name equals the original type, just return the input node
if (value == type.ToString()) return node;
// Process and return the type name
TypeSyntax newType = SyntaxFactory.ParseTypeName(value).WithLeadingTrivia(type.GetLeadingTrivia()).WithTrailingTrivia(type.GetTrailingTrivia());
return node.ReplaceNode(type, newType);
}
/// <summary>
/// Checks a <see cref="MemberAccessExpressionSyntax"/> instance and replaces it to be HLSL compatible, if needed
/// </summary>
/// <param name="node">The input <see cref="MemberAccessExpressionSyntax"/> to check and modify if needed</param>
/// <param name="semanticModel">The <see cref="SemanticModel"/> to use to load symbols for the input node</param>
/// <param name="variable">The info on parsed static members, if any</param>
/// <param name="method">The info on parsed static methods, if any</param>
/// <returns>A <see cref="SyntaxNode"/> instance that is compatible with HLSL</returns>
[Pure]
public static SyntaxNode ReplaceMember(this MemberAccessExpressionSyntax node, SemanticModel semanticModel, out (string Name, ReadableMember MemberInfo)? variable, out (string Name, MethodInfo MethodInfo)? method)
{
// Set the out parameters to null, replace them later on if needed
variable = null;
method = null;
SymbolInfo containingMemberSymbolInfo;
ISymbol? memberSymbol;
try
{
containingMemberSymbolInfo = semanticModel.GetSymbolInfo(node.Expression);
SymbolInfo memberSymbolInfo = semanticModel.GetSymbolInfo(node.Name);
memberSymbol = memberSymbolInfo.Symbol ?? memberSymbolInfo.CandidateSymbols.FirstOrDefault();
}
catch (ArgumentException)
{
// Member access on a captured HLSL-compatible field or property
string name = node.Name.ToFullString();
if (name == "X" || name == "Y" || name == "Z" || name == "W") return node.WithName(SyntaxFactory.IdentifierName(name.ToLowerInvariant()));
return node;
}
// If the input member has no symbol, try to load it manually
if (memberSymbol is null)
{
string expression = node.WithoutTrivia().ToFullString();
int index = expression.LastIndexOf(Type.Delimiter);
string fullname = expression.Substring(0, index);
if (!(AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetType(fullname)).FirstOrDefault(t => t != null) is Type type))
{
// The current node can't possibly represent a field or a property, so just return it
return node;
}
// Try to get the target static field or property, if present
string name = expression.Substring(index + 1, expression.Length - fullname.Length - 1);
MemberInfo[] memberInfos = type.GetMember(name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (memberInfos.Length == 0) return node;
bool isReadonly;
ReadableMember memberInfo;
switch (memberInfos.First())
{
case FieldInfo fieldInfo:
isReadonly = fieldInfo.IsInitOnly;
memberInfo = fieldInfo;
break;
case PropertyInfo propertyInfo:
isReadonly = !propertyInfo.CanWrite;
memberInfo = propertyInfo;
break;
case MethodInfo methodInfo:
string methodName = $"{methodInfo.DeclaringType.Name}_{methodInfo.Name}";
method = (methodName, methodInfo);
return SyntaxFactory.IdentifierName(methodName).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia());
default: throw new InvalidOperationException($"Invalid symbol kind: {memberInfos.First().GetType()}");
}
// Handle the loaded info
return ProcessStaticMember(node, memberInfo, isReadonly, ref variable);
}
// If the input member is not a field, property or method, just return it
if (memberSymbol.Kind != SymbolKind.Field &&
memberSymbol.Kind != SymbolKind.Property &&
memberSymbol.Kind != SymbolKind.Method)
{
return node;
}
// Process the input node if it's a known method invocation
if (HlslKnownMethods.TryGetMappedName(containingMemberSymbolInfo.Symbol, memberSymbol, out string? mappedName))
{
string expression = memberSymbol.IsStatic ? mappedName : $"{node.Expression}{mappedName}";
return SyntaxFactory.IdentifierName(expression).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia());
}
// Handle static members as a special case
if (memberSymbol.IsStatic && (
memberSymbol.Kind == SymbolKind.Field ||
memberSymbol.Kind == SymbolKind.Property ||
memberSymbol.Kind == SymbolKind.Method))
{
// Get the containing type
string
typeFullname = memberSymbol.ContainingType.ToString(),
assemblyFullname = memberSymbol.ContainingAssembly.ToString();
Type memberDeclaringType = Type.GetType($"{typeFullname}, {assemblyFullname}");
// Static field or property
if (memberSymbol.Kind == SymbolKind.Field || memberSymbol.Kind == SymbolKind.Property)
{
bool isReadonly;
ReadableMember memberInfo;
switch (memberSymbol.Kind)
{
case SymbolKind.Field:
FieldInfo fieldInfo = memberDeclaringType.GetField(memberSymbol.Name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
isReadonly = fieldInfo.IsInitOnly;
memberInfo = fieldInfo;
break;
case SymbolKind.Property:
PropertyInfo propertyInfo = memberDeclaringType.GetProperty(memberSymbol.Name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
isReadonly = !propertyInfo.CanWrite;
memberInfo = propertyInfo;
break;
default: throw new InvalidOperationException($"Invalid symbol kind: {memberSymbol.Kind}");
}
// Handle the loaded info
return ProcessStaticMember(node, memberInfo, isReadonly, ref variable);
}
// Static method
MethodInfo methodInfo = memberDeclaringType.GetMethod(memberSymbol.Name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
string name = $"{methodInfo.DeclaringType.Name}_{methodInfo.Name}";
method = (name, methodInfo);
return SyntaxFactory.IdentifierName(name).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia());
}
return node;
}
/// <summary>
/// Checks a <see cref="InvocationExpressionSyntax"/> instance and replaces it to be HLSL compatible, if needed
/// </summary>
/// <param name="node">The input <see cref="InvocationExpressionSyntax"/> to check and modify if needed</param>
/// <param name="declaringType">The <see cref="Type"/> in which the input syntax tree is declared in</param>
/// <param name="variable">The info on parsed static members, if any</param>
/// <param name="method">The info on parsed static methods, if any</param>
/// <returns>A <see cref="SyntaxNode"/> instance that is compatible with HLSL</returns>
[Pure]
public static InvocationExpressionSyntax ReplaceInvocation(this InvocationExpressionSyntax node, Type declaringType, out (string Name, ReadableMember MemberInfo)? variable, out (string Name, MethodInfo MethodInfo)? method)
{
// Set the variable and method to null
variable = null;
method = null;
// Explore the nested classes from bottom to top
if (declaringType.TryFindAncestorMember(node.Expression.ToString(), BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, out var result))
{
// If a static method or delegate is found, track it
string name = $"{result.Value.DeclaringType.Name}_{result.Value.MemberInfo.Name}";
switch (result.Value.MemberInfo)
{
case FieldInfo fieldInfo:
variable = (name, fieldInfo);
break;
case PropertyInfo propertyInfo:
variable = (name, propertyInfo);
break;
case MethodInfo methodInfo:
method = (name, methodInfo);
return SyntaxFactory.InvocationExpression(SyntaxFactory.ParseExpression(name), node.ArgumentList).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia());
default: throw new InvalidOperationException($"Invalid symbol kind: {result.Value.MemberInfo.GetType()}");
}
// Return the mapped expression
return SyntaxFactory.InvocationExpression(SyntaxFactory.ParseExpression(name), node.ArgumentList).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia());
}
return node;
}
/// <summary>
/// Checks a <see cref="IdentifierNameSyntax"/> instance and replaces it to be HLSL compatible, if needed
/// </summary>
/// <param name="node">The input <see cref="IdentifierNameSyntax"/> to check and modify if needed</param>
/// <param name="declaringType">The <see cref="Type"/> in which the input syntax tree is declared in</param>
/// <param name="variable">The info on parsed static members, if any</param>
/// <returns>A <see cref="SyntaxNode"/> instance that is compatible with HLSL</returns>
[Pure]
public static IdentifierNameSyntax ReplaceIdentifierName(this IdentifierNameSyntax node, Type declaringType, out (string Name, ReadableMember MemberInfo)? variable)
{
// Set the variable to null
variable = null;
// Explore the nested classes from bottom to top
if (declaringType.TryFindAncestorMember(node.Identifier.ToString(), BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, out var result))
{
// If a static scalar or vector member is found, track it
string name = $"{result.Value.DeclaringType.Name}_{result.Value.MemberInfo.Name}";
switch (result.Value.MemberInfo)
{
case FieldInfo fieldInfo when HlslKnownTypes.IsKnownType(fieldInfo.FieldType):
variable = (name, fieldInfo);
break;
case PropertyInfo propertyInfo when HlslKnownTypes.IsKnownType(propertyInfo.PropertyType):
variable = (name, propertyInfo);
break;
default: return node;
}
// Return the mapped expression
return SyntaxFactory.IdentifierName(name).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia());
}
return node;
}
/// <summary>
/// Processes a loaded static member, either a field or a property
/// </summary>
/// <param name="node">The input <see cref="MemberAccessExpressionSyntax"/> to check and modify if needed</param>
/// <param name="memberInfo">The wrapped member that needs to be processed</param>
/// <param name="isReadonly">Indicates whether or not the target member is readonly</param>
/// <param name="variable">The info on parsed static members, if any</param>
/// <returns>A <see cref="SyntaxNode"/> instance that is compatible with HLSL</returns>
private static SyntaxNode ProcessStaticMember(SyntaxNode node, ReadableMember memberInfo, bool isReadonly, ref (string Name, ReadableMember MemberInfo)? variable)
{
// Constant replacement if the value is a readonly scalar value
if (isReadonly && HlslKnownTypes.IsKnownScalarType(memberInfo.MemberType))
{
LiteralExpressionSyntax expression = memberInfo.GetValue(null) switch
{
true => SyntaxFactory.LiteralExpression(SyntaxKind.TrueLiteralExpression, SyntaxFactory.Token(SyntaxKind.TrueKeyword)),
false => SyntaxFactory.LiteralExpression(SyntaxKind.TrueLiteralExpression, SyntaxFactory.Token(SyntaxKind.FalseKeyword)),
Bool b when b => SyntaxFactory.LiteralExpression(SyntaxKind.TrueLiteralExpression, SyntaxFactory.Token(SyntaxKind.TrueKeyword)),
Bool b when !b => SyntaxFactory.LiteralExpression(SyntaxKind.TrueLiteralExpression, SyntaxFactory.Token(SyntaxKind.FalseKeyword)),
IFormattable scalar => SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.ParseToken(scalar.ToString(null, CultureInfo.InvariantCulture))),
_ => throw new InvalidOperationException($"Invalid field of type {memberInfo.MemberType}")
};
return expression.WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia());
}
// Captured member, treat it like any other captured variable in the closure
string name = $"{memberInfo.DeclaringType.Name}_{memberInfo.Name}";
variable = (name, memberInfo);
return SyntaxFactory.IdentifierName(name).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia());
}
}
}
-53
ファイルの表示
@@ -1,53 +0,0 @@
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace System
{
/// <summary>
/// A <see langword="class"/> that provides extension methods for the <see cref="Type"/> type
/// </summary>
internal static class TypeExtensions
{
/// <summary>
/// Gets whether or not the input <see cref="Type"/> represents a <see cref="Delegate"/>
/// </summary>
/// <param name="type">The input type to analyze</param>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsDelegate(this Type type) => type.IsClass &&
type.IsSubclassOf(typeof(Delegate));
/// <summary>
/// Gets whether or not the input <see cref="Type"/> represents a <see cref="Delegate"/> with no captured variables
/// </summary>
/// <param name="type">The input type to analyze</param>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsStatelessDelegateContainer(this Type type) => type.GetFields(BindingFlags.Static | BindingFlags.Public).Length > 0;
/// <summary>
/// Tries to find an ancestor member starting from the input <see cref="Type"/>
/// </summary>
/// <param name="type">The input type to start the search from</param>
/// <param name="name">The name of the member to retrieve</param>
/// <param name="bindingAttr">A bitmask comprised of one or more <see cref="BindingFlags"></see> that specify how the search is conducted</param>
/// <returns><see langword="true"/> when a member with the given name is found, <see langword="false"/> otherwise</returns>
public static bool TryFindAncestorMember(this Type type, string name, BindingFlags bindingAttr, [NotNullWhen(true)] out (Type DeclaringType, MemberInfo MemberInfo)? result)
{
while ((type = type.DeclaringType) != null)
{
MemberInfo[] memberInfos = type.GetMember(name, bindingAttr);
if (memberInfos.Length > 0)
{
result = (type, memberInfos[0]);
return true;
}
}
result = null;
return false;
}
}
}
-64
ファイルの表示
@@ -1,64 +0,0 @@
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Text.RegularExpressions;
namespace ComputeSharp.Shaders.Mappings
{
/// <summary>
/// A <see langword="class"/> that contains and maps known HLSL method names to common .NET method
/// </summary>
internal static class HlslKnownKeywords
{
/// <summary>
/// The mapping of supported known methods to HLSL methods
/// </summary>
private static readonly IReadOnlyCollection<string> KnownKeywords = new[]
{
"asm", "asm_fragment", "cbuffer", "centroid", "column_major",
"compile", "discard", "dword", "export", "fxgroup", "groupshared",
"half", "inline", "inout", "line", "lineadj", "linear", "matrix",
"nointerpolation", "noperspective", "NULL", "packoffset", "pass",
"pixelfragment", "point", "precise", "register", "row_major", "sample",
"sampler", "shared", "snorm", "stateblock", "stateblock_state", "tbuffer",
"technique", "typedef", "triangle", "triangleadj", "uniform", "unorm",
"unsigned", "vector", "vertexfragment", "zero"
};
private static Regex? _KeywordsRegex;
/// <summary>
/// The <see cref="Regex"/> to use to match variable names
/// </summary>
private static Regex KeywordsRegex
{
get
{
if (_KeywordsRegex == null)
{
string
keywords = string.Join("|", KnownKeywords),
pattern = $@"(?<![A-Za-z])(?:{keywords})(?!\w)";
_KeywordsRegex = new Regex(pattern, RegexOptions.Compiled);
}
return _KeywordsRegex;
}
}
/// <summary>
/// Gets the mapped HLSL-compatible variable name for the input identifier name
/// </summary>
/// <param name="name">The input variable name to map</param>
/// <returns>The HLSL-compatible variable name name that can be used in an HLSL shader</returns>
[Pure]
public static string GetMappedName(string name) => KeywordsRegex.IsMatch(name) ? $"_{name}" : name;
/// <summary>
/// Processes an input text and replaces all the occurrences of reserved keywords
/// </summary>
/// <param name="text">The input text to process</param>
/// <returns>A valid shader body source code that can be used in HLSL</returns>
[Pure]
public static string GetMappedText(string text) => KeywordsRegex.Replace(text, m => $"_{m.Value}");
}
}
-285
ファイルの表示
@@ -1,285 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Reflection;
using ComputeSharp.Core.Attributes;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.Shaders.Mappings
{
/// <summary>
/// A <see langword="class"/> that contains and maps known HLSL method names to common .NET method
/// </summary>
internal static class HlslKnownMethods
{
private static IReadOnlyDictionary<string, string>? _KnownMethods;
/// <summary>
/// The mapping of supported known methods to HLSL methods
/// </summary>
private static IReadOnlyDictionary<string, string> KnownMethods
{
get
{
if (_KnownMethods != null) return _KnownMethods;
// Initialize the initial mappings
Dictionary<string, string> knownMethods = new Dictionary<string, string>
{
// Math
["System.Math.Max"] = "max",
["System.Math.Min"] = "min",
["System.Math.Pow"] = "pow",
["System.Math.Sin"] = "sin",
["System.Math.Sinh"] = "sinh",
["System.Math.Asin"] = "asin",
["System.Math.Cos"] = "cos",
["System.Math.Cosh"] = "cosh",
["System.Math.Acos"] = "acos",
["System.Math.Tan"] = "tan",
["System.Math.Tanh"] = "tanh",
["System.Math.Atan"] = "atan",
["System.Math.Atan2"] = "atan2",
["System.Math.Ceiling"] = "ceil",
["System.Math.Floor"] = "floor",
["System.Math.Clamp"] = "clamp",
["System.Math.Exp"] = "exp",
["System.Math.Log"] = "log",
["System.Math.Log10"] = "log10",
["System.Math.Round"] = "round",
["System.Math.Sqrt"] = "sqrt",
["System.Math.Sign"] = "sign",
["System.Math.Truncate"] = "trunc",
["System.Math.PI"] = "3.1415926535897931",
// MathF
["System.MathF.Max"] = "max",
["System.MathF.Min"] = "min",
["System.MathF.Pow"] = "pow",
["System.MathF.Sin"] = "sin",
["System.MathF.Sinh"] = "sinh",
["System.MathF.Asin"] = "asin",
["System.MathF.Cos"] = "cos",
["System.MathF.Cosh"] = "cosh",
["System.MathF.Acos"] = "acos",
["System.MathF.Tan"] = "tan",
["System.MathF.Tanh"] = "tanh",
["System.MathF.Atan"] = "atan",
["System.MathF.Atan2"] = "atan2",
["System.MathF.Ceiling"] = "ceil",
["System.MathF.Floor"] = "floor",
["System.MathF.Clamp"] = "clamp",
["System.MathF.Exp"] = "exp",
["System.MathF.Log"] = "log",
["System.MathF.Log10"] = "log10",
["System.MathF.Round"] = "round",
["System.MathF.Sqrt"] = "sqrt",
["System.MathF.Sign"] = "sign",
["System.MathF.Truncate"] = "trunc",
["System.MathF.PI"] = "3.14159274f",
// Float
["float.IsFinite"] = "isfinite",
["float.IsInfinity"] = "isinf",
["float.IsNaN"] = "isnan",
// ThreadIds
["ComputeSharp.ThreadIds.X"] = ".x",
["ComputeSharp.ThreadIds.Y"] = ".y",
["ComputeSharp.ThreadIds.Z"] = ".z",
// Vector2
["System.Numerics.Vector2.X"] = ".x",
["System.Numerics.Vector2.Y"] = ".y",
["System.Numerics.Vector2.Dot"] = "dot",
["System.Numerics.Vector2.Lerp"] = "lerp",
["System.Numerics.Vector2.Transform"] = "mul",
["System.Numerics.Vector2.TransformNormal"] = "mul",
["System.Numerics.Vector2.Normalize"] = "normalize",
["System.Numerics.Vector2.Zero"] = "(float2)0",
["System.Numerics.Vector2.One"] = "float2(1.0f, 1.0f)",
["System.Numerics.Vector2.UnitX"] = "float2(1.0f, 0.0f)",
["System.Numerics.Vector2.UnitY"] = "float2(0.0f, 1.0f)",
// Vector3
["System.Numerics.Vector3.X"] = ".x",
["System.Numerics.Vector3.Y"] = ".y",
["System.Numerics.Vector3.Z"] = ".z",
["System.Numerics.Vector3.Cross"] = "cross",
["System.Numerics.Vector3.Dot"] = "dot",
["System.Numerics.Vector3.Lerp"] = "lerp",
["System.Numerics.Vector3.Transform"] = "mul",
["System.Numerics.Vector3.TransformNormal"] = "mul",
["System.Numerics.Vector3.Normalize"] = "normalize",
["System.Numerics.Vector3.Zero"] = "(float3)0",
["System.Numerics.Vector3.One"] = "float3(1.0f, 1.0f, 1.0f)",
["System.Numerics.Vector3.UnitX"] = "float3(1.0f, 0.0f, 0.0f)",
["System.Numerics.Vector3.UnitY"] = "float3(0.0f, 1.0f, 0.0f)",
["System.Numerics.Vector3.UnitZ"] = "float3(0.0f, 0.0f, 1.0f)",
// Vector4
["System.Numerics.Vector4.X"] = ".x",
["System.Numerics.Vector4.Y"] = ".y",
["System.Numerics.Vector4.Z"] = ".z",
["System.Numerics.Vector4.W"] = ".w",
["System.Numerics.Vector4.Lerp"] = "lerp",
["System.Numerics.Vector4.Transform"] = "mul",
["System.Numerics.Vector4.Normalize"] = "normalize",
["System.Numerics.Vector4.Zero"] = "(float4)0",
["System.Numerics.Vector4.One"] = "float4(1.0f, 1.0f, 1.0f, 1.0f)",
// Bool2
["ComputeSharp.Bool2.False"] = "(bool2)0",
["ComputeSharp.Bool2.True"] = "bool2(true, true)",
["ComputeSharp.Bool2.TrueX"] = "bool2(true, false)",
["ComputeSharp.Bool2.TrueY"] = "bool2(false, true)",
// Bool3
["ComputeSharp.Bool3.False"] = "(bool3)0",
["ComputeSharp.Bool3.True"] = "bool3(true, true, true)",
["ComputeSharp.Bool3.TrueX"] = "bool3(true, false, false)",
["ComputeSharp.Bool3.TrueY"] = "bool3(false, true, false)",
["ComputeSharp.Bool3.TrueZ"] = "bool3(false, false, true)",
// Bool4
["ComputeSharp.Bool4.False"] = "(bool4)0",
["ComputeSharp.Bool4.True"] = "bool4(true, true, true, true)",
["ComputeSharp.Bool4.TrueX"] = "bool4(true, false, false, false)",
["ComputeSharp.Bool4.TrueY"] = "bool4(false, true, false, false)",
["ComputeSharp.Bool4.TrueZ"] = "bool4(false, false, true, false)",
["ComputeSharp.Bool4.TrueW"] = "bool4(false, false, false, true)",
// Int2
["ComputeSharp.Int2.Zero"] = "(int2)0",
["ComputeSharp.Int2.One"] = "int2(1, 1)",
["ComputeSharp.Int2.UnitX"] = "int2(1, 0)",
["ComputeSharp.Int2.UnitY"] = "int2(0, 1)",
// Int3
["ComputeSharp.Int3.Zero"] = "(int3)0",
["ComputeSharp.Int3.One"] = "int3(1, 1, 1)",
["ComputeSharp.Int3.UnitX"] = "int3(1, 0, 0)",
["ComputeSharp.Int3.UnitY"] = "int3(0, 1, 0)",
["ComputeSharp.Int3.UnitZ"] = "int3(0, 0, 1)",
// Int4
["ComputeSharp.Int4.Zero"] = "(int4)0",
["ComputeSharp.Int4.One"] = "int4(1, 1, 1, 1)",
["ComputeSharp.Int4.UnitX"] = "int4(1, 0, 0, 0)",
["ComputeSharp.Int4.UnitY"] = "int4(0, 1, 0, 0)",
["ComputeSharp.Int4.UnitZ"] = "int4(0, 0, 1, 0)",
["ComputeSharp.Int4.UnitW"] = "int4(0, 0, 0, 1)",
// UInt2
["ComputeSharp.UInt2.Zero"] = "(uint2)0",
["ComputeSharp.UInt2.One"] = "uint2(1u, 1u)",
["ComputeSharp.UInt2.UnitX"] = "uint2(1u, 0u)",
["ComputeSharp.UInt2.UnitY"] = "uint2(0u, 1u)",
// UInt3
["ComputeSharp.UInt3.Zero"] = "(uint3)0",
["ComputeSharp.UInt3.One"] = "uint3(1u, 1u, 1u)",
["ComputeSharp.UInt3.UnitX"] = "uint3(1u, 0u, 0u)",
["ComputeSharp.UInt3.UnitY"] = "uint3(0u, 1u, 0u)",
["ComputeSharp.UInt3.UnitZ"] = "uint3(0u, 0u, 1u)",
// UInt4
["ComputeSharp.UInt4.Zero"] = "(uint4)0",
["ComputeSharp.UInt4.One"] = "uint4(1u, 1u, 1u, 1u)",
["ComputeSharp.UInt4.UnitX"] = "uint4(1u, 0u, 0u, 0u)",
["ComputeSharp.UInt4.UnitY"] = "uint4(0u, 1u, 0u, 0u)",
["ComputeSharp.UInt4.UnitZ"] = "uint4(0u, 0u, 1u, 0u)",
["ComputeSharp.UInt4.UnitW"] = "uint4(0u, 0u, 0u, 1u)",
// Float2
["ComputeSharp.Float2.Zero"] = "(float2)0",
["ComputeSharp.Float2.One"] = "float2(1.0f, 1.0f)",
["ComputeSharp.Float2.UnitX"] = "float2(1.0f, 0.0f)",
["ComputeSharp.Float2.UnitY"] = "float2(0.0f, 1.0f)",
// Float3
["ComputeSharp.Float3.Zero"] = "(float3)0",
["ComputeSharp.Float3.One"] = "float3(1.0f, 1.0f, 1.0f)",
["ComputeSharp.Float3.UnitX"] = "float3(1.0f, 0.0f, 0.0f)",
["ComputeSharp.Float3.UnitY"] = "float3(0.0f, 1.0f, 0.0f)",
["ComputeSharp.Float3.UnitZ"] = "float3(0.0f, 0.0f, 1.0f)",
// Float4
["ComputeSharp.Float4.Zero"] = "(float4)0",
["ComputeSharp.Float4.One"] = "float4(1.0f, 1.0f, 1.0f, 1.0f)",
["ComputeSharp.Float4.UnitX"] = "float4(1.0f, 0.0f, 0.0f, 0.0f)",
["ComputeSharp.Float4.UnitY"] = "float4(0.0f, 1.0f, 0.0f, 0.0f)",
["ComputeSharp.Float4.UnitZ"] = "float4(0.0f, 0.0f, 1.0f, 0.0f)",
["ComputeSharp.Float4.UnitW"] = "float4(0.0f, 0.0f, 0.0f, 1.0f)",
// Double2
["ComputeSharp.Double2.Zero"] = "(double2)0",
["ComputeSharp.Double2.One"] = "double2(1.0, 1.0)",
["ComputeSharp.Double2.UnitX"] = "double2(1.0, 0.0)",
["ComputeSharp.Double2.UnitY"] = "double2(0.0, 1.0)",
// Double3
["ComputeSharp.Double3.Zero"] = "(double3)0",
["ComputeSharp.Double3.One"] = "double3(1.0, 1.0, 1.0)",
["ComputeSharp.Double3.UnitX"] = "double3(1.0, 0.0, 0.0)",
["ComputeSharp.Double3.UnitY"] = "double3(0.0, 1.0, 0.0)",
["ComputeSharp.Double3.UnitZ"] = "double3(0.0, 0.0, 1.0)",
// Double4
["ComputeSharp.Double4.Zero"] = "(double4)0",
["ComputeSharp.Double4.One"] = "double4(1.0, 1.0, 1.0, 1.0)",
["ComputeSharp.Double4.UnitX"] = "double4(1.0, 0.0, 0.0, 0.0)",
["ComputeSharp.Double4.UnitY"] = "double4(0.0, 1.0, 0.0, 0.0)",
["ComputeSharp.Double4.UnitZ"] = "double4(0.0, 0.0, 1.0, 0.0)",
["ComputeSharp.Double4.UnitW"] = "double4(0.0, 0.0, 0.0, 1.0)"
};
// Programmatically load mappings from the Hlsl class as well
foreach (var method in
from method in typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static)
group method by method.Name
into groups
select (Name: groups.Key, MethodInfo: groups.First()))
{
// Check whether the current method should be translated with the original name
// or with the lowercase version. This is needed because all C# methods are exposed
// with the upper camel case format, while HLSL intrinsics use multiple different formats.
string hlslName = method.MethodInfo.GetCustomAttribute<PreserveMemberNameAttribute>() != null
? method.Name
: method.Name.ToLowerInvariant();
knownMethods.Add($"{typeof(Hlsl).FullName}{Type.Delimiter}{method.Name}", hlslName);
}
// Programmatically load mappings for the vector types
foreach (var item in
from type in HlslKnownTypes.HlslMappedVectorTypes
from property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
select (Type: type, Property: property))
{
knownMethods.Add($"{item.Type.FullName}{Type.Delimiter}{item.Property.Name}", $".{item.Property.Name.ToLowerInvariant()}");
}
return _KnownMethods = knownMethods;
}
}
/// <summary>
/// Tries to get the mapped HLSL-compatible mthod name for the input symbols
/// </summary>
/// <param name="containingMemberSymbol">The containing member symbol for the method to check</param>
/// <param name="memberSymbol">The symbol for the method to check</param>
/// <param name="mapped">The mapped name, if one is found</param>
/// <returns>The HLSL-compatible method name that can be used in an HLSL shader</returns>
[Pure]
public static bool TryGetMappedName(ISymbol containingMemberSymbol, ISymbol memberSymbol, [NotNullWhen(true)] out string? mapped)
{
string fullTypeName = containingMemberSymbol.IsStatic ? containingMemberSymbol.ToString() : memberSymbol.ContainingType.ToString();
// Check if the target method is a known method
return KnownMethods.TryGetValue($"{fullTypeName}{Type.Delimiter}{memberSymbol.Name}", out mapped);
}
}
}
-169
ファイルの表示
@@ -1,169 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Numerics;
using System.Text.RegularExpressions;
namespace ComputeSharp.Shaders.Mappings
{
/// <summary>
/// A <see langword="class"/> that contains and maps known HLSL type names to common .NET types
/// </summary>
internal static class HlslKnownTypes
{
/// <summary>
/// The mapping of supported known types to HLSL types
/// </summary>
private static readonly IReadOnlyDictionary<string, string> KnownTypes = new Dictionary<string, string>
{
[typeof(bool).FullName] = "bool",
[typeof(Bool).FullName] = "bool",
[typeof(Bool2).FullName] = "bool2",
[typeof(Bool3).FullName] = "bool3",
[typeof(Bool4).FullName] = "bool4",
[typeof(int).FullName] = "int",
[typeof(Int2).FullName] = "int2",
[typeof(Int3).FullName] = "int3",
[typeof(Int4).FullName] = "int4",
[typeof(uint).FullName] = "uint",
[typeof(UInt2).FullName] = "uint2",
[typeof(UInt3).FullName] = "uint3",
[typeof(UInt4).FullName] = "uint4",
[typeof(float).FullName] = "float",
[typeof(Float2).FullName] = "float2",
[typeof(Float3).FullName] = "float3",
[typeof(Float4).FullName] = "float4",
[typeof(Vector2).FullName] = "float2",
[typeof(Vector3).FullName] = "float3",
[typeof(Vector4).FullName] = "float4",
[typeof(double).FullName] = "double",
[typeof(Double2).FullName] = "double2",
[typeof(Double3).FullName] = "double3",
[typeof(Double4).FullName] = "double4",
[typeof(ThreadIds).FullName] = "uint3",
[typeof(ReadOnlyBuffer<>).FullName] = "StructuredBuffer",
[typeof(ReadWriteBuffer<>).FullName] = "RWStructuredBuffer"
};
private static HashSet<Type> _HlslMappedVectorTypes { get; } = new HashSet<Type>(new[]
{
typeof(Bool2), typeof(Bool3), typeof(Bool4),
typeof(Int2), typeof(Int3), typeof(Int4),
typeof(UInt2), typeof(UInt3), typeof(UInt4),
typeof(Float2), typeof(Float3), typeof(Float4),
typeof(Double2), typeof(Double3), typeof(Double4)
});
/// <summary>
/// Gets the known HLSL vector types available as mapped types
/// </summary>
public static IReadOnlyCollection<Type> HlslMappedVectorTypes => _HlslMappedVectorTypes;
/// <summary>
/// Checks whether or not the input type is a known HLSL-compatible type
/// </summary>
/// <param name="type">The input <see cref="Type"/> instance to check</param>
/// <returns>A <see langword="bool"/> indicating whether the input <see cref="Type"/> is in fact a known HLSL type</returns>
[Pure]
public static bool IsKnownType(Type type) => IsKnownScalarType(type) ||
IsKnownVectorType(type) ||
IsConstantBufferType(type) ||
IsReadOnlyBufferType(type) ||
IsReadWriteBufferType(type);
/// <summary>
/// Checks whether or not the input type is a known scalar type
/// </summary>
/// <param name="type">The input <see cref="Type"/> instance to check</param>
/// <returns>A <see langword="bool"/> indicating whether the input <see cref="Type"/> is in fact a known HLSL scalar type</returns>
[Pure]
public static bool IsKnownScalarType(Type type) => type == typeof(bool) ||
type == typeof(Bool) ||
type == typeof(int) ||
type == typeof(uint) ||
type == typeof(float) ||
type == typeof(double);
/// <summary>
/// Checks whether or not the input type is a known vector type
/// </summary>
/// <param name="type">The input <see cref="Type"/> instance to check</param>
/// <returns>A <see langword="bool"/> indicating whether the input <see cref="Type"/> is in fact a known HLSL vector type</returns>
[Pure]
public static bool IsKnownVectorType(Type type) => _HlslMappedVectorTypes.Contains(type) ||
type == typeof(Vector2) ||
type == typeof(Vector3) ||
type == typeof(Vector4);
/// <summary>
/// Checks whether or not the input type is a known buffer type
/// </summary>
/// <param name="type">The input <see cref="Type"/> instance to check</param>
/// <returns>A <see langword="bool"/> indicating whether the input <see cref="Type"/> is in fact a known buffer type</returns>
[Pure]
public static bool IsKnownBufferType(Type type) => IsConstantBufferType(type) ||
IsReadOnlyBufferType(type) ||
IsReadWriteBufferType(type);
/// <summary>
/// Checks whether or not the input type is a <see cref="ConstantBuffer{T}"/> value
/// </summary>
/// <param name="type">The input <see cref="Type"/> instance to check</param>
/// <returns>A <see langword="bool"/> indicating whether the input <see cref="Type"/> is in fact a <see cref="ConstantBuffer{T}"/> instance</returns>
[Pure]
public static bool IsConstantBufferType(Type type) => type.IsGenericType &&
type.GetGenericTypeDefinition() == typeof(ConstantBuffer<>);
/// <summary>
/// Checks whether or not the input type is a <see cref="ReadOnlyBuffer{T}"/> value
/// </summary>
/// <param name="type">The input <see cref="Type"/> instance to check</param>
/// <returns>A <see langword="bool"/> indicating whether the input <see cref="Type"/> is in fact a <see cref="ReadOnlyBuffer{T}"/> instance</returns>
[Pure]
public static bool IsReadOnlyBufferType(Type type) => type.IsGenericType &&
type.GetGenericTypeDefinition() == typeof(ReadOnlyBuffer<>);
/// <summary>
/// Checks whether or not the input type is a <see cref="ReadWriteBuffer{T}"/> value
/// </summary>
/// <param name="type">The input <see cref="Type"/> instance to check</param>
/// <returns>A <see langword="bool"/> indicating whether the input <see cref="Type"/> is in fact a <see cref="ReadWriteBuffer{T}"/> instance</returns>
[Pure]
public static bool IsReadWriteBufferType(Type type) => type.IsGenericType &&
type.GetGenericTypeDefinition() == typeof(ReadWriteBuffer<>);
/// <summary>
/// Gets the mapped HLSL-compatible type name for the input <see cref="Type"/> instance
/// </summary>
/// <param name="type">The input <see cref="Type"/> instance to map</param>
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader</returns>
[Pure]
public static string GetMappedName(Type type)
{
Type declaredType = type.IsArray ? type.GetElementType() : type;
string
fullname = $"{declaredType.Namespace}{Type.Delimiter}{declaredType.Name}",
mappedName = KnownTypes.TryGetValue(fullname, out string mapped) ? mapped : declaredType.Name,
hlslName = declaredType.IsGenericType ? mappedName + $"<{GetMappedName(declaredType.GetGenericArguments()[0])}>" : mappedName;
return hlslName;
}
/// <summary>
/// Gets the mapped HLSL-compatible type name for the input type name
/// </summary>
/// <param name="name">The input type name to map</param>
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader</returns>
[Pure]
public static string GetMappedName(string name)
{
int indexOfOpenBracket = name.IndexOf('<');
string
genericArguments = indexOfOpenBracket >= 0 ? name.Substring(indexOfOpenBracket) : string.Empty,
polishedName = indexOfOpenBracket >= 0 ? name.Remove(indexOfOpenBracket) + "`1" : name,
mappedName = KnownTypes.TryGetValue(polishedName, out string mapped) ? mapped : Regex.Match(polishedName, @"[^\.]+$").Value;
return $"{mappedName}{genericArguments}";
}
}
}
-27
ファイルの表示
@@ -1,27 +0,0 @@
using System;
namespace ComputeSharp.Shaders.Renderer.Models.Fields.Abstract
{
/// <summary>
/// A <see langword="class"/> that contains info on a shader buffer field
/// </summary>
internal abstract class HlslBufferInfo : CapturedFieldInfo
{
/// <summary>
/// Gets or sets the index of the current buffer, relative to its own type
/// </summary>
public int BufferIndex { get; set; }
/// <summary>
/// Creates a new <see cref="HlslBufferInfo"/> instance with the specified parameters
/// </summary>
/// <param name="fieldCsharpType">The type of the current field in the C# source</param>
/// <param name="fieldHlslType">The type of the current field in the HLSL shader</param>
/// <param name="fieldName">The name of the current field</param>
/// <param name="bufferIndex">The index of the current buffer field</param>
protected HlslBufferInfo(Type fieldCsharpType, string fieldHlslType, string fieldName, int bufferIndex) : base(fieldCsharpType, fieldHlslType, fieldName)
{
BufferIndex = bufferIndex;
}
}
}
-39
ファイルの表示
@@ -1,39 +0,0 @@
using ComputeSharp.Graphics.Extensions;
using System;
namespace ComputeSharp.Shaders.Renderer.Models.Fields
{
/// <summary>
/// A <see langword="class"/> that contains info on a shader field
/// </summary>
internal class CapturedFieldInfo
{
/// <summary>
/// Gets the type of the current field in the C# source
/// </summary>
public string FieldCsharpType { get; }
/// <summary>
/// Gets the type of the current field in the HLSL shader
/// </summary>
public string FieldHlslType { get; }
/// <summary>
/// Gets the name to use for the current field
/// </summary>
public string FieldName { get; }
/// <summary>
/// Creates a new <see cref="CapturedFieldInfo"/> instance with the specified parameters
/// </summary>
/// <param name="fieldCsharpType">The type of the current field in the C# source</param>
/// <param name="fieldHlslType">The type of the current field in the HLSL shader</param>
/// <param name="fieldName">The name to use for the current field</param>
public CapturedFieldInfo(Type fieldCsharpType, string fieldHlslType, string fieldName)
{
FieldCsharpType = fieldCsharpType.ToFriendlyString();
FieldHlslType = fieldHlslType;
FieldName = fieldName;
}
}
}
-26
ファイルの表示
@@ -1,26 +0,0 @@
using System;
using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
namespace ComputeSharp.Shaders.Renderer.Models.Fields
{
/// <summary>
/// A <see langword="class"/> that contains info on a constant buffer field
/// </summary>
internal sealed class ConstantBufferFieldInfo : HlslBufferInfo
{
/// <summary>
/// Gets whether or not the current <see cref="CapturedFieldInfo"/> instance represents a constant buffer (always <see langword="true"/>)
/// </summary>
public bool IsConstantBuffer { get; } = true;
/// <summary>
/// Creates a new <see cref="ConstantBufferFieldInfo"/> instance with the specified parameters
/// </summary>
/// <param name="fieldCsharpType">The type of the current field in the C# source</param>
/// <param name="fieldHlslType">The type of the current field in the HLSL shader</param>
/// <param name="fieldName">The name of the current field</param>
/// <param name="bufferIndex">The index of the current constant buffer field</param>
public ConstantBufferFieldInfo(Type fieldCsharpType, string fieldHlslType, string fieldName, int bufferIndex)
: base(fieldCsharpType, fieldHlslType, fieldName, bufferIndex) { }
}
}
-26
ファイルの表示
@@ -1,26 +0,0 @@
using System;
using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
namespace ComputeSharp.Shaders.Renderer.Models.Fields
{
/// <summary>
/// A <see langword="class"/> that contains info on a readonly buffer field
/// </summary>
internal sealed class ReadOnlyBufferFieldInfo : HlslBufferInfo
{
/// <summary>
/// Gets whether or not the current <see cref="CapturedFieldInfo"/> instance represents a readonly buffer (always <see langword="true"/>)
/// </summary>
public bool IsReadOnlyBuffer { get; } = true;
/// <summary>
/// Creates a new <see cref="ReadOnlyBufferFieldInfo"/> instance with the specified parameters
/// </summary>
/// <param name="fieldCsharpType">The type of the current field in the C# source</param>
/// <param name="fieldHlslType">The type of the current field in the HLSL shader</param>
/// <param name="fieldName">The name of the current field</param>
/// <param name="bufferIndex">The index of the current readonly buffer field</param>
public ReadOnlyBufferFieldInfo(Type fieldCsharpType, string fieldHlslType, string fieldName, int bufferIndex)
: base(fieldCsharpType, fieldHlslType, fieldName, bufferIndex) { }
}
}
-26
ファイルの表示
@@ -1,26 +0,0 @@
using System;
using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
namespace ComputeSharp.Shaders.Renderer.Models.Fields
{
/// <summary>
/// A <see langword="class"/> that contains info on a read write buffer field
/// </summary>
internal sealed class ReadWriteBufferFieldInfo : HlslBufferInfo
{
/// <summary>
/// Gets whether or not the current <see cref="CapturedFieldInfo"/> instance represents a read write buffer (always <see langword="true"/>)
/// </summary>
public bool IsReadWriteBuffer { get; } = true;
/// <summary>
/// Creates a new <see cref="ReadWriteBufferFieldInfo"/> instance with the specified parameters
/// </summary>
/// <param name="fieldCsharpType">The type of the current field in the C# source</param>
/// <param name="fieldHlslType">The type of the current field in the HLSL shader</param>
/// <param name="fieldName">The name of the current field</param>
/// <param name="bufferIndex">The index of the current read write buffer field</param>
public ReadWriteBufferFieldInfo(Type fieldCsharpType, string fieldHlslType, string fieldName, int bufferIndex)
: base(fieldCsharpType, fieldHlslType, fieldName, bufferIndex) { }
}
}
-75
ファイルの表示
@@ -1,75 +0,0 @@
using ComputeSharp.Graphics.Extensions;
using System;
using System.Collections.Generic;
namespace ComputeSharp.Shaders.Renderer.Models.Functions
{
/// <summary>
/// A <see langword="class"/> that contains info on a shader function
/// </summary>
internal sealed class FunctionInfo
{
/// <summary>
/// Gets the return type of the current function in the C# source
/// </summary>
public string FunctionCsharpReturnType { get; }
/// <summary>
/// Gets the fullname of the current function in the C# source
/// </summary>
public string FunctionFullName { get; }
/// <summary>
/// Gets the parameters of the function in the C# source
/// </summary>
public string FunctionCsharpParameters { get; }
/// <summary>
/// Gets the return type of the current function
/// </summary>
public string ReturnType { get; }
/// <summary>
/// Gets the name of the current function
/// </summary>
public string FunctionName { get; }
/// <summary>
/// Gets the list of parameters for the current function
/// </summary>
public IReadOnlyList<ParameterInfo> ParametersList { get; }
/// <summary>
/// Gets the body of the current function
/// </summary>
public string FunctionBody { get; }
/// <summary>
/// Creates a new <see cref="FunctionInfo"/> instance with the specified parameters
/// </summary>
/// <param name="functionCsharpType">The concrete return type for the function</param>
/// <param name="functionFullname">The fullname of the function in the C# source</param>
/// <param name="functionCsharpParameters">The parameters of the function in the C# source</param>
/// <param name="returnType">The return type of the current function</param>
/// <param name="functionName">The name of the current function</param>
/// <param name="parameters">The function parameters, if any</param>
/// <param name="functionBody">The current function</param>
public FunctionInfo(
Type functionCsharpType,
string functionFullname,
string functionCsharpParameters,
string returnType,
string functionName,
IReadOnlyList<ParameterInfo> parameters,
string functionBody)
{
FunctionCsharpReturnType = functionCsharpType.ToFriendlyString();
FunctionFullName = functionFullname;
FunctionCsharpParameters = functionCsharpParameters;
ReturnType = returnType;
FunctionName = functionName;
ParametersList = parameters;
FunctionBody = functionBody;
}
}
}
-29
ファイルの表示
@@ -1,29 +0,0 @@
using System;
namespace ComputeSharp.Shaders.Renderer.Models.Functions
{
/// <summary>
/// A <see langword="class"/> that contains info on a local shader function
/// </summary>
internal sealed class LocalFunctionInfo
{
/// <summary>
/// Gets the prototype for the current function
/// </summary>
public string FunctionPrototype => FunctionDeclaration.Split(Environment.NewLine)[0];
/// <summary>
/// Gets the declaration of the current function
/// </summary>
public string FunctionDeclaration { get; }
/// <summary>
/// Creates a new <see cref="LocalFunctionInfo"/> instance with the specified parameters
/// </summary>
/// <param name="functionDeclaration">The declaration of the current function</param>
public LocalFunctionInfo(string functionDeclaration)
{
FunctionDeclaration = functionDeclaration;
}
}
}
-52
ファイルの表示
@@ -1,52 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
namespace ComputeSharp.Shaders.Renderer.Models.Functions
{
/// <summary>
/// A <see langword="class"/> that contains info on a function parameter
/// </summary>
internal sealed class ParameterInfo
{
/// <summary>
/// Gets the modifier to use for the current parameter
/// </summary>
public string ParameterModifier { get; }
/// <summary>
/// Gets the type of the current parameter
/// </summary>
public string ParameterType { get; }
/// <summary>
/// Gets the name to use for the current parameter
/// </summary>
public string ParameterName { get; }
/// <summary>
/// Gets whether or not the current parameter is the last one for the parent function
/// </summary>
public bool IsLastParameter { get; }
/// <summary>
/// Creates a new <see cref="ParameterInfo"/> instance with the specified parameters
/// </summary>
/// <param name="parameterModifiers">The modifiers used in the current parameter</param>
/// <param name="parameterType">The type of the current parameter</param>
/// <param name="parameterName">The name of the current parameter</param>
/// <param name="last">Indicates whether or not the current parameter is the last one</param>
public ParameterInfo(IReadOnlyList<SyntaxToken> parameterModifiers, string parameterType, string parameterName, bool last)
{
if (parameterModifiers.Count == 0) ParameterModifier = "in";
else if (parameterModifiers.First().IsKind(SyntaxKind.OutKeyword)) ParameterModifier = "out";
else if (parameterModifiers.Any(m => m.IsKind(SyntaxKind.RefKeyword)) && !parameterModifiers.Any(m => m.IsKind(SyntaxKind.ReadOnlyKeyword))) ParameterModifier = "inout";
else ParameterModifier = "in";
ParameterType = parameterType;
ParameterName = parameterName;
IsLastParameter = last;
}
}
}
-60
ファイルの表示
@@ -1,60 +0,0 @@
using System.Collections.Generic;
using ComputeSharp.Shaders.Renderer.Models.Fields;
using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
using ComputeSharp.Shaders.Renderer.Models.Functions;
#pragma warning disable CS8618 // Non-nullable field is uninitialized
namespace ComputeSharp.Shaders.Renderer.Models
{
/// <summary>
/// A <see langword="class"/> that contains info to render a shader source to compile
/// </summary>
internal sealed class ShaderInfo
{
/// <summary>
/// Gets or sets the list of captured buffers being present in the current shader
/// </summary>
public IReadOnlyList<HlslBufferInfo> BuffersList { get; set; }
/// <summary>
/// Gets or sets the list of captured variables being present in the current shader
/// </summary>
public IReadOnlyList<CapturedFieldInfo> FieldsList { get; set; }
/// <summary>
/// Gets or sets the number of threads in the X group
/// </summary>
public int NumThreadsX { get; set; }
/// <summary>
/// Gets or sets the number of threads in the Y group
/// </summary>
public int NumThreadsY { get; set; }
/// <summary>
/// Gets or sets the number of threads in the Z group
/// </summary>
public int NumThreadsZ { get; set; }
/// <summary>
/// Gets or sets the name for the threads id variable used in the shader
/// </summary>
public string ThreadsIdsVariableName { get; set; }
/// <summary>
/// Gets or sets the shader body to compile
/// </summary>
public string ShaderBody { get; set; }
/// <summary>
/// Gets or sets the list of static functions used by the shader
/// </summary>
public IReadOnlyList<FunctionInfo> FunctionsList { get; set; }
/// <summary>
/// Gets or sets the list of local (implicit) functions used by the shader
/// </summary>
public IReadOnlyList<LocalFunctionInfo> LocalFunctionsList { get; set; }
}
}
379ファイル中100ファイルを読み込みました。 変更されたファイルが多すぎるため、それ以降のファイルは表示していません。 さらに表示