@@ -49,26 +49,6 @@ public void SetUpVeldrid()
4949
5050 private void CreateResources ( )
5151 {
52- // Check if swapchain is available - if not, defer resource creation
53- if ( Surface ? . Swapchain == null )
54- {
55- Console . WriteLine ( "[DEBUG] Swapchain not available yet, deferring resource creation" ) ;
56- // For Wayland systems, the swapchain might not be available immediately
57- // This is normal and expected - we'll retry when VeldridInitialized is called again
58- return ;
59- }
60-
61- // Add debugging for graphics device backend
62- Console . WriteLine ( $ "[DEBUG] Graphics device backend type: { Surface . GraphicsDevice ? . BackendType } ") ;
63- Console . WriteLine ( $ "[DEBUG] Expected backend type: { Surface . Backend } ") ;
64-
65- // Check for backend mismatch
66- if ( Surface . GraphicsDevice ? . BackendType != Surface . Backend )
67- {
68- Console . WriteLine ( $ "[ERROR] Backend mismatch! Expected: { Surface . Backend } , Got: { Surface . GraphicsDevice ? . BackendType } ") ;
69- throw new InvalidOperationException ( $ "Graphics device backend mismatch. Expected: { Surface . Backend } , Got: { Surface . GraphicsDevice ? . BackendType } ") ;
70- }
71-
7252 // Veldrid.SPIRV is an additional library that complements Veldrid
7353 // by simplifying the development of cross-backend shaders, and is
7454 // currently the recommended approach to doing so:
@@ -81,14 +61,6 @@ private void CreateResources()
8161 byte [ ] vertexShaderSpirvBytes = LoadSpirvBytes ( ShaderStages . Vertex ) ;
8262 byte [ ] fragmentShaderSpirvBytes = LoadSpirvBytes ( ShaderStages . Fragment ) ;
8363
84- Console . WriteLine ( $ "[DEBUG] Vertex shader bytes loaded: { vertexShaderSpirvBytes ? . Length ?? 0 } bytes") ;
85- Console . WriteLine ( $ "[DEBUG] Fragment shader bytes loaded: { fragmentShaderSpirvBytes ? . Length ?? 0 } bytes") ;
86-
87- if ( vertexShaderSpirvBytes == null || fragmentShaderSpirvBytes == null )
88- {
89- throw new InvalidOperationException ( "Failed to load shader bytecode" ) ;
90- }
91-
9264 CrossCompileOptions ? options = new ( ) ;
9365 switch ( Surface ! . GraphicsDevice ! . BackendType )
9466 {
@@ -136,54 +108,7 @@ private void CreateResources()
136108
137109 ShaderDescription vertex = new ( ShaderStages . Vertex , vertexShaderSpirvBytes , "main" , true ) ;
138110 ShaderDescription fragment = new ( ShaderStages . Fragment , fragmentShaderSpirvBytes , "main" , true ) ;
139-
140- Console . WriteLine ( $ "[DEBUG] About to create shaders using CreateFromSpirv for backend: { Surface . GraphicsDevice . BackendType } ") ;
141- Console . WriteLine ( $ "[DEBUG] ResourceFactory type: { factory . GetType ( ) . FullName } ") ;
142-
143- Shader [ ] shaders ;
144- try
145- {
146- // Test if SPIRV compilation is available by attempting a simple operation
147- Console . WriteLine ( "[DEBUG] Testing SPIRV library availability..." ) ;
148-
149- shaders = factory . CreateFromSpirv ( vertex , fragment , options ) ;
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 ) ;
175- }
176- catch ( Exception ex )
177- {
178- Console . WriteLine ( $ "[ERROR] Failed to create shaders: { ex . GetType ( ) . Name } : { ex . Message } ") ;
179- Console . WriteLine ( $ "[ERROR] Stack trace: { ex . StackTrace } ") ;
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 ) ;
186- }
111+ Shader [ ] shaders = factory . CreateFromSpirv ( vertex , fragment , options ) ;
187112
188113 ResourceLayout modelMatrixLayout = factory . CreateResourceLayout (
189114 new ResourceLayoutDescription (
@@ -218,23 +143,6 @@ private void CreateResources()
218143 create_pipelines ( ref factory , ref viewMatrixLayout , ref modelMatrixLayout , ref shaders , ref vertexLayout ) ;
219144
220145 CommandList = factory . CreateCommandList ( ) ;
221-
222- // VeldridDriver resources successfully created - no debug message needed
223- }
224-
225- public void CompleteResourceCreation ( )
226- {
227- // This method can be called when the swapchain becomes available
228- // to complete resource creation that was deferred
229- if ( Surface ? . Swapchain != null && ! Ready )
230- {
231- Console . WriteLine ( "[DEBUG] Completing deferred VeldridDriver resource creation" ) ;
232- CreateResources ( ) ;
233- if ( CommandList != null )
234- {
235- Ready = true ;
236- }
237- }
238146 }
239147
240148 private void create_pipelines ( ref ResourceFactory factory , ref ResourceLayout viewMatrixLayout ,
@@ -309,30 +217,16 @@ private byte[] LoadSpirvBytes(ShaderStages stage)
309217 string name = $ "VertexColor-{ stage . ToString ( ) . ToLowerInvariant ( ) } .450.glsl";
310218 string full = $ "Eto.VeldridSurface.shaders.{ name } ";
311219
312- Console . WriteLine ( $ "[DEBUG] Loading shader: { name } from resource: { full } ") ;
313-
314220 // Precompiled SPIR-V bytecode can speed up program start by saving
315221 // the need to load text files and compile them before converting
316222 // the result to the final backend shader format. If they're not
317223 // available, though, the plain .glsl files will do just fine. Look
318224 // up glslangValidator to learn how to compile SPIR-V binary files.
319225
320226 using ( Stream ? stream = GetType ( ) . Assembly . GetManifestResourceStream ( full ) )
227+ using ( BinaryReader ? reader = new ( stream ! ) )
321228 {
322- if ( stream == null )
323- {
324- Console . WriteLine ( $ "[ERROR] Could not find shader resource: { full } ") ;
325- throw new InvalidOperationException ( $ "Could not find shader resource: { full } ") ;
326- }
327-
328- Console . WriteLine ( $ "[DEBUG] Shader resource found, length: { stream . Length } bytes") ;
329-
330- using ( BinaryReader ? reader = new ( stream ) )
331- {
332- byte [ ] result = reader . ReadBytes ( ( int ) stream . Length ) ;
333- Console . WriteLine ( $ "[DEBUG] Successfully loaded { result . Length } bytes for { stage } shader") ;
334- return result ;
335- }
229+ return reader . ReadBytes ( ( int ) stream ! . Length ) ;
336230 }
337231 }
338232 }
0 commit comments