Minor code refactoring

このコミットが含まれているのは:
Sergio Pedri committed 2022-10-21 05:45:43 -07:00
1 親 ca7e001bd6
コミット a27c8e0205
2ファイル変更
+77 -61

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

@@ -1,7 +1,7 @@
using System;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1.Extensions;
using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
using ComputeSharp.D2D1.Shaders.Interop.Extensions;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
#if !NET6_0_OR_GREATER
@@ -96,65 +96,9 @@ internal unsafe partial struct PixelShaderEffect
// If E_INVALIDARG was returned, try to check whether double precision support was requested when not available. This
// is only done to provide a more helpful error message to callers. If no error was returned, the behavior is the same.
if (hresult == E.E_INVALIDARG)
if (hresult == E.E_INVALIDARG && !effectContext->IsShaderNotSupported(@this->bytecode, @this->bytecodeSize))
{
using ComPtr<ID3D11ShaderReflection> d3D11ShaderReflection = default;
// Create the reflection instance, and in case of error just return the previous error like above
if (!Windows.SUCCEEDED(DirectX.D3DReflect(
pSrcData: @this->bytecode,
SrcDataSize: (uint)@this->bytecodeSize,
pInterface: Windows.__uuidof<ID3D11ShaderReflection>(),
ppReflector: d3D11ShaderReflection.GetVoidAddressOf())))
{
return E.E_INVALIDARG;
}
D3D_FEATURE_LEVEL d3DMinFeatureLevel;
// Get the minimum feature level for the shader (in case of errors, just return the previous result again)
if (!Windows.SUCCEEDED(d3D11ShaderReflection.Get()->GetMinFeatureLevel(&d3DMinFeatureLevel)))
{
return E.E_INVALIDARG;
}
D3D_FEATURE_LEVEL d3DMaxFeatureLevel;
// Check whether the current context supports the minimum feature level
HRESULT hresultMaximumSupportedFeatureLevel = effectContext->GetMaximumSupportedFeatureLevel(
featureLevels: &d3DMinFeatureLevel,
featureLevelsCount: 1,
maximumSupportedFeatureLevel: &d3DMaxFeatureLevel);
// If the context doesn't match the required feature level, return that as an error
if (hresultMaximumSupportedFeatureLevel == D2DERR.D2DERR_INSUFFICIENT_DEVICE_CAPABILITIES)
{
return D2DERR.D2DERR_INSUFFICIENT_DEVICE_CAPABILITIES;
}
// If the call failed for another reason, also just stop here and return the previous result
if (!Windows.SUCCEEDED(hresultMaximumSupportedFeatureLevel))
{
return E.E_INVALIDARG;
}
D2D1_FEATURE_DATA_DOUBLES d2D1FeatureDataDoubles = default;
// If the call failed, just do nothing and return the previous result
if (!Windows.SUCCEEDED(effectContext->CheckFeatureSupport(D2D1_FEATURE.D2D1_FEATURE_DOUBLES, &d2D1FeatureDataDoubles, (uint)sizeof(D2D1_FEATURE_DATA_DOUBLES))))
{
return E.E_INVALIDARG;
}
// If the context does not support double precision values, check whether the shader requested them
if (d2D1FeatureDataDoubles.doublePrecisionFloatShaderOps == 0)
{
// If the shader requires double precision support, return a more descriptive error
if ((d3D11ShaderReflection.Get()->GetRequiresFlags() & (D3D.D3D_SHADER_REQUIRES_DOUBLES | D3D.D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS)) != 0)
{
return D2DERR.D2DERR_INSUFFICIENT_DEVICE_CAPABILITIES;
}
}
hresult = D2DERR.D2DERR_INSUFFICIENT_DEVICE_CAPABILITIES;
}
// If loading the bytecode succeeded, set the transform node
+74 -2
ファイルの表示
@@ -1,5 +1,6 @@
using System;
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1.Extensions;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
@@ -8,7 +9,7 @@ namespace ComputeSharp.D2D1.Shaders.Interop.Extensions;
/// <summary>
/// Extensions for the <see cref="ID2D1Multithread"/> type.
/// </summary>
internal static class ID2D1EffectContextExtensions
internal static unsafe class ID2D1EffectContextExtensions
{
/// <summary>
/// Gets an <see cref="ID2D1Multithread"/> from an input <see cref="ID2D1EffectContext"/> object.
@@ -37,7 +38,7 @@ internal static class ID2D1EffectContextExtensions
/// be cast to <see cref="ID2D1Multithread"/>, which can then be kept and used to synchronize later calls.
/// </para>
/// </remarks>
public static unsafe int GetD2D1Multithread(this ref ID2D1EffectContext effectContext, ID2D1Multithread** multithread)
public static int GetD2D1Multithread(this ref ID2D1EffectContext effectContext, ID2D1Multithread** multithread)
{
using ComPtr<ID2D1Effect> floodEffect = default;
@@ -63,4 +64,75 @@ internal static class ID2D1EffectContextExtensions
return hresult;
}
/// <summary>
/// Checks whether the input shader is not supported by the target <see cref="ID2D1EffectContext"/> instance.
/// </summary>
/// <param name="effectContext">The input <see cref="ID2D1EffectContext"/> instance.</param>
/// <param name="bytecode">The shader bytecode.</param>
/// <param name="bytecodeSize">The size of <paramref name="bytecode"/>.</param>
/// <returns>Whether the shader is not supported.</returns>
/// <remarks>If any calls needed to check support fail, the method will also return <see langword="false"/>.</remarks>
public static bool IsShaderNotSupported(this ref ID2D1EffectContext effectContext, byte* bytecode, int bytecodeSize)
{
using ComPtr<ID3D11ShaderReflection> d3D11ShaderReflection = default;
// Create the reflection instance, and in case of error just return the previous error like above
if (!Windows.SUCCEEDED(DirectX.D3DReflect(
pSrcData: bytecode,
SrcDataSize: (uint)bytecodeSize,
pInterface: Windows.__uuidof<ID3D11ShaderReflection>(),
ppReflector: d3D11ShaderReflection.GetVoidAddressOf())))
{
return false;
}
D3D_FEATURE_LEVEL d3DMinFeatureLevel;
// Get the minimum feature level for the shader (in case of errors, just return the previous result again)
if (!Windows.SUCCEEDED(d3D11ShaderReflection.Get()->GetMinFeatureLevel(&d3DMinFeatureLevel)))
{
return false;
}
D3D_FEATURE_LEVEL d3DMaxFeatureLevel;
// Check whether the current context supports the minimum feature level
HRESULT hresultMaximumSupportedFeatureLevel = effectContext.GetMaximumSupportedFeatureLevel(
featureLevels: &d3DMinFeatureLevel,
featureLevelsCount: 1,
maximumSupportedFeatureLevel: &d3DMaxFeatureLevel);
// If the context doesn't match the required feature level, return that as an error
if (hresultMaximumSupportedFeatureLevel == D2DERR.D2DERR_INSUFFICIENT_DEVICE_CAPABILITIES)
{
return true;
}
// If the call failed for another reason, also just stop here and return the previous result
if (!Windows.SUCCEEDED(hresultMaximumSupportedFeatureLevel))
{
return false;
}
D2D1_FEATURE_DATA_DOUBLES d2D1FeatureDataDoubles = default;
// If the call failed, just do nothing and return the previous result
if (!Windows.SUCCEEDED(effectContext.CheckFeatureSupport(D2D1_FEATURE.D2D1_FEATURE_DOUBLES, &d2D1FeatureDataDoubles, (uint)sizeof(D2D1_FEATURE_DATA_DOUBLES))))
{
return false;
}
// If the context does not support double precision values, check whether the shader requested them
if (d2D1FeatureDataDoubles.doublePrecisionFloatShaderOps == 0)
{
// If the shader requires double precision support, return a more descriptive error
if ((d3D11ShaderReflection.Get()->GetRequiresFlags() & (D3D.D3D_SHADER_REQUIRES_DOUBLES | D3D.D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS)) != 0)
{
return true;
}
}
return false;
}
}