Skip to content

Commit 89237ce

Browse files
Copilotphilstopford
andcommitted
Add comprehensive debugging for OpenGL SPIRV compilation and improve Vulkan widget embedding approach
Co-authored-by: philstopford <1983851+philstopford@users.noreply.github.com>
1 parent 34e9dea commit 89237ce

File tree

2 files changed

+58
-9
lines changed

2 files changed

+58
-9
lines changed

Eto/Eto.Veldrid.Gtk/GtkVeldridSurfaceHandler.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,42 @@ private SwapchainSource CreateWaylandSwapchainSource(IntPtr gdkDisplay)
136136

137137
Console.WriteLine($"[DEBUG] DrawingArea state - Visible: {drawingArea.Visible}, Realized: {drawingArea.IsRealized}, Mapped: {drawingArea.IsMapped}, Window.IsVisible: {drawingArea.Window.IsVisible}");
138138

139-
// Get Wayland handles from DrawingArea
139+
// Try to get Wayland handles from DrawingArea without forcing native window creation
140140
var waylandDisplay = X11Interop.gdk_wayland_display_get_wl_display(gdkDisplay);
141141
var waylandSurface = X11Interop.gdk_wayland_window_get_wl_surface(drawingArea.Window.Handle);
142142

143143
if (waylandDisplay == IntPtr.Zero || waylandSurface == IntPtr.Zero)
144144
{
145-
Console.WriteLine("[DEBUG] Failed to get Wayland handles initially, trying native window creation");
146-
// Only create native window as a last resort
147-
X11Interop.gdk_window_ensure_native(drawingArea.Window.Handle);
145+
Console.WriteLine("[DEBUG] Failed to get Wayland handles from DrawingArea, trying parent window");
148146

149-
// Try again after native window creation
150-
waylandDisplay = X11Interop.gdk_wayland_display_get_wl_display(gdkDisplay);
151-
waylandSurface = X11Interop.gdk_wayland_window_get_wl_surface(drawingArea.Window.Handle);
147+
// Try to use the parent window's surface instead of creating a native window
148+
// This should prevent the separate window issue
149+
var topLevelWindow = drawingArea.Toplevel;
150+
if (topLevelWindow?.Window != null)
151+
{
152+
Console.WriteLine("[DEBUG] Trying to use parent window for Wayland surface");
153+
waylandSurface = X11Interop.gdk_wayland_window_get_wl_surface(topLevelWindow.Window.Handle);
154+
155+
if (waylandSurface != IntPtr.Zero)
156+
{
157+
Console.WriteLine("[DEBUG] Successfully got Wayland surface from parent window");
158+
}
159+
}
152160

153161
if (waylandDisplay == IntPtr.Zero || waylandSurface == IntPtr.Zero)
154162
{
155-
throw new InvalidOperationException($"Failed to get Wayland handles even after native window creation - Display: {waylandDisplay}, Surface: {waylandSurface}");
163+
// As a last resort, try native window creation - but this may cause separation
164+
Console.WriteLine("[DEBUG] Still no Wayland handles, reluctantly trying native window creation");
165+
Console.WriteLine("[DEBUG] WARNING: This may cause the viewport to appear as a separate window");
166+
X11Interop.gdk_window_ensure_native(drawingArea.Window.Handle);
167+
168+
waylandDisplay = X11Interop.gdk_wayland_display_get_wl_display(gdkDisplay);
169+
waylandSurface = X11Interop.gdk_wayland_window_get_wl_surface(drawingArea.Window.Handle);
170+
171+
if (waylandDisplay == IntPtr.Zero || waylandSurface == IntPtr.Zero)
172+
{
173+
throw new InvalidOperationException($"Failed to get Wayland handles even after native window creation - Display: {waylandDisplay}, Surface: {waylandSurface}");
174+
}
156175
}
157176
}
158177

Eto/Eto.VeldridSurface/VeldridDriver.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Eto.Veldrid;
22
using System.Numerics;
33
using System.Runtime.InteropServices;
4+
using System.IO;
5+
using System.Linq;
46
using Veldrid;
57
using Veldrid.SPIRV;
68
using VeldridEto;
@@ -49,6 +51,16 @@ public void SetUpVeldrid()
4951

5052
private void CreateResources()
5153
{
54+
// Check if libveldrid-spirv.so is available for SPIRV compilation
55+
bool nativeLibExists = File.Exists("libveldrid-spirv.so");
56+
Console.WriteLine($"[DEBUG] libveldrid-spirv.so exists in current directory: {nativeLibExists}");
57+
if (!nativeLibExists)
58+
{
59+
Console.WriteLine($"[DEBUG] Current directory: {Directory.GetCurrentDirectory()}");
60+
var files = Directory.GetFiles(".", "*.so").Take(5);
61+
Console.WriteLine($"[DEBUG] Available .so files: {string.Join(", ", files)}");
62+
}
63+
5264
// Veldrid.SPIRV is an additional library that complements Veldrid
5365
// by simplifying the development of cross-backend shaders, and is
5466
// currently the recommended approach to doing so:
@@ -115,7 +127,25 @@ private void CreateResources()
115127
Console.WriteLine($"[DEBUG] About to create shaders using CreateFromSpirv for backend: {Surface.GraphicsDevice.BackendType}");
116128
Console.WriteLine($"[DEBUG] ResourceFactory type: {factory.GetType().Name}");
117129

118-
Shader[] shaders = factory.CreateFromSpirv(vertex, fragment, options);
130+
Shader[] shaders;
131+
try
132+
{
133+
shaders = factory.CreateFromSpirv(vertex, fragment, options);
134+
Console.WriteLine($"[DEBUG] Successfully created {shaders.Length} shaders using SPIRV compilation");
135+
}
136+
catch (Exception ex)
137+
{
138+
Console.WriteLine($"[DEBUG] SPIRV shader compilation failed: {ex.GetType().Name}: {ex.Message}");
139+
Console.WriteLine($"[DEBUG] Exception stack trace: {ex.StackTrace}");
140+
141+
// If SPIRV compilation fails, it's likely due to missing native library or GLSL source being treated as SPIRV
142+
Console.WriteLine($"[DEBUG] This error suggests either:");
143+
Console.WriteLine($"[DEBUG] 1. libveldrid-spirv.so is not available or not loadable");
144+
Console.WriteLine($"[DEBUG] 2. GLSL source files are being passed to SPIRV compiler instead of pre-compiled bytecode");
145+
Console.WriteLine($"[DEBUG] 3. The shader files contain invalid GLSL syntax");
146+
147+
throw;
148+
}
119149

120150
ResourceLayout modelMatrixLayout = factory.CreateResourceLayout(
121151
new ResourceLayoutDescription(

0 commit comments

Comments
 (0)