From 2fdbdafab8b2ba6fddd37f2b9548f25698f730e8 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 23 May 2022 14:31:07 +0200 Subject: [PATCH] Improve D2D1CompileOptions handling in LoadBytecode APIs --- .../Shaders/Interop/D2D1PixelShader.cs | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs index 644f16c7..1ca9843d 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs @@ -63,8 +63,12 @@ public static class D2D1PixelShader /// Loads the bytecode from an input D2D1 pixel shader. /// /// The type of D2D1 pixel shader to load the bytecode for. - /// The compile options to use to get the shader bytecode. + /// + /// The compile options to use to get the shader bytecode. + /// For consistency with , will be automatically added. + /// /// A instance with the resulting shader bytecode. + /// Thrown if is specified within . /// /// /// If precompiled shader with the requested options does not exist, the shader will be compiled with the input options. If additional compile @@ -81,7 +85,12 @@ public static class D2D1PixelShader public static ReadOnlyMemory LoadBytecode(D2D1CompileOptions options) where T : unmanaged, ID2D1PixelShader { - return LoadOrCompileBytecode(null, options); + if ((options & D2D1CompileOptions.PackMatrixColumnMajor) != 0) + { + ThrowHelper.ThrowArgumentException(nameof(options), "The PackMatrixColumnMajor compile options is not compatible with ComputeSharp.D2D1 shaders."); + } + + return LoadOrCompileBytecode(null, options | D2D1CompileOptions.PackMatrixRowMajor); } /// @@ -89,8 +98,12 @@ public static class D2D1PixelShader /// /// The type of D2D1 pixel shader to load the bytecode for. /// The shader profile to use to get the shader bytecode. - /// The compile options to use to get the shader bytecode. + /// + /// The compile options to use to get the shader bytecode. + /// For consistency with , will be automatically added. + /// /// A instance with the resulting shader bytecode. + /// Thrown if is specified within . /// /// If the input shader was precompiled, the returned instance will wrap a pinned memory buffer (from the PE section). /// If the shader was compiled at runtime, the returned instance will wrap a array with the bytecode. @@ -98,7 +111,12 @@ public static class D2D1PixelShader public static ReadOnlyMemory LoadBytecode(D2D1ShaderProfile shaderProfile, D2D1CompileOptions options) where T : unmanaged, ID2D1PixelShader { - return LoadOrCompileBytecode(shaderProfile, options); + if ((options & D2D1CompileOptions.PackMatrixColumnMajor) != 0) + { + ThrowHelper.ThrowArgumentException(nameof(options), "The PackMatrixColumnMajor compile options is not compatible with ComputeSharp.D2D1 shaders."); + } + + return LoadOrCompileBytecode(shaderProfile, options | D2D1CompileOptions.PackMatrixRowMajor); } ///