Invert and improve logic for IsShaderSupported API
このコミットが含まれているのは:
1 親
960db097e1
コミット
64be81e56f
3ファイル変更
+40
-25
検索条件に一致するファイルはありません
+2
-1
@@ -96,7 +96,8 @@ 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 && !effectContext->IsShaderNotSupported(@this->bytecode, @this->bytecodeSize))
|
||||
// If any error is detected while trying to check for shader support, ignore the value and propagate the current HRESULT.
|
||||
if (hresult == E.E_INVALIDARG && effectContext->IsShaderSupported(@this->bytecode, @this->bytecodeSize) == S.S_FALSE)
|
||||
{
|
||||
hresult = D2DERR.D2DERR_INSUFFICIENT_DEVICE_CAPABILITIES;
|
||||
}
|
||||
|
||||
+1
-1
@@ -113,7 +113,7 @@ partial struct D2D1ResourceTextureManagerImpl
|
||||
{
|
||||
using ComPtr<ID2D1Multithread> d2D1Multithread = default;
|
||||
|
||||
int hresult = effectContext->GetD2D1Multithread(d2D1Multithread.GetAddressOf());
|
||||
HRESULT hresult = effectContext->GetD2D1Multithread(d2D1Multithread.GetAddressOf());
|
||||
|
||||
// If an ID2D1Multithread object is available, we can safely store the context. That
|
||||
// is, under the condition that the required multithread support is also available.
|
||||
|
||||
@@ -38,7 +38,7 @@ internal static unsafe class ID2D1EffectContextExtensions
|
||||
/// be cast to <see cref="ID2D1Multithread"/>, which can then be kept and used to synchronize later calls.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public static int GetD2D1Multithread(this ref ID2D1EffectContext effectContext, ID2D1Multithread** multithread)
|
||||
public static HRESULT GetD2D1Multithread(this ref ID2D1EffectContext effectContext, ID2D1Multithread** multithread)
|
||||
{
|
||||
using ComPtr<ID2D1Effect> floodEffect = default;
|
||||
|
||||
@@ -66,73 +66,87 @@ internal static unsafe class ID2D1EffectContextExtensions
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the input shader is not supported by the target <see cref="ID2D1EffectContext"/> instance.
|
||||
/// Checks whether the input shader is 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>
|
||||
/// <returns>
|
||||
/// The <see cref="HRESULT"/> for the operation:
|
||||
/// <list type="bullet">
|
||||
/// <item><see cref="S.S_OK"/>: the shader is supported.</item>
|
||||
/// <item><see cref="S.S_FALSE"/>: the shader is not supported.</item>
|
||||
/// <item>Any other <see cref="HRESULT"/>: an error occurred while checking the shader support.</item>
|
||||
/// </list>
|
||||
/// </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)
|
||||
public static HRESULT IsShaderSupported(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(
|
||||
// Create the reflection instance to extract the shader info
|
||||
HRESULT hresult = DirectX.D3DReflect(
|
||||
pSrcData: bytecode,
|
||||
SrcDataSize: (uint)bytecodeSize,
|
||||
pInterface: Windows.__uuidof<ID3D11ShaderReflection>(),
|
||||
ppReflector: d3D11ShaderReflection.GetVoidAddressOf())))
|
||||
ppReflector: d3D11ShaderReflection.GetVoidAddressOf());
|
||||
|
||||
if (!Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
return false;
|
||||
return hresult;
|
||||
}
|
||||
|
||||
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)))
|
||||
// Get the minimum feature level for the shader
|
||||
hresult = d3D11ShaderReflection.Get()->GetMinFeatureLevel(&d3DMinFeatureLevel);
|
||||
|
||||
if (!Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
return false;
|
||||
return hresult;
|
||||
}
|
||||
|
||||
D3D_FEATURE_LEVEL d3DMaxFeatureLevel;
|
||||
|
||||
// Check whether the current context supports the minimum feature level
|
||||
HRESULT hresultMaximumSupportedFeatureLevel = effectContext.GetMaximumSupportedFeatureLevel(
|
||||
hresult = 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)
|
||||
if (hresult == D2DERR.D2DERR_INSUFFICIENT_DEVICE_CAPABILITIES)
|
||||
{
|
||||
return true;
|
||||
return S.S_FALSE;
|
||||
}
|
||||
|
||||
// If the call failed for another reason, also just stop here and return the previous result
|
||||
if (!Windows.SUCCEEDED(hresultMaximumSupportedFeatureLevel))
|
||||
// If the call failed for any other reason, stop here like before
|
||||
if (!Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
return false;
|
||||
return hresult;
|
||||
}
|
||||
|
||||
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))))
|
||||
// Check the feature support for the effect context in use
|
||||
hresult = effectContext.CheckFeatureSupport(D2D1_FEATURE.D2D1_FEATURE_DOUBLES, &d2D1FeatureDataDoubles, (uint)sizeof(D2D1_FEATURE_DATA_DOUBLES));
|
||||
|
||||
if (!Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
return false;
|
||||
return hresult;
|
||||
}
|
||||
|
||||
// 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 the shader requires double precision support, the shader is not supported
|
||||
if ((d3D11ShaderReflection.Get()->GetRequiresFlags() & (D3D.D3D_SHADER_REQUIRES_DOUBLES | D3D.D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS)) != 0)
|
||||
{
|
||||
return true;
|
||||
return S.S_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
// All calls succeeded and no unsupported feature was detected, so assume the shader is supported
|
||||
return S.S_OK;
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする