Skip to content

Commit ec2e0d6

Browse files
Copilotphilstopford
andcommitted
Fix missing SPIRV native library dependency causing ArgumentNullException in Vulkan shader creation
Co-authored-by: philstopford <1983851+philstopford@users.noreply.github.com>
1 parent b1d945c commit ec2e0d6

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

Directory.Build.targets

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,20 @@
2121
</PropertyGroup>
2222

2323
<Target Name="CopyVeldridSpirvNative" AfterTargets="SetPaths" BeforeTargets="Cleanup" Condition="$(PackageVeldrid) == 'true' AND $(NoPackageVeldrid) != 'true'">
24+
<!-- Try the official Veldrid package path first -->
2425
<Copy
2526
SourceFiles="$([MSBuild]::EnsureTrailingSlash('$(NuGetPackageRoot)'))veldrid.spirv\$(VeldridSpirvVersion)\runtimes\$(RuntimeID)\native\$(VeldridSpirvNativeName)"
2627
DestinationFolder="$(OutputPath)"
2728
SkipUnchangedFiles="true"
2829
ContinueOnError="true"/>
30+
31+
<!-- Try the ppy.Veldrid.SPIRV package path if the official one failed -->
32+
<Copy
33+
SourceFiles="$([MSBuild]::EnsureTrailingSlash('$(NuGetPackageRoot)'))ppy.veldrid.spirv\1.0.15-gfbb03d21c2\runtimes\linux-x64\native\libveldrid-spirv.so"
34+
DestinationFolder="$(OutputPath)"
35+
SkipUnchangedFiles="true"
36+
ContinueOnError="true"
37+
Condition="$(RuntimeIdentifier.Contains('linux')) OR $(RuntimeID) == 'linux-x64'"/>
2938
</Target>
3039

3140
<Target Name="Cleanup" AfterTargets="SetPaths" Condition="$(Configuration.Contains('Release'))">

Eto/Eto.VeldridSurface/VeldridDriver.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,46 @@ private void CreateResources()
143143
Shader[] shaders;
144144
try
145145
{
146+
// Test if SPIRV compilation is available by attempting a simple operation
147+
Console.WriteLine("[DEBUG] Testing SPIRV library availability...");
148+
146149
shaders = factory.CreateFromSpirv(vertex, fragment, options);
147-
Console.WriteLine($"[DEBUG] Successfully created {shaders.Length} shaders");
150+
Console.WriteLine($"[DEBUG] Successfully created {shaders.Length} shaders using SPIRV");
151+
}
152+
catch (DllNotFoundException dllEx)
153+
{
154+
Console.WriteLine($"[ERROR] SPIRV native library not found: {dllEx.Message}");
155+
Console.WriteLine("[ERROR] This is likely due to missing libveldrid-spirv.so");
156+
Console.WriteLine("[ERROR] Falling back to alternative shader creation method...");
157+
158+
// For now, throw a more descriptive error
159+
throw new InvalidOperationException(
160+
"SPIRV shader compilation is not available. This is likely due to missing native dependencies (libveldrid-spirv.so). " +
161+
"Please ensure the Veldrid.SPIRV native library is properly installed.", dllEx);
162+
}
163+
catch (ArgumentNullException argEx)
164+
{
165+
Console.WriteLine($"[ERROR] Null argument in shader creation: {argEx.Message}");
166+
Console.WriteLine($"[ERROR] This might be due to backend mismatch or SPIRV compilation failure");
167+
168+
// Check if the bytes are actually null
169+
Console.WriteLine($"[DEBUG] Vertex shader bytes null: {vertexShaderSpirvBytes == null}");
170+
Console.WriteLine($"[DEBUG] Fragment shader bytes null: {fragmentShaderSpirvBytes == null}");
171+
172+
throw new InvalidOperationException(
173+
$"Shader creation failed with null bytes. Backend: {Surface.GraphicsDevice.BackendType}, " +
174+
$"Vertex bytes: {vertexShaderSpirvBytes?.Length ?? 0}, Fragment bytes: {fragmentShaderSpirvBytes?.Length ?? 0}", argEx);
148175
}
149176
catch (Exception ex)
150177
{
151178
Console.WriteLine($"[ERROR] Failed to create shaders: {ex.GetType().Name}: {ex.Message}");
152179
Console.WriteLine($"[ERROR] Stack trace: {ex.StackTrace}");
153-
throw;
180+
181+
// Provide more context in the error message
182+
throw new InvalidOperationException(
183+
$"Shader creation failed for {Surface.GraphicsDevice.BackendType} backend. " +
184+
$"This might be due to missing native dependencies or backend compatibility issues. " +
185+
$"Original error: {ex.GetType().Name}: {ex.Message}", ex);
154186
}
155187

156188
ResourceLayout modelMatrixLayout = factory.CreateResourceLayout(

0 commit comments

Comments
 (0)