Merge pull request #171 from Sergio0694/feature/build-time-compilation
Build time compilation support
このコミットが含まれているのは:
28ファイル変更
+958
-148
検索条件に一致するファイルはありません
@@ -44,10 +44,30 @@ jobs:
|
||||
run: msbuild -t:restore,build /p:Configuration=Release /p:Platform=x64
|
||||
shell: cmd
|
||||
|
||||
# Build the whole ComputeSharp solution with /p:DisableShaderCompilationSupport=True
|
||||
build-solution-release-no-dynamic:
|
||||
runs-on: windows-2022
|
||||
steps:
|
||||
- name: Git checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/[email protected]
|
||||
- name: Setup .NET Core 3.1 SDK
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 3.1.x
|
||||
- name: Setup .NET 6 SDK
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 6.0.x
|
||||
- name: Build
|
||||
run: msbuild -t:restore,build /p:Configuration=Release /p:Platform=x64 /p:DisableShaderCompilationSupport=True
|
||||
shell: cmd
|
||||
|
||||
# Run all the unit tests referencing the ComputeSharp project directly
|
||||
run-tests:
|
||||
if: success()
|
||||
needs: [build-solution-debug, build-solution-release]
|
||||
needs: [build-solution-debug, build-solution-release, build-solution-release-no-dynamic]
|
||||
runs-on: windows-2022
|
||||
steps:
|
||||
- name: Git checkout
|
||||
@@ -151,7 +171,7 @@ jobs:
|
||||
# This workflow also uploads the resulting package as an artifact.
|
||||
build-package:
|
||||
if: success()
|
||||
needs: [build-solution-debug, build-solution-release]
|
||||
needs: [build-solution-debug, build-solution-release, build-solution-release-no-dynamic]
|
||||
runs-on: windows-2022
|
||||
steps:
|
||||
- name: Git checkout
|
||||
|
||||
@@ -84,6 +84,8 @@ Global
|
||||
src\ComputeSharp.UI\ComputeSharp.UI.projitems*{afaafdc9-be42-45d4-8c79-0ee8c8edbf52}*SharedItemsImports = 5
|
||||
samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{e7c9247d-016b-4819-af9f-0e9b3591e04b}*SharedItemsImports = 5
|
||||
samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{e91f4d24-922a-4921-a8d7-9c45a143c45d}*SharedItemsImports = 5
|
||||
src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{eb52cb67-4162-4722-874b-44ea8da5450e}*SharedItemsImports = 5
|
||||
src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{eb52cb67-4162-4722-874b-44ea8da5450e}*SharedItemsImports = 5
|
||||
src\ComputeSharp.UI\ComputeSharp.UI.projitems*{fa18ba9f-76bf-4de0-8d24-02fc7657e6cb}*SharedItemsImports = 5
|
||||
samples\ComputeSharp.SwapChain.Core.Shared\ComputeSharp.SwapChain.Core.Shared.projitems*{fbd388a5-7855-4408-98ff-e689f509db5a}*SharedItemsImports = 4
|
||||
samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{fbd388a5-7855-4408-98ff-e689f509db5a}*SharedItemsImports = 4
|
||||
|
||||
@@ -142,7 +142,6 @@
|
||||
<Link>Assets\Textures\RustyMetal.png</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="Package.StoreAssociation.xml" />
|
||||
<Content Include="Assets\SmallTile.scale-100.png" />
|
||||
<Content Include="Assets\SmallTile.scale-125.png" />
|
||||
<Content Include="Assets\SmallTile.scale-150.png" />
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\Path.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\InterpolatedStringHandlerArgumentAttribute.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\InterpolatedStringHandlerAttribute.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IsExternalInit.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\SkipLocalsInitAttribute.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\MemoryMarshal.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeHelpers.cs" />
|
||||
|
||||
+1
-5
@@ -1,8 +1,4 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace System.Runtime.CompilerServices;
|
||||
|
||||
@@ -52,3 +52,7 @@ CMPS0044 | ComputeSharp.IComputeShader | Error | IShaderGenerator, [Documentatio
|
||||
CMPS0045 | ComputeSharp.IComputeShader | Error | IShaderGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0046 | ComputeSharp.IComputeShader | Error | IShaderGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0047 | ComputeSharp.IComputeShader | Error | IShaderGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0048 | ComputeSharp.IComputeShader | Error | IShaderGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0049 | ComputeSharp.IComputeShader | Error | IShaderGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0050 | ComputeSharp.IComputeShader | Error | IShaderGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0051 | ComputeSharp.IComputeShader | Error | IShaderGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
@@ -4,73 +4,77 @@
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<PackSymbols>false</PackSymbols>
|
||||
<Description>ComputeSharp.SourceGenerators</Description>
|
||||
<NoWarn>$(NoWarn);CS1591;CS0649</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<DefineConstants>SOURCE_GENERATOR</DefineConstants>
|
||||
<DefineConstants>$(DefineConstants);SOURCE_GENERATOR</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--The source generator cannot contain package references or project references, so instead we're just
|
||||
manually linking the source files from ComputeSharp\Core in here. We only need them to extract metadata
|
||||
and to match members based on full name, so the types being in the generator assembly are not an issue.-->
|
||||
<ItemGroup>
|
||||
<Compile Include="..\ComputeSharp.NetStandard\System\Runtime\CompilerServices\RuntimeHelpers.cs" Link="Helpers\RuntimeHelpers.cs" />
|
||||
<Compile Include="..\ComputeSharp.NetStandard\System\Runtime\InteropServices\MemoryMarshal.cs" Link="Helpers\MemoryMarshal.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Attributes\AutoConstructorAttribute.cs" Link="Core\Attributes\AutoConstructorAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Attributes\GroupSharedAttribute.cs" Link="Core\Attributes\GroupSharedAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Attributes\ShaderMethodAttribute.cs" Link="Core\Attributes\ShaderMethodAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Attributes\__Internals\ShaderMethodSourceAttribute.cs" Link="Core\Attributes\__Internals\ShaderMethodSourceAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\DispatchSize.cs" Link="Core\Dispatch\DispatchSize.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\GridIds.cs" Link="Core\Dispatch\GridIds.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\GroupIds.cs" Link="Core\Dispatch\GroupIds.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\GroupSize.cs" Link="Core\Dispatch\GroupSize.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\ThreadIds.cs" Link="Core\Dispatch\ThreadIds.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\ThreadIds.Normalized.cs" Link="Core\Dispatch\ThreadIds.Normalized.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Exceptions\InvalidExecutionContextException.cs" Link="Core\Exceptions\InvalidExecutionContextException.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Extensions\MethodInfoExtensions.cs" Link="Core\Extensions\MethodInfoExtensions.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Helpers\AlignmentHelper.cs" Link="Core\Helpers\AlignmentHelper.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Interfaces\IComputeShader.cs" Link="Core\Interfaces\IComputeShader.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Interfaces\IPixelShader{TPixel}.cs" Link="Core\Interfaces\IPixelShader{TPixel}.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Intrinsics\Attributes\HlslIntrinsicNameAttribute.cs" Link="Core\Intrinsics\Attributes\HlslIntrinsicNameAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Intrinsics\Hlsl.cs" Link="Core\Intrinsics\Hlsl.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Intrinsics\Hlsl.g.cs" Link="Core\Intrinsics\Hlsl.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Bool\Bool.cs" Link="Core\Primitives\Bool\Bool.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Bool\Bool2.cs" Link="Core\Primitives\Bool\Bool2.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Bool\Bool3.cs" Link="Core\Primitives\Bool\Bool3.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Bool\Bool4.cs" Link="Core\Primitives\Bool\Bool4.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Bool\Bool2.g.cs" Link="Core\Primitives\Bool\Bool2.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Bool\Bool3.g.cs" Link="Core\Primitives\Bool\Bool3.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Bool\Bool4.g.cs" Link="Core\Primitives\Bool\Bool4.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Bool\BoolMxN.g.cs" Link="Core\Primitives\Bool\BoolMxN.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Double\Double2.cs" Link="Core\Primitives\Double\Double2.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Double\Double3.cs" Link="Core\Primitives\Double\Double3.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Double\Double4.cs" Link="Core\Primitives\Double\Double4.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Double\Double2.g.cs" Link="Core\Primitives\Double\Double2.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Double\Double3.g.cs" Link="Core\Primitives\Double\Double3.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Double\Double4.g.cs" Link="Core\Primitives\Double\Double4.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Double\DoubleMxN.g.cs" Link="Core\Primitives\Double\DoubleMxN.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Float\Float2.cs" Link="Core\Primitives\Float\Float2.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Float\Float3.cs" Link="Core\Primitives\Float\Float3.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Float\Float4.cs" Link="Core\Primitives\Float\Float4.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Float\Float2.g.cs" Link="Core\Primitives\Float\Float2.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Float\Float3.g.cs" Link="Core\Primitives\Float\Float3.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Float\Float4.g.cs" Link="Core\Primitives\Float\Float4.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Float\FloatMxN.g.cs" Link="Core\Primitives\Float\FloatMxN.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Int\Int2.cs" Link="Core\Primitives\Int\Int2.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Int\Int3.cs" Link="Core\Primitives\Int\Int3.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Int\Int4.cs" Link="Core\Primitives\Int\Int4.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Int\Int2.g.cs" Link="Core\Primitives\Int\Int2.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Int\Int3.g.cs" Link="Core\Primitives\Int\Int3.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Int\Int4.g.cs" Link="Core\Primitives\Int\Int4.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Int\IntMxN.g.cs" Link="Core\Primitives\Int\IntMxN.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\UInt\UInt2.cs" Link="Core\Primitives\UInt\UInt2.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\UInt\UInt3.cs" Link="Core\Primitives\UInt\UInt3.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\UInt\UInt4.cs" Link="Core\Primitives\UInt\UInt4.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\UInt\UInt2.g.cs" Link="Core\Primitives\UInt\UInt2.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\UInt\UInt3.g.cs" Link="Core\Primitives\UInt\UInt3.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\UInt\UInt4.g.cs" Link="Core\Primitives\UInt\UInt4.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\UInt\UIntMxN.g.cs" Link="Core\Primitives\UInt\UIntMxN.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\MatrixIndex.cs" Link="Core\Primitives\MatrixIndex.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Attributes\AutoConstructorAttribute.cs" Link="ComputeSharp\Core\Attributes\AutoConstructorAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Attributes\EmbeddedBytecodeAttribute.cs" Link="ComputeSharp\Core\Attributes\EmbeddedBytecodeAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Attributes\GroupSharedAttribute.cs" Link="ComputeSharp\Core\Attributes\GroupSharedAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Attributes\ShaderMethodAttribute.cs" Link="ComputeSharp\Core\Attributes\ShaderMethodAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Attributes\__Internals\ShaderMethodSourceAttribute.cs" Link="ComputeSharp\Core\Attributes\__Internals\ShaderMethodSourceAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\DispatchSize.cs" Link="ComputeSharp\Core\Dispatch\DispatchSize.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\GridIds.cs" Link="ComputeSharp\Core\Dispatch\GridIds.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\GroupIds.cs" Link="ComputeSharp\Core\Dispatch\GroupIds.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\GroupSize.cs" Link="ComputeSharp\Core\Dispatch\GroupSize.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\ThreadIds.cs" Link="ComputeSharp\Core\Dispatch\ThreadIds.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\ThreadIds.Normalized.cs" Link="ComputeSharp\Core\Dispatch\ThreadIds.Normalized.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Exceptions\InvalidExecutionContextException.cs" Link="ComputeSharp\Core\Exceptions\InvalidExecutionContextException.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Extensions\MethodInfoExtensions.cs" Link="ComputeSharp\Core\Extensions\MethodInfoExtensions.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Helpers\AlignmentHelper.cs" Link="ComputeSharp\Core\Helpers\AlignmentHelper.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Interfaces\IComputeShader.cs" Link="ComputeSharp\Core\Interfaces\IComputeShader.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Interfaces\IPixelShader{TPixel}.cs" Link="ComputeSharp\Core\Interfaces\IPixelShader{TPixel}.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Intrinsics\Attributes\HlslIntrinsicNameAttribute.cs" Link="ComputeSharp\Core\Intrinsics\Attributes\HlslIntrinsicNameAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Intrinsics\Hlsl.cs" Link="ComputeSharp\Core\Intrinsics\Hlsl.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Intrinsics\Hlsl.g.cs" Link="ComputeSharp\Core\Intrinsics\Hlsl.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Bool\Bool.cs" Link="ComputeSharp\Core\Primitives\Bool\Bool.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Bool\Bool2.cs" Link="ComputeSharp\Core\Primitives\Bool\Bool2.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Bool\Bool3.cs" Link="ComputeSharp\Core\Primitives\Bool\Bool3.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Bool\Bool4.cs" Link="ComputeSharp\Core\Primitives\Bool\Bool4.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Bool\Bool2.g.cs" Link="ComputeSharp\Core\Primitives\Bool\Bool2.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Bool\Bool3.g.cs" Link="ComputeSharp\Core\Primitives\Bool\Bool3.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Bool\Bool4.g.cs" Link="ComputeSharp\Core\Primitives\Bool\Bool4.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Bool\BoolMxN.g.cs" Link="ComputeSharp\Core\Primitives\Bool\BoolMxN.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Double\Double2.cs" Link="ComputeSharp\Core\Primitives\Double\Double2.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Double\Double3.cs" Link="ComputeSharp\Core\Primitives\Double\Double3.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Double\Double4.cs" Link="ComputeSharp\Core\Primitives\Double\Double4.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Double\Double2.g.cs" Link="ComputeSharp\Core\Primitives\Double\Double2.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Double\Double3.g.cs" Link="ComputeSharp\Core\Primitives\Double\Double3.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Double\Double4.g.cs" Link="ComputeSharp\Core\Primitives\Double\Double4.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Double\DoubleMxN.g.cs" Link="ComputeSharp\Core\Primitives\Double\DoubleMxN.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Float\Float2.cs" Link="ComputeSharp\Core\Primitives\Float\Float2.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Float\Float3.cs" Link="ComputeSharp\Core\Primitives\Float\Float3.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Float\Float4.cs" Link="ComputeSharp\Core\Primitives\Float\Float4.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Float\Float2.g.cs" Link="ComputeSharp\Core\Primitives\Float\Float2.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Float\Float3.g.cs" Link="ComputeSharp\Core\Primitives\Float\Float3.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Float\Float4.g.cs" Link="ComputeSharp\Core\Primitives\Float\Float4.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Float\FloatMxN.g.cs" Link="ComputeSharp\Core\Primitives\Float\FloatMxN.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Int\Int2.cs" Link="ComputeSharp\Core\Primitives\Int\Int2.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Int\Int3.cs" Link="ComputeSharp\Core\Primitives\Int\Int3.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Int\Int4.cs" Link="ComputeSharp\Core\Primitives\Int\Int4.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Int\Int2.g.cs" Link="ComputeSharp\Core\Primitives\Int\Int2.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Int\Int3.g.cs" Link="ComputeSharp\Core\Primitives\Int\Int3.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Int\Int4.g.cs" Link="ComputeSharp\Core\Primitives\Int\Int4.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\Int\IntMxN.g.cs" Link="ComputeSharp\Core\Primitives\Int\IntMxN.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\UInt\UInt2.cs" Link="ComputeSharp\Core\Primitives\UInt\UInt2.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\UInt\UInt3.cs" Link="ComputeSharp\Core\Primitives\UInt\UInt3.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\UInt\UInt4.cs" Link="ComputeSharp\Core\Primitives\UInt\UInt4.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\UInt\UInt2.g.cs" Link="ComputeSharp\Core\Primitives\UInt\UInt2.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\UInt\UInt3.g.cs" Link="ComputeSharp\Core\Primitives\UInt\UInt3.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\UInt\UInt4.g.cs" Link="ComputeSharp\Core\Primitives\UInt\UInt4.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\UInt\UIntMxN.g.cs" Link="ComputeSharp\Core\Primitives\UInt\UIntMxN.g.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Primitives\MatrixIndex.cs" Link="ComputeSharp\Core\Primitives\MatrixIndex.cs" />
|
||||
<Compile Include="..\ComputeSharp\Graphics\Extensions\Interop\ComPtrExtensions.cs" Link="ComputeSharp\Graphics\Extensions\Interop\ComPtrExtensions.cs" />
|
||||
<Compile Include="..\ComputeSharp\Shaders\Exceptions\HlslCompilationException.cs" Link="ComputeSharp\Shaders\Exceptions\HlslCompilationException.cs" />
|
||||
<Compile Include="..\ComputeSharp\Shaders\Translation\ShaderCompiler.cs" Link="ComputeSharp\Shaders\Translation\ShaderCompiler.cs" />
|
||||
<Compile Include="..\ComputeSharp\Shaders\Translation\__Internals\ArrayPoolStringBuilder.cs" Link="ComputeSharp\Shaders\Translation\__Internals\ArrayPoolStringBuilder.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -82,12 +86,23 @@
|
||||
<AdditionalFiles Include="AnalyzerReleases.Unshipped.md" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Pregenerated file with global using directives -->
|
||||
<ItemGroup>
|
||||
<Compile Remove="EmbeddedResources\GlobalUsingDirectives.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="EmbeddedResources\GlobalUsingDirectives.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\ComputeSharp\Libraries\x64\dxcompiler.dll" Link="ComputeSharp\Libraries\x64\dxcompiler.dll" />
|
||||
<EmbeddedResource Include="..\ComputeSharp\Libraries\x64\dxil.dll" Link="ComputeSharp\Libraries\x64\dxil.dll" />
|
||||
<EmbeddedResource Include="..\ComputeSharp\Libraries\arm64\dxcompiler.dll" Link="ComputeSharp\Libraries\arm64\dxcompiler.dll" />
|
||||
<EmbeddedResource Include="..\ComputeSharp\Libraries\arm64\dxil.dll" Link="ComputeSharp\Libraries\arm64\dxil.dll" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Shared project with .NET Standard 2.0 polyfills -->
|
||||
<Import Project="..\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems" Label="Shared" />
|
||||
|
||||
<!-- Shared project with TerraFX.Interop.Windows fork -->
|
||||
<Import Project="..\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems" Label="Shared" />
|
||||
|
||||
</Project>
|
||||
差分なしでファイル名を変更。
+35
@@ -0,0 +1,35 @@
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.Core.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Helper methods to efficiently throw exceptions.
|
||||
/// </summary>
|
||||
[DebuggerStepThrough]
|
||||
internal static class HResultExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws a <see cref="Win32Exception"/> if <paramref name="result"/> represents an error.
|
||||
/// </summary>
|
||||
/// <param name="result">The input <see cref="HRESULT"/> to check.</param>
|
||||
/// <exception cref="Win32Exception">Thrown if <paramref name="result"/> represents an error.</exception>
|
||||
public static void Assert(this HRESULT result)
|
||||
{
|
||||
Assert((int)result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a <see cref="Win32Exception"/> if <paramref name="result"/> represents an error.
|
||||
/// </summary>
|
||||
/// <param name="result">The input <see cref="int"/> to check.</param>
|
||||
/// <exception cref="Win32Exception">Thrown if <paramref name="result"/> represents an error.</exception>
|
||||
public static void Assert(this int result)
|
||||
{
|
||||
if (result < 0)
|
||||
{
|
||||
throw new Win32Exception(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -630,4 +630,68 @@ internal static class DiagnosticDescriptors
|
||||
isEnabledByDefault: true,
|
||||
description: "A shader type cannot implement more than one shader interface.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for a dynamic shader annotated as an embedded bytecode.
|
||||
/// <para>
|
||||
/// Format: <c>"The shader of type {0} cannot be precompiled, as it is dynamic (it captures delegate fields)"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static readonly DiagnosticDescriptor EmbeddedBytecodeWithDynamicShader = new(
|
||||
id: "CMPS0048",
|
||||
title: "Embedded bytecode for dynamic shader",
|
||||
messageFormat: $"The shader of type {{0}} cannot be precompiled, as it is dynamic (it captures delegate fields)",
|
||||
category: typeof(IShaderGenerator).FullName,
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "A shader type cannot be precompiled if it captures one or more delegate values.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for an embedded bytecode shader with invalid thread ids values.
|
||||
/// <para>
|
||||
/// Format: <c>"The shader of type {0} is annotated with invalid thread ids values ({1}, {2}, {3})"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static readonly DiagnosticDescriptor InvalidEmbeddedBytecodeThreadIds = new(
|
||||
id: "CMPS0049",
|
||||
title: "Invalid thread ids for shader with embedded bytecode",
|
||||
messageFormat: $"The shader of type {{0}} is annotated with invalid thread ids values ({{1}}, {{2}}, {{3}})",
|
||||
category: typeof(IShaderGenerator).FullName,
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "The thread ids values for a shader marked as embedded bytecode have to be in the valid range.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for an embedded bytecode shader failed due to a Win32 exception.
|
||||
/// <para>
|
||||
/// Format: <c>"The shader of type {{0}} failed to compile due to a Win32 exception (HRESULT: {1:X8}, Message: "{2}")"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithWin32Exception = new(
|
||||
id: "CMPS0050",
|
||||
title: "Embedded bytecode compilation failed due to Win32 exception",
|
||||
messageFormat: $"The shader of type {{0}} failed to compile due to a Win32 exception (HRESULT: {{1:X8}}, Message: \"{{2}}\")",
|
||||
category: typeof(IShaderGenerator).FullName,
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "The embedded bytecode for a shader failed to be compiled due to a Win32 exception.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for an embedded bytecode shader failed due to an HLSL compilation exception.
|
||||
/// <para>
|
||||
/// Format: <c>"The shader of type {{0}} failed to compile due to an HLSL compiler error (Message: "{1}")"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithHlslCompilationException = new(
|
||||
id: "CMPS0051",
|
||||
title: "Embedded bytecode compilation failed due to an HLSL compiler error",
|
||||
messageFormat: $"The shader of type {{0}} failed to compile due to an HLSL compiler error (Message: \"{{1}}\")",
|
||||
category: typeof(IShaderGenerator).FullName,
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "The embedded bytecode for a shader failed to be compiled due to an HLSL compiler error.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace System;
|
||||
|
||||
/// <summary>
|
||||
/// A polyfill type that mirrors some methods from <see cref="HashCode"/> on .NET 6.
|
||||
/// </summary>
|
||||
internal struct HashCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Combines six values into a hash code.
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">The type of the first value to combine into the hash code.</typeparam>
|
||||
/// <typeparam name="T2">The type of the second value to combine into the hash code.</typeparam>
|
||||
/// <typeparam name="T3">The type of the third value to combine into the hash code.</typeparam>
|
||||
/// <typeparam name="T4">The type of the fourth value to combine into the hash code.</typeparam>
|
||||
/// <typeparam name="T5">The type of the fifth value to combine into the hash code.</typeparam>
|
||||
/// <typeparam name="T6">The type of the sixth value to combine into the hash code.</typeparam>
|
||||
/// <param name="value1">The first value to combine into the hash code.</param>
|
||||
/// <param name="value2">The second value to combine into the hash code.</param>
|
||||
/// <param name="value3">The third value to combine into the hash code.</param>
|
||||
/// <param name="value4">The fourth value to combine into the hash code.</param>
|
||||
/// <param name="value5">The fifth value to combine into the hash code.</param>
|
||||
/// <param name="value6">The sixth value to combine into the hash code.</param>
|
||||
/// <returns>The hash code that represents the six values.</returns>
|
||||
public static int Combine<T1, T2, T3, T4, T5, T6>(T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a single value to the hash code.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the value to add to the hash code.</typeparam>
|
||||
/// <param name="value">The value to add to the hash code.</param>
|
||||
public void Add<T>(T value)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the final hash code after consecutive <see cref="Add{T}(T)"/> invocations.
|
||||
/// </summary>
|
||||
/// <returns>The calculated hash code.</returns>
|
||||
public int ToHashCode()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,8 @@ public sealed partial class IShaderGenerator
|
||||
StructDeclarationSyntax structDeclaration,
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
out string? implicitTextureType,
|
||||
out bool isSamplerUsed)
|
||||
out bool isSamplerUsed,
|
||||
out string hlslSource)
|
||||
{
|
||||
// Properties are not supported
|
||||
DetectAndReportPropertyDeclarations(context, structDeclarationSymbol);
|
||||
@@ -70,7 +71,8 @@ public sealed partial class IShaderGenerator
|
||||
accessesStaticSampler,
|
||||
sharedBuffers,
|
||||
processedMethods,
|
||||
entryPoint);
|
||||
entryPoint,
|
||||
out hlslSource);
|
||||
|
||||
implicitTextureType = pixelShaderTextureType;
|
||||
isSamplerUsed = accessesStaticSampler;
|
||||
@@ -472,6 +474,7 @@ public sealed partial class IShaderGenerator
|
||||
/// <param name="sharedBuffers">The sequence of shared buffers declared by the shader.</param>
|
||||
/// <param name="processedMethods">The sequence of processed methods used by the shader.</param>
|
||||
/// <param name="executeMethod">The body of the entry point of the shader.</param>
|
||||
/// <param name="hlslSource">The generated HLSL source code (ignoring captured delegates, if present).</param>
|
||||
/// <returns>The series of statements to build the HLSL source to compile to execute the current shader.</returns>
|
||||
private static IEnumerable<StatementSyntax> GenerateRenderMethodBody(
|
||||
IEnumerable<(string Name, string Value)> definedConstants,
|
||||
@@ -483,34 +486,41 @@ public sealed partial class IShaderGenerator
|
||||
bool isSamplerUsed,
|
||||
IEnumerable<(string Name, string Type, int? Count)> sharedBuffers,
|
||||
IEnumerable<(string Signature, string Definition)> processedMethods,
|
||||
string executeMethod)
|
||||
string executeMethod,
|
||||
out string hlslSource)
|
||||
{
|
||||
List<StatementSyntax> statements = new();
|
||||
StringBuilder textBuilder = new();
|
||||
StringBuilder chunkedTextBuilder = new();
|
||||
StringBuilder aggregateTextBuilder = new();
|
||||
int capturedDelegates = 0;
|
||||
int prologueStatements = 0;
|
||||
int sizeHint = 64;
|
||||
|
||||
void AppendLF()
|
||||
{
|
||||
textBuilder.Append('\n');
|
||||
chunkedTextBuilder.Append('\n');
|
||||
}
|
||||
|
||||
void AppendLine(string text)
|
||||
{
|
||||
textBuilder.Append(text);
|
||||
chunkedTextBuilder.Append(text);
|
||||
}
|
||||
|
||||
void AppendLineAndLF(string text)
|
||||
{
|
||||
textBuilder.Append(text);
|
||||
textBuilder.Append('\n');
|
||||
chunkedTextBuilder.Append(text);
|
||||
chunkedTextBuilder.Append('\n');
|
||||
}
|
||||
|
||||
void AppendCharacterAndLF(char c)
|
||||
{
|
||||
textBuilder.Append(c);
|
||||
textBuilder.Append('\n');
|
||||
chunkedTextBuilder.Append(c);
|
||||
chunkedTextBuilder.Append('\n');
|
||||
}
|
||||
|
||||
void AppendThreadNumIdentifier(string name)
|
||||
{
|
||||
aggregateTextBuilder.Append(name);
|
||||
}
|
||||
|
||||
void AppendParsedStatement(string text)
|
||||
@@ -522,17 +532,21 @@ public sealed partial class IShaderGenerator
|
||||
|
||||
void FlushText()
|
||||
{
|
||||
if (textBuilder.Length > 0)
|
||||
if (chunkedTextBuilder.Length > 0)
|
||||
{
|
||||
sizeHint += textBuilder.Length;
|
||||
string chunkedText = chunkedTextBuilder.ToString();
|
||||
|
||||
aggregateTextBuilder.Append(chunkedText);
|
||||
|
||||
sizeHint += chunkedTextBuilder.Length;
|
||||
|
||||
statements.Add(
|
||||
ExpressionStatement(
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName("builder"), IdentifierName("Append")))
|
||||
.AddArgumentListArguments(Argument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(textBuilder.ToString()))))));
|
||||
.AddArgumentListArguments(Argument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(chunkedText))))));
|
||||
|
||||
textBuilder.Clear();
|
||||
chunkedTextBuilder.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -608,12 +622,15 @@ public sealed partial class IShaderGenerator
|
||||
AppendLF();
|
||||
AppendLine("#define __GroupSize__get_X ");
|
||||
AppendParsedStatement("builder.Append(threadsX);");
|
||||
AppendThreadNumIdentifier("<THREADSX>");
|
||||
AppendLF();
|
||||
AppendLine("#define __GroupSize__get_Y ");
|
||||
AppendParsedStatement("builder.Append(threadsY);");
|
||||
AppendThreadNumIdentifier("<THREADSY>");
|
||||
AppendLF();
|
||||
AppendLine("#define __GroupSize__get_Z ");
|
||||
AppendParsedStatement("builder.Append(threadsZ);");
|
||||
AppendThreadNumIdentifier("<THREADSZ>");
|
||||
AppendLF();
|
||||
|
||||
// Define declarations
|
||||
@@ -810,6 +827,8 @@ public sealed partial class IShaderGenerator
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(sizeHint)))))));
|
||||
|
||||
hlslSource = aggregateTextBuilder.ToString();
|
||||
|
||||
return statements;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ namespace ComputeSharp.SourceGenerators;
|
||||
public sealed partial class IShaderGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
private static partial MethodDeclarationSyntax CreateGetDispatchIdMethod(INamedTypeSymbol structDeclarationSymbol)
|
||||
private static partial MethodDeclarationSyntax CreateGetDispatchIdMethod(INamedTypeSymbol structDeclarationSymbol, out bool isDynamicShader)
|
||||
{
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
@@ -30,16 +30,17 @@ public sealed partial class IShaderGenerator
|
||||
Identifier("GetDispatchId"))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.__Internals.{nameof(IShader)}")))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.WithBody(GetShaderHashCodeBody(structDeclarationSymbol));
|
||||
.WithBody(GetShaderHashCodeBody(structDeclarationSymbol, out isDynamicShader));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="BlockSyntax"/> instance with the logic to compute the hashcode of a given shader type.
|
||||
/// </summary>
|
||||
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
|
||||
/// <param name="isDynamicShader">Indicates whether or not the shader is dynamic (ie. captures delegates).</param>
|
||||
/// <returns>The <see cref="BlockSyntax"/> instance to hash the input shader.</returns>
|
||||
[Pure]
|
||||
private static BlockSyntax GetShaderHashCodeBody(INamedTypeSymbol structDeclarationSymbol)
|
||||
private static BlockSyntax GetShaderHashCodeBody(INamedTypeSymbol structDeclarationSymbol, out bool isDynamicShader)
|
||||
{
|
||||
var delegateFields = structDeclarationSymbol
|
||||
.GetMembers()
|
||||
@@ -47,6 +48,8 @@ public sealed partial class IShaderGenerator
|
||||
.Where(static m => m.Type is INamedTypeSymbol { TypeKind: TypeKind.Delegate, IsStatic: false })
|
||||
.ToImmutableArray();
|
||||
|
||||
isDynamicShader = delegateFields.Length > 0;
|
||||
|
||||
if (delegateFields.Length == 0)
|
||||
{
|
||||
// return 0;
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Shaders.Translation;
|
||||
using ComputeSharp.SourceGenerators.Diagnostics;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
using static ComputeSharp.SourceGenerators.Diagnostics.DiagnosticDescriptors;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class IShaderGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates whether the required <c>dxcompiler.dll</c> and <c>dxil.dll</c> libraries have been loaded.
|
||||
/// </summary>
|
||||
private static bool areDxcLibrariesLoaded;
|
||||
|
||||
/// <inheritdoc/>
|
||||
private static partial MethodDeclarationSyntax CreateTryGetBytecodeMethod(
|
||||
GeneratorExecutionContext context,
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
bool isDynamicShader,
|
||||
string hlslSource,
|
||||
out string? bytecodeLiterals)
|
||||
{
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// readonly int global::ComputeSharp.__Internals.IShader.TryGetBytecode(int threadsX, int threadsY, int threadsZ, out ReadOnlySpan<byte> bytecode)
|
||||
// {
|
||||
// <BODY>
|
||||
// }
|
||||
return
|
||||
MethodDeclaration(
|
||||
PredefinedType(Token(SyntaxKind.BoolKeyword)),
|
||||
Identifier("TryGetBytecode"))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.__Internals.{nameof(IShader)}")))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.AddParameterListParameters(
|
||||
Parameter(Identifier("threadsX")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))),
|
||||
Parameter(Identifier("threadsY")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))),
|
||||
Parameter(Identifier("threadsZ")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))),
|
||||
Parameter(Identifier("bytecode")).AddModifiers(Token(SyntaxKind.OutKeyword)).WithType(IdentifierName("global::System.ReadOnlySpan<byte>")))
|
||||
.WithBody(GetShaderBytecodeBody(context, structDeclarationSymbol, isDynamicShader, hlslSource, out bytecodeLiterals));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="BlockSyntax"/> instance with the logic to try to get a compiled shader bytecode.
|
||||
/// </summary>
|
||||
/// <param name="context">The current generator context in use.</param>
|
||||
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
|
||||
/// <param name="isDynamicShader">Indicates whether or not the shader is dynamic (ie. captures delegates).</param>
|
||||
/// <param name="hlslSource">The generated HLSL source code (ignoring captured delegates, if present).</param>
|
||||
/// <param name="bytecodeLiterals">The resulting bytecode literals to insert into the final source code.</param>
|
||||
/// <returns>The <see cref="BlockSyntax"/> instance to hash the input shader.</returns>
|
||||
[Pure]
|
||||
private static unsafe BlockSyntax GetShaderBytecodeBody(
|
||||
GeneratorExecutionContext context,
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
bool isDynamicShader,
|
||||
string hlslSource,
|
||||
out string? bytecodeLiterals)
|
||||
{
|
||||
AttributeData? attribute = structDeclarationSymbol.GetAttributes().FirstOrDefault(static a => a.AttributeClass is { Name: nameof(EmbeddedBytecodeAttribute) });
|
||||
|
||||
// No embedded shader was requested
|
||||
if (attribute is null)
|
||||
{
|
||||
goto Failure;
|
||||
}
|
||||
|
||||
// If the current shader is dynamic, emit a diagnostic error
|
||||
if (isDynamicShader)
|
||||
{
|
||||
context.ReportDiagnostic(EmbeddedBytecodeWithDynamicShader, structDeclarationSymbol, structDeclarationSymbol);
|
||||
|
||||
goto Failure;
|
||||
}
|
||||
|
||||
// Validate the thread number arguments
|
||||
if (attribute.ConstructorArguments[0].Value is not int threadsX ||
|
||||
attribute.ConstructorArguments[1].Value is not int threadsY ||
|
||||
attribute.ConstructorArguments[2].Value is not int threadsZ ||
|
||||
threadsX is < 1 or > 1024 ||
|
||||
threadsY is < 1 or > 1024 ||
|
||||
threadsZ is < 1 or > 64)
|
||||
{
|
||||
context.ReportDiagnostic(InvalidEmbeddedBytecodeThreadIds, structDeclarationSymbol, structDeclarationSymbol);
|
||||
|
||||
goto Failure;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Try to load dxcompiler.dll and dxil.dll
|
||||
LoadNativeDxcLibraries();
|
||||
|
||||
// Replace the actual thread num values
|
||||
hlslSource = hlslSource.Replace("<THREADSX>", threadsX.ToString()).Replace("<THREADSY>", threadsY.ToString()).Replace("<THREADSZ>", threadsZ.ToString());
|
||||
|
||||
// Compile the shader bytecode
|
||||
using ComPtr<IDxcBlob> dxcBlobBytecode = ShaderCompiler.Instance.CompileShader(hlslSource.AsSpan());
|
||||
|
||||
byte* buffer = (byte*)dxcBlobBytecode.Get()->GetBufferPointer();
|
||||
int length = checked((int)dxcBlobBytecode.Get()->GetBufferSize());
|
||||
|
||||
// Build and set the text with the literal expressions
|
||||
bytecodeLiterals = BuildShaderBytecodeExpressionString(new ReadOnlySpan<byte>(buffer, length));
|
||||
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// if (threadsX == <X> && threadsY == <Y> && threadsZ == <Z>)
|
||||
// {
|
||||
// bytecode = new byte[] { __EMBEDDED_SHADER_BYTECODE };
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// bytecode = default;
|
||||
//
|
||||
// return false;
|
||||
//
|
||||
// Note that the __EMBEDDED_SHADER_BYTECODE identifier will be replaced after the string
|
||||
// is created by the generator. This greatly speeds up the code generation, as it avoids
|
||||
// having to create/parse tens of thousands of literal expression nodes for every shader.
|
||||
return
|
||||
Block(
|
||||
IfStatement(
|
||||
BinaryExpression(
|
||||
SyntaxKind.LogicalAndExpression,
|
||||
BinaryExpression(
|
||||
SyntaxKind.LogicalAndExpression,
|
||||
BinaryExpression(
|
||||
SyntaxKind.EqualsExpression,
|
||||
IdentifierName("threadsX"),
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(threadsX))),
|
||||
BinaryExpression(
|
||||
SyntaxKind.EqualsExpression,
|
||||
IdentifierName("threadsY"),
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(threadsY)))),
|
||||
BinaryExpression(
|
||||
SyntaxKind.EqualsExpression,
|
||||
IdentifierName("threadsZ"),
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(threadsZ)))),
|
||||
Block(
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
IdentifierName("bytecode"),
|
||||
ArrayCreationExpression(
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.ByteKeyword)))
|
||||
.AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(OmittedArraySizeExpression()))))
|
||||
.WithInitializer(
|
||||
InitializerExpression(
|
||||
SyntaxKind.ArrayInitializerExpression,
|
||||
SingletonSeparatedList<ExpressionSyntax>(IdentifierName("__EMBEDDED_SHADER_BYTECODE")))))),
|
||||
ReturnStatement(LiteralExpression(SyntaxKind.TrueLiteralExpression)))),
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
IdentifierName("bytecode"),
|
||||
LiteralExpression(SyntaxKind.DefaultLiteralExpression, Token(SyntaxKind.DefaultKeyword)))),
|
||||
ReturnStatement(LiteralExpression(SyntaxKind.FalseLiteralExpression)));
|
||||
}
|
||||
catch (Win32Exception e)
|
||||
{
|
||||
context.ReportDiagnostic(
|
||||
EmbeddedBytecodeFailedWithWin32Exception,
|
||||
structDeclarationSymbol,
|
||||
structDeclarationSymbol,
|
||||
e.HResult,
|
||||
e.Message);
|
||||
}
|
||||
catch (HlslCompilationException e)
|
||||
{
|
||||
context.ReportDiagnostic(
|
||||
EmbeddedBytecodeFailedWithHlslCompilationException,
|
||||
structDeclarationSymbol,
|
||||
structDeclarationSymbol,
|
||||
e.Message);
|
||||
}
|
||||
|
||||
Failure:
|
||||
bytecodeLiterals = null;
|
||||
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// bytecode = default;
|
||||
//
|
||||
// return false;
|
||||
return
|
||||
Block(
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
IdentifierName("bytecode"),
|
||||
LiteralExpression(SyntaxKind.DefaultLiteralExpression, Token(SyntaxKind.DefaultKeyword)))),
|
||||
ReturnStatement(
|
||||
LiteralExpression(
|
||||
SyntaxKind.FalseLiteralExpression)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extracts and loads the <c>dxcompiler.dll</c> and <c>dxil.dll</c> libraries.
|
||||
/// </summary>
|
||||
/// <exception cref="NotSupportedException">Thrown if the CPU architecture is not supported.</exception>
|
||||
/// <exception cref="Win32Exception">Thrown if a library fails to load.</exception>
|
||||
private static void LoadNativeDxcLibraries()
|
||||
{
|
||||
// Extracts a specified native library for a given runtime identifier
|
||||
static string ExtractLibrary(string rid, string name)
|
||||
{
|
||||
string sourceFilename = $"ComputeSharp.SourceGenerators.ComputeSharp.Libraries.{rid}.{name}.dll";
|
||||
string targetFilename = Path.Combine(Path.GetTempPath(), "ComputeSharp.SourceGenerators", Path.GetRandomFileName(), rid, $"{name}.dll");
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(targetFilename));
|
||||
|
||||
using Stream sourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(sourceFilename);
|
||||
|
||||
try
|
||||
{
|
||||
using Stream destinationStream = File.Open(targetFilename, FileMode.CreateNew, FileAccess.Write);
|
||||
|
||||
sourceStream.CopyTo(destinationStream);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
}
|
||||
|
||||
return targetFilename;
|
||||
}
|
||||
|
||||
// Loads a target native library
|
||||
static unsafe void LoadLibrary(string filename)
|
||||
{
|
||||
[DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
|
||||
static extern void* LoadLibraryW(ushort* lpLibFileName);
|
||||
|
||||
fixed (char* p = filename)
|
||||
{
|
||||
if (LoadLibraryW((ushort*)p) is null)
|
||||
{
|
||||
int hresult = Marshal.GetLastWin32Error();
|
||||
|
||||
throw new Win32Exception(hresult, $"Failed to load {Path.GetFileName(filename)}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!areDxcLibrariesLoaded)
|
||||
{
|
||||
string rid = RuntimeInformation.ProcessArchitecture switch
|
||||
{
|
||||
Architecture.X64 => "x64",
|
||||
Architecture.Arm64 => "arm64",
|
||||
_ => throw new NotSupportedException("Invalid process architecture")
|
||||
};
|
||||
|
||||
LoadLibrary(ExtractLibrary(rid, "dxil"));
|
||||
LoadLibrary(ExtractLibrary(rid, "dxcompiler"));
|
||||
}
|
||||
|
||||
areDxcLibrariesLoaded = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A mapping of precomputed literals for all <see cref="byte"/> values.
|
||||
/// </summary>
|
||||
private static readonly string[] formattedBytes =
|
||||
{
|
||||
"0x00", "0x01", "0x02", "0x03", "0x04", "0x05", "0x06", "0x07", "0x08", "0x09", "0x0A", "0x0B", "0x0C", "0x0D", "0x0E", "0x0F",
|
||||
"0x10", "0x11", "0x12", "0x13", "0x14", "0x15", "0x16", "0x17", "0x18", "0x19", "0x1A", "0x1B", "0x1C", "0x1D", "0x1E", "0x1F",
|
||||
"0x20", "0x21", "0x22", "0x23", "0x24", "0x25", "0x26", "0x27", "0x28", "0x29", "0x2A", "0x2B", "0x2C", "0x2D", "0x2E", "0x2F",
|
||||
"0x30", "0x31", "0x32", "0x33", "0x34", "0x35", "0x36", "0x37", "0x38", "0x39", "0x3A", "0x3B", "0x3C", "0x3D", "0x3E", "0x3F",
|
||||
"0x40", "0x41", "0x42", "0x43", "0x44", "0x45", "0x46", "0x47", "0x48", "0x49", "0x4A", "0x4B", "0x4C", "0x4D", "0x4E", "0x4F",
|
||||
"0x50", "0x51", "0x52", "0x53", "0x54", "0x55", "0x56", "0x57", "0x58", "0x59", "0x5A", "0x5B", "0x5C", "0x5D", "0x5E", "0x5F",
|
||||
"0x60", "0x61", "0x62", "0x63", "0x64", "0x65", "0x66", "0x67", "0x68", "0x69", "0x6A", "0x6B", "0x6C", "0x6D", "0x6E", "0x6F",
|
||||
"0x70", "0x71", "0x72", "0x73", "0x74", "0x75", "0x76", "0x77", "0x78", "0x79", "0x7A", "0x7B", "0x7C", "0x7D", "0x7E", "0x7F",
|
||||
"0x80", "0x81", "0x82", "0x83", "0x84", "0x85", "0x86", "0x87", "0x88", "0x89", "0x8A", "0x8B", "0x8C", "0x8D", "0x8E", "0x8F",
|
||||
"0x90", "0x91", "0x92", "0x93", "0x94", "0x95", "0x96", "0x97", "0x98", "0x99", "0x9A", "0x9B", "0x9C", "0x9D", "0x9E", "0x9F",
|
||||
"0xA0", "0xA1", "0xA2", "0xA3", "0xA4", "0xA5", "0xA6", "0xA7", "0xA8", "0xA9", "0xAA", "0xAB", "0xAC", "0xAD", "0xAE", "0xAF",
|
||||
"0xB0", "0xB1", "0xB2", "0xB3", "0xB4", "0xB5", "0xB6", "0xB7", "0xB8", "0xB9", "0xBA", "0xBB", "0xBC", "0xBD", "0xBE", "0xBF",
|
||||
"0xC0", "0xC1", "0xC2", "0xC3", "0xC4", "0xC5", "0xC6", "0xC7", "0xC8", "0xC9", "0xCA", "0xCB", "0xCC", "0xCD", "0xCE", "0xCF",
|
||||
"0xD0", "0xD1", "0xD2", "0xD3", "0xD4", "0xD5", "0xD6", "0xD7", "0xD8", "0xD9", "0xDA", "0xDB", "0xDC", "0xDD", "0xDE", "0xDF",
|
||||
"0xE0", "0xE1", "0xE2", "0xE3", "0xE4", "0xE5", "0xE6", "0xE7", "0xE8", "0xE9", "0xEA", "0xEB", "0xEC", "0xED", "0xEE", "0xEF",
|
||||
"0xF0", "0xF1", "0xF2", "0xF3", "0xF4", "0xF5", "0xF6", "0xF7", "0xF8", "0xF9", "0xFA", "0xFB", "0xFC", "0xFD", "0xFE", "0xFF"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Creates a formatted expression to initialize a <see cref="ReadOnlySpan{T}"/> with a given shader data.
|
||||
/// </summary>
|
||||
/// <param name="bytecode">The input shader bytecode to serialize.</param>
|
||||
/// <returns>A formatted <see cref="string"/> with the serialized data.</returns>
|
||||
private static string BuildShaderBytecodeExpressionString(ReadOnlySpan<byte> bytecode)
|
||||
{
|
||||
//The estimation is 4 characters per byte (up to "255" in hex), plus ", " to separate sequential values
|
||||
using ArrayPoolStringBuilder builder = ArrayPoolStringBuilder.Create(bytecode.Length * 6);
|
||||
|
||||
builder.Append(formattedBytes[bytecode[0]]);
|
||||
|
||||
foreach (byte b in bytecode.Slice(1))
|
||||
{
|
||||
builder.Append(", ");
|
||||
builder.Append(formattedBytes[b]);
|
||||
}
|
||||
|
||||
return builder.WrittenSpan.ToString();
|
||||
}
|
||||
}
|
||||
@@ -56,10 +56,11 @@ public sealed partial class IShaderGenerator : ISourceGenerator
|
||||
private static void OnExecute(GeneratorExecutionContext context, StructDeclarationSyntax structDeclaration, INamedTypeSymbol structDeclarationSymbol)
|
||||
{
|
||||
// Create the required interface methods for the current shader type
|
||||
MethodDeclarationSyntax getDispatchIdMethod = CreateGetDispatchIdMethod(structDeclarationSymbol);
|
||||
MethodDeclarationSyntax getDispatchIdMethod = CreateGetDispatchIdMethod(structDeclarationSymbol, out bool isDynamicShader);
|
||||
MethodDeclarationSyntax loadDispatchDataMethod = CreateLoadDispatchDataMethod(context, structDeclarationSymbol, out var discoveredResources, out int root32BitConstants);
|
||||
MethodDeclarationSyntax buildHlslStringMethod = CreateBuildHlslStringMethod(context, structDeclaration, structDeclarationSymbol, out string? implicitTextureType, out bool isSamplerUsed);
|
||||
MethodDeclarationSyntax buildHlslStringMethod = CreateBuildHlslStringMethod(context, structDeclaration, structDeclarationSymbol, out string? implicitTextureType, out bool isSamplerUsed, out string hlslSource);
|
||||
MethodDeclarationSyntax loadDispatchMetadataMethod = CreateLoadDispatchMetadataMethod(implicitTextureType, discoveredResources, root32BitConstants, isSamplerUsed);
|
||||
MethodDeclarationSyntax tryGetBytecodeMethod = CreateTryGetBytecodeMethod(context, structDeclarationSymbol, isDynamicShader, hlslSource, out string? bytecodeLiterals);
|
||||
|
||||
// Reorder the method declarations to respect the order in the interface definition
|
||||
MethodDeclarationSyntax[] methods =
|
||||
@@ -67,7 +68,8 @@ public sealed partial class IShaderGenerator : ISourceGenerator
|
||||
getDispatchIdMethod,
|
||||
loadDispatchDataMethod,
|
||||
loadDispatchMetadataMethod,
|
||||
buildHlslStringMethod
|
||||
buildHlslStringMethod,
|
||||
tryGetBytecodeMethod
|
||||
};
|
||||
|
||||
// Method attributes
|
||||
@@ -140,6 +142,12 @@ public sealed partial class IShaderGenerator : ISourceGenerator
|
||||
.NormalizeWhitespace(eol: "\n")
|
||||
.ToFullString();
|
||||
|
||||
// Insert the bytecode literals, if needed
|
||||
if (bytecodeLiterals is not null)
|
||||
{
|
||||
source = source.Replace("__EMBEDDED_SHADER_BYTECODE", bytecodeLiterals);
|
||||
}
|
||||
|
||||
// Add the method source attribute
|
||||
context.AddSource(structDeclarationSymbol.GetGeneratedFileName(), SourceText.From(source, Encoding.UTF8));
|
||||
}
|
||||
@@ -148,8 +156,9 @@ public sealed partial class IShaderGenerator : ISourceGenerator
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>GetDispatchId</c> method.
|
||||
/// </summary>
|
||||
/// <param name="structDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for the input struct declaration.</param>
|
||||
/// <param name="isDynamicShader">Indicates whether or not the shader is dynamic (ie. captures delegates).</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>GetDispatchId</c> method.</returns>
|
||||
private static partial MethodDeclarationSyntax CreateGetDispatchIdMethod(INamedTypeSymbol structDeclarationSymbol);
|
||||
private static partial MethodDeclarationSyntax CreateGetDispatchIdMethod(INamedTypeSymbol structDeclarationSymbol, out bool isDynamicShader);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>LoadDispatchDataMethod</c> method.
|
||||
@@ -173,13 +182,15 @@ public sealed partial class IShaderGenerator : ISourceGenerator
|
||||
/// <param name="structDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for <paramref name="structDeclaration"/>.</param>
|
||||
/// <param name="implicitTextureType">The implicit texture type, if available (if the shader is a pixel shader).</param>
|
||||
/// <param name="isSamplerUsed">Whether or not the current shader type requires a static sampler to be available.</param>
|
||||
/// <param name="hlslSource">The generated HLSL source code (ignoring captured delegates, if present).</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>BuildHlslString</c> method.</returns>
|
||||
private static partial MethodDeclarationSyntax CreateBuildHlslStringMethod(
|
||||
GeneratorExecutionContext context,
|
||||
StructDeclarationSyntax structDeclaration,
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
out string? implicitTextureType,
|
||||
out bool isSamplerUsed);
|
||||
out bool isSamplerUsed,
|
||||
out string hlslSource);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>LoadDispatchMetadata</c> method.
|
||||
@@ -194,4 +205,20 @@ public sealed partial class IShaderGenerator : ISourceGenerator
|
||||
IReadOnlyCollection<string> discoveredResources,
|
||||
int root32BitConstantsCount,
|
||||
bool isSamplerUsed);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>TryGetBytecode</c> method.
|
||||
/// </summary>
|
||||
/// <param name="context">The input <see cref="GeneratorExecutionContext"/> instance to use.</param>
|
||||
/// <param name="structDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for the shader type.</param>
|
||||
/// <param name="isDynamicShader">Indicates whether or not the shader is dynamic (ie. captures delegates).</param>
|
||||
/// <param name="hlslSource">The generated HLSL source code (ignoring captured delegates, if present).</param>
|
||||
/// <param name="bytecodeLiterals">The resulting bytecode literals to insert into the final source code.</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>BuildHlslString</c> method.</returns>
|
||||
private static partial MethodDeclarationSyntax CreateTryGetBytecodeMethod(
|
||||
GeneratorExecutionContext context,
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
bool isDynamicShader,
|
||||
string hlslSource,
|
||||
out string? bytecodeLiterals);
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
<DocumentationFile>ComputeSharp.xml</DocumentationFile>
|
||||
<Description>ComputeSharp</Description>
|
||||
<Platforms>AnyCPU;x64;ARM64</Platforms>
|
||||
<DisableShaderCompilationSupport>false</DisableShaderCompilationSupport>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -37,8 +38,16 @@
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Define DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT if requested -->
|
||||
<PropertyGroup Condition="'$(DisableShaderCompilationSupport)' == 'true'">
|
||||
<DefineConstants>$(DefineConstants);DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<Choose>
|
||||
|
||||
<!-- Skip bundling any native library if support is disabled -->
|
||||
<When Condition="'$(DisableShaderCompilationSupport)' == 'true'"/>
|
||||
|
||||
<!-- When building locally for x64/ARM64 (using the project through a project reference),
|
||||
just copy the right native libraries to the output directory, with no subfolders. -->
|
||||
<When Condition="'$(Platform)' == 'x64'">
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// An attribute that indicates that a given shader should be precompiled at build time and embedded
|
||||
/// directly into the containing assembly as static bytecode, to avoid compiling it at runtime.
|
||||
/// <para>
|
||||
/// This attribute can be used to annotate shader types as follows:
|
||||
/// <code>
|
||||
/// [EmbeddedBytecode(8, 8, 1)]
|
||||
/// struct MyShader : IComputeShader
|
||||
/// {
|
||||
/// }
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This attribute can only be used when the shader type being annotated does not require dynamic
|
||||
/// features. Specifically, this attribute is not supported if the shader captures any delegates.
|
||||
/// </para>
|
||||
/// The runtime compilation will automatically be skipped if the shader is invoked using matching
|
||||
/// thread count values, otherwise the usual runtime compilation will be used as fallback. In case
|
||||
/// the fallback support is not needed and all shaders in use are being precompiled, it is possible
|
||||
/// to skip bundling the native <c>dxcompiler.dll</c> and <c>dxil.dll</c> libraries included with
|
||||
/// ComputeSharp entirely, resulting in a smaller binary size in consuming applications. To do this,
|
||||
/// the <c>PackageReference</c> item for the library should be annotated with <c>ExcludeAssets="native"</c>.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
|
||||
public sealed class EmbeddedBytecodeAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="EmbeddedBytecodeAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="threadsX">The number of threads in each thread group for the X axis.</param>
|
||||
/// <param name="threadsY">The number of threads in each thread group for the Y axis.</param>
|
||||
/// <param name="threadsZ">The number of threads in each thread group for the Z axis.</param>
|
||||
public EmbeddedBytecodeAttribute(int threadsX, int threadsY, int threadsZ)
|
||||
{
|
||||
ThreadsX = threadsX;
|
||||
ThreadsY = threadsY;
|
||||
ThreadsZ = threadsZ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of threads in each thread group for the X axis
|
||||
/// </summary>
|
||||
public int ThreadsX { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of threads in each thread group for the Y axis
|
||||
/// </summary>
|
||||
public int ThreadsY { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of threads in each thread group for the Z axis
|
||||
/// </summary>
|
||||
public int ThreadsZ { get; init; }
|
||||
}
|
||||
@@ -81,4 +81,24 @@ public interface IShader
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Tries to retrieve the precompiled bytecode for the current shader.
|
||||
/// </summary>
|
||||
/// <param name="threadsX">The number of threads in each thread group for the X axis.</param>
|
||||
/// <param name="threadsY">The number of threads in each thread group for the Y axis.</param>
|
||||
/// <param name="threadsZ">The number of threads in each thread group for the Z axis.</param>
|
||||
/// <param name="bytecode">The resulting bytecode, if found.</param>
|
||||
/// <returns>Whether or not a precompiled bytecode was found.</returns>
|
||||
/// <remarks>The underlying buffer for <paramref name="bytecode"/>, if found, can be assumed to always be pinned.</remarks>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be used directly by user code")]
|
||||
bool TryGetBytecode(int threadsX, int threadsY, int threadsZ, out ReadOnlySpan<byte> bytecode)
|
||||
#if NET6_0_OR_GREATER
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
}
|
||||
@@ -1,10 +1,18 @@
|
||||
using System;
|
||||
#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
|
||||
using System.Runtime.CompilerServices;
|
||||
#endif
|
||||
using ComputeSharp.__Internals;
|
||||
#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
|
||||
using ComputeSharp.Core.Extensions;
|
||||
using ComputeSharp.Shaders.Translation;
|
||||
#else
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
#endif
|
||||
#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
#endif
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
@@ -102,6 +110,11 @@ public static class ReflectionServices
|
||||
private static unsafe void GetNonGenericShaderInfo<T>(in T shader, out ShaderInfo shaderInfo)
|
||||
where T : struct, IShader
|
||||
{
|
||||
#if DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
|
||||
ThrowHelper.ThrowNotSupportedException("Runtime shader compilation is not supported by the current configuration.");
|
||||
|
||||
shaderInfo = default;
|
||||
#else
|
||||
Unsafe.AsRef(in shader).BuildHlslString(out ArrayPoolStringBuilder shaderSource, 1, 1, 1);
|
||||
|
||||
using ComPtr<IDxcBlob> dxcBlobBytecode = ShaderCompiler.Instance.CompileShader(shaderSource.WrittenSpan);
|
||||
@@ -155,5 +168,6 @@ public static class ReflectionServices
|
||||
Unsafe.AsRef(shaderInfo.MovcInstructionCount) = d3D12ShaderReflection.Get()->GetMovcInstructionCount();
|
||||
Unsafe.AsRef(shaderInfo.MovInstructionCount) = d3D12ShaderReflection.Get()->GetMovInstructionCount();
|
||||
Unsafe.AsRef(shaderInfo.InterfaceSlotCount) = d3D12ShaderReflection.Get()->GetNumInterfaceSlots();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@ using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Shaders.Dispatching;
|
||||
using ComputeSharp.Shaders.Extensions;
|
||||
#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
|
||||
using ComputeSharp.Shaders.Translation;
|
||||
#endif
|
||||
using ComputeSharp.Shaders.Translation.Models;
|
||||
using ComputeSharp.__Internals;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
@@ -25,7 +27,7 @@ internal static class ShaderRunner<T>
|
||||
/// <summary>
|
||||
/// The mapping used to cache and reuse compiled shaders.
|
||||
/// </summary>
|
||||
private static readonly Dictionary<ShaderKey, CachedShader> ShadersCache = new();
|
||||
private static readonly Dictionary<ShaderKey, ICachedShader> ShadersCache = new();
|
||||
|
||||
/// <summary>
|
||||
/// Compiles and runs the input shader on a target <see cref="GraphicsDevice"/> instance, with the specified parameters.
|
||||
@@ -129,7 +131,7 @@ internal static class ShaderRunner<T>
|
||||
lock (ShadersCache)
|
||||
{
|
||||
// Get or preload the shader
|
||||
if (!ShadersCache.TryGetValue(key, out CachedShader? shaderData))
|
||||
if (!ShadersCache.TryGetValue(key, out ICachedShader? shaderData))
|
||||
{
|
||||
LoadShader(threadsX, threadsY, threadsZ, ref shader, out shaderData);
|
||||
|
||||
@@ -183,7 +185,7 @@ internal static class ShaderRunner<T>
|
||||
lock (ShadersCache)
|
||||
{
|
||||
// Get or preload the shader
|
||||
if (!ShadersCache.TryGetValue(key, out CachedShader? shaderData))
|
||||
if (!ShadersCache.TryGetValue(key, out ICachedShader? shaderData))
|
||||
{
|
||||
LoadShader(threadsX, threadsY, 1, ref shader, out shaderData);
|
||||
|
||||
@@ -222,27 +224,40 @@ internal static class ShaderRunner<T>
|
||||
/// <param name="threadsY">The number of threads in each thread group for the Y axis.</param>
|
||||
/// <param name="threadsZ">The number of threads in each thread group for the Z axis.</param>
|
||||
/// <param name="shader">The input <typeparamref name="T"/> instance representing the compute shader to run.</param>
|
||||
/// <param name="shaderData">The <see cref="CachedShader"/> instance to return with the cached shader data.</param>
|
||||
/// <param name="shaderData">The <see cref="ICachedShader"/> instance to return with the cached shader data.</param>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static unsafe void LoadShader(int threadsX, int threadsY, int threadsZ, ref T shader, out CachedShader shaderData)
|
||||
private static unsafe void LoadShader(int threadsX, int threadsY, int threadsZ, ref T shader, out ICachedShader shaderData)
|
||||
{
|
||||
shader.BuildHlslString(out ArrayPoolStringBuilder builder, threadsX, threadsY, threadsZ);
|
||||
if (shader.TryGetBytecode(threadsX, threadsY, threadsZ, out ReadOnlySpan<byte> bytecode))
|
||||
{
|
||||
shaderData = new ICachedShader.Embedded(bytecode);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
|
||||
ThrowHelper.ThrowNotSupportedException("Runtime shader compilation is not supported by the current configuration.");
|
||||
|
||||
using ComPtr<IDxcBlob> dxcBlobBytecode = ShaderCompiler.Instance.CompileShader(builder.WrittenSpan);
|
||||
shaderData = null!;
|
||||
#else
|
||||
shader.BuildHlslString(out ArrayPoolStringBuilder builder, threadsX, threadsY, threadsZ);
|
||||
|
||||
builder.Dispose();
|
||||
using ComPtr<IDxcBlob> dxcBlobBytecode = ShaderCompiler.Instance.CompileShader(builder.WrittenSpan);
|
||||
|
||||
shaderData = new CachedShader(dxcBlobBytecode.Get());
|
||||
builder.Dispose();
|
||||
|
||||
shaderData = new ICachedShader.Dynamic(dxcBlobBytecode.Get());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and caches a <see cref="PipelineData"/> instance for a given shader.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> to use to run the shader.</param>
|
||||
/// <param name="shaderData">The <see cref="CachedShader"/> instance with the data on the loaded shader.</param>
|
||||
/// <param name="shaderData">The <see cref="ICachedShader"/> instance with the data on the loaded shader.</param>
|
||||
/// <param name="pipelineData">The resulting <see cref="PipelineData"/> instance to use to run the shader.</param>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static unsafe void CreatePipelineData(GraphicsDevice device, CachedShader shaderData, out PipelineData pipelineData)
|
||||
private static unsafe void CreatePipelineData(GraphicsDevice device, ICachedShader shaderData, out PipelineData pipelineData)
|
||||
{
|
||||
using ComPtr<ID3D12RootSignature> d3D12RootSignature = default;
|
||||
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.Shaders.Translation.Models;
|
||||
|
||||
/// <summary>
|
||||
/// A class that contains info on a cached shader.
|
||||
/// </summary>
|
||||
internal sealed unsafe class CachedShader : NativeObject
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="IDxcBlob"/> instance currently in use.
|
||||
/// </summary>
|
||||
private ComPtr<IDxcBlob> dxcBlobBytecode;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="CachedShader"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="dxcBlobBytecode">The <see cref="IDxcBlob"/> bytecode instance to wrap.</param>
|
||||
public CachedShader(IDxcBlob* dxcBlobBytecode)
|
||||
{
|
||||
this.dxcBlobBytecode = new ComPtr<IDxcBlob>(dxcBlobBytecode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the map of cached <see cref="PipelineData"/> instances for each GPU in use.
|
||||
/// </summary>
|
||||
public ConditionalWeakTable<GraphicsDevice, PipelineData> CachedPipelines { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a raw pointer to the <see cref="IDxcBlob"/> instance in use.
|
||||
/// </summary>
|
||||
public D3D12_SHADER_BYTECODE D3D12ShaderBytecode => new((ID3DBlob*)this.dxcBlobBytecode.Get());
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnDispose()
|
||||
{
|
||||
this.dxcBlobBytecode.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.Shaders.Translation.Models;
|
||||
|
||||
/// <summary>
|
||||
/// An interface that contains info on a cached shader.
|
||||
/// </summary>
|
||||
internal interface ICachedShader
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the map of cached <see cref="PipelineData"/> instances for each GPU in use.
|
||||
/// </summary>
|
||||
ConditionalWeakTable<GraphicsDevice, PipelineData> CachedPipelines { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="D3D12_SHADER_BYTECODE"/> value pointing shader bytecode to use.
|
||||
/// </summary>
|
||||
D3D12_SHADER_BYTECODE D3D12ShaderBytecode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="ICachedShader"/> implementation for an embedded shader.
|
||||
/// </summary>
|
||||
public sealed unsafe class Embedded : ICachedShader
|
||||
{
|
||||
/// <summary>
|
||||
/// The bytecode buffer, if a precompiled shader is used.
|
||||
/// </summary>
|
||||
private readonly byte* precompiledBytecodeBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// The buffer size for <see cref="precompiledBytecodeBuffer"/>, if present.
|
||||
/// </summary>
|
||||
private readonly uint precompiledBytecodeSize;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Embedded"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="precompiledBytecode">The shader bytecode buffer to wrap.</param>
|
||||
/// <remarks>
|
||||
/// It is assumed that <paramref name="precompiledBytecode"/> is a static binary block in the <c>.text</c> segment of the
|
||||
/// PE file, which is what Roslyn generates when directly assigning a new array to a <see cref="ReadOnlySpan{T}"/>. As such,
|
||||
/// the underlying buffer is assumed to be pinned, and it will not be properly tracked for GC compactions. If an invalid
|
||||
/// buffer is passed and its contents are moved, the behavior is undefined (access violations will most definitely occurr).
|
||||
/// </remarks>
|
||||
public Embedded(ReadOnlySpan<byte> precompiledBytecode)
|
||||
{
|
||||
this.precompiledBytecodeBuffer = (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(precompiledBytecode));
|
||||
this.precompiledBytecodeSize = (uint)precompiledBytecode.Length;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ConditionalWeakTable<GraphicsDevice, PipelineData> CachedPipelines { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public D3D12_SHADER_BYTECODE D3D12ShaderBytecode => new(this.precompiledBytecodeBuffer, this.precompiledBytecodeSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="ICachedShader"/> implementation for a dynamically compiled shader.
|
||||
/// </summary>
|
||||
public sealed unsafe class Dynamic : NativeObject, ICachedShader
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="IDxcBlob"/> instance currently in use.
|
||||
/// </summary>
|
||||
private ComPtr<IDxcBlob> dxcBlobBytecode;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Dynamic"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="dxcBlobBytecode">The <see cref="IDxcBlob"/> bytecode instance to wrap.</param>
|
||||
public Dynamic(IDxcBlob* dxcBlobBytecode)
|
||||
{
|
||||
this.dxcBlobBytecode = new ComPtr<IDxcBlob>(dxcBlobBytecode);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ConditionalWeakTable<GraphicsDevice, PipelineData> CachedPipelines { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public D3D12_SHADER_BYTECODE D3D12ShaderBytecode => new ((ID3DBlob*)this.dxcBlobBytecode.Get());
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnDispose()
|
||||
{
|
||||
this.dxcBlobBytecode.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#if NET6_0_OR_GREATER
|
||||
#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT && NET6_0_OR_GREATER
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Core.Extensions;
|
||||
@@ -153,3 +155,5 @@ internal sealed unsafe partial class ShaderCompiler
|
||||
throw new HlslCompilationException(message);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,8 @@
|
||||
// Ported from um/dxcapi.h in the Windows SDK for Windows 10.0.20348.0
|
||||
// Original source is Copyright © Microsoft. All rights reserved. Licensed under the University of Illinois Open Source License.
|
||||
|
||||
#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop.Windows;
|
||||
@@ -15,3 +17,5 @@ namespace TerraFX.Interop.DirectX
|
||||
public static extern HRESULT DxcCreateInstance([NativeTypeName("const IID &")] Guid* rclsid, [NativeTypeName("const IID &")] Guid* riid, [NativeTypeName("LPVOID *")] void** ppv);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -4,6 +4,12 @@
|
||||
<TargetFrameworks>net472;netcoreapp3.1;net6.0</TargetFrameworks>
|
||||
<IsPackable>false</IsPackable>
|
||||
<Platforms>AnyCPU;x64;ARM64</Platforms>
|
||||
<DisableShaderCompilationSupport>false</DisableShaderCompilationSupport>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Define DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT if requested -->
|
||||
<PropertyGroup Condition="'$(DisableShaderCompilationSupport)' == 'true'">
|
||||
<DefineConstants>$(DefineConstants);DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
|
||||
|
||||
using System;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Shaders.Translation;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
@@ -45,3 +47,5 @@ public class ShaderCompilerTests
|
||||
using ComPtr<IDxcBlob> dxcBlob = ShaderCompiler.Instance.CompileShader(faultyShader.AsSpan());
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1399,6 +1399,76 @@ public class DiagnosticsTests
|
||||
VerifyGeneratedDiagnostics<IShaderGenerator>(source, "CMPS0047");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EmbeddedBytecodeWithDynamicShader()
|
||||
{
|
||||
string source = @"
|
||||
using System;
|
||||
using ComputeSharp;
|
||||
|
||||
namespace ComputeSharp
|
||||
{
|
||||
public interface IComputeShader { }
|
||||
public class ReadWriteBuffer<T> { }
|
||||
public class EmbeddedBytecodeAttribute : Attribute { }
|
||||
}
|
||||
|
||||
namespace MyFancyApp.Sample
|
||||
{
|
||||
[EmbeddedBytecode]
|
||||
public struct MyShader : IComputeShader
|
||||
{
|
||||
public ReadWriteBuffer<float> buffer;
|
||||
public Action action;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
VerifyGeneratedDiagnostics<IShaderGenerator>(source, "CMPS0048");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(-1, 1, 1)]
|
||||
[DataRow(1, -1, 1)]
|
||||
[DataRow(1, 1, -1)]
|
||||
[DataRow(1050, 1, 1)]
|
||||
[DataRow(1, 1050, 1)]
|
||||
[DataRow(1, 1, 70)]
|
||||
public void InvalidEmbeddedBytecodeThreadIds(int threadsX, int threadsY, int threadsZ)
|
||||
{
|
||||
string source = $@"
|
||||
using System;
|
||||
using ComputeSharp;
|
||||
|
||||
namespace ComputeSharp
|
||||
{{
|
||||
public interface IComputeShader {{ }}
|
||||
public class ReadWriteBuffer<T> {{ }}
|
||||
public class EmbeddedBytecodeAttribute : Attribute
|
||||
{{
|
||||
public EmbeddedBytecodeAttribute(int threadsX, int threadsY, int threadsZ) {{ }}
|
||||
}}
|
||||
}}
|
||||
|
||||
namespace MyFancyApp.Sample
|
||||
{{
|
||||
[EmbeddedBytecode({threadsX}, {threadsY}, {threadsZ})]
|
||||
public struct MyShader : IComputeShader
|
||||
{{
|
||||
public ReadWriteBuffer<float> buffer;
|
||||
|
||||
public void Execute()
|
||||
{{
|
||||
}}
|
||||
}}
|
||||
}}";
|
||||
|
||||
VerifyGeneratedDiagnostics<IShaderGenerator>(source, "CMPS0049");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the output of a source generator.
|
||||
/// </summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする