Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shaders are compiled at runtime despite having [D2DEmbeddedBytecode(...)] #282

Closed
rickbrew opened this issue May 23, 2022 · 1 comment · Fixed by #283
Closed

Shaders are compiled at runtime despite having [D2DEmbeddedBytecode(...)] #282

rickbrew opened this issue May 23, 2022 · 1 comment · Fixed by #283
Labels
bug 🐛 Something isn't working

Comments

@rickbrew
Copy link
Collaborator

This is from the latest alpha off the public nuget feed, not the nightly build.

This seems to be affecting all of my shaders, at least on ARM64. I don't know if they're being compiled at runtime on x64. I ran into this crash that is due to dotnet/wpf#5462, which I can fix by just not packaging D3DCompiler_47.dll with my app (I don't need it since I'm targeting Win10+). But, with the crash gone, why are the shaders being compiled at runtime? 🤔

Here's one of the shaders:

[D2DInputCount(3)]
[D2DInputSimple(0)]
[D2DInputDescription(0, D2D1Filter.MinMagMipPoint)]
[D2DInputSimple(1)]
[D2DInputDescription(1, D2D1Filter.MinMagMipPoint)]
[D2DInputSimple(2)]
[D2DInputDescription(2, D2D1Filter.MinMagMipPoint)]
[D2DPixelOptions(D2D1PixelOptions.TrivialSampling)]
[D2DEmbeddedBytecode(D2D1ShaderProfile.PixelShader40Level91)]
private readonly partial struct OverwriteCompositeShader
    : IPixelShader<OverwriteCompositeShader>
{
    static IPixelShaderTransformImpl IPixelShader<OverwriteCompositeShader>.CreateTransform(in OverwriteCompositeShader shader)
    {
        return PixelShaderTransforms.CreateDefault(shader);
    }

    public float4 Execute()
    {
        float4 dst = D2D.GetInput(0);
        float4 src = D2D.GetInput(1);
        float4 srcMask = D2D.GetInput(2);
        float4 result = ((1 - srcMask) * dst) + (srcMask * src);
        return result;
    }
}

And here's the exception I'm getting, which I had to snag by hooking AppDomain.FirstChanceException :

Exception details:
System.TypeInitializationException: The type initializer for 'ShaderCacheHelper`1' threw an exception.
 ---> System.EntryPointNotFoundException: Unable to find an entry point named 'D3DCompile' in DLL 'd3dcompiler_47'.
   at TerraFX.Interop.DirectX.DirectX.D3DCompile(Void* , UIntPtr , SByte* , D3D_SHADER_MACRO* , Void* , SByte* , SByte* , UInt32 , UInt32 , ID3DBlob** , ID3DBlob** )
   at ComputeSharp.D2D1.Shaders.Translation.D2D1ShaderCompiler.CompileD2DFullShader(ReadOnlySpan`1 , D2D1ShaderProfile )
   at ComputeSharp.D2D1.Shaders.Translation.D2D1ShaderCompiler.Compile(ReadOnlySpan`1 , D2D1ShaderProfile , Boolean )
   at ComputeSharp.D2D1.__Internals.D2D1ShaderCompiler.LoadDynamicBytecode[TLoader,T](TLoader& , T& , Nullable`1 , Boolean )
   at PaintDotNet.Direct2D1.Effects.OverwriteCompositeEffect.OverwriteCompositeShader.global::ComputeSharp.D2D1.__Internals.ID2D1Shader.LoadBytecode[TLoader](TLoader& loader, Nullable`1 shaderProfile) in D:\src\pdn\src\Windows.Framework\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.ID2D1ShaderGenerator\PaintDotNet.Direct2D1.Effects.OverwriteCompositeEffect.OverwriteCompositeShader.LoadBytecode.cs:line 21
   at ComputeSharp.D2D1.Interop.D2D1ReflectionServices.GetShaderInfo[T]()
   at PaintDotNet.Direct2D1.Effects.D2D1PixelShaderUtil.ShaderCacheHelper`1..cctor() in D:\src\pdn\src\Windows.Framework\Direct2D1\Effects\D2D1PixelShaderUtil.cs:line 54
   --- End of inner exception stack trace ---
   at PaintDotNet.Direct2D1.Effects.D2D1PixelShaderUtil.GetCachedInputDescriptions[TShader]() in D:\src\pdn\src\Windows.Framework\Direct2D1\Effects\D2D1PixelShaderUtil.cs:line 21
@rickbrew rickbrew added bug 🐛 Something isn't working untriaged 🧰 A new issue that needs initial triage labels May 23, 2022
@Sergio0694 Sergio0694 removed the untriaged 🧰 A new issue that needs initial triage label May 23, 2022
@Sergio0694
Copy link
Owner

Yeah pretty sure I've fixed this already (IIRC it was some flags being passed wrong which re-triggered the build), though I can find the exact commit where I fixed that right now. I've opened #283 to add more tests to ensure we can spot regressions 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants