gfx-rs / gfx

[maintenance mode] A low-overhead Vulkan-like GPU API for Rust.
http://gfx-rs.github.io/
Apache License 2.0
5.35k stars 549 forks source link

gfx_backend_gl: Shader compilation error: illegal use of reserved word 'readonly' #3562

Closed torokati44 closed 3 years ago

torokati44 commented 3 years ago

Short info header:

I am once again trying to run Ruffle with the OpenGL backend. On startup I get this error:

[2021-01-04T15:51:14Z DEBUG gfx_backend_gl::device] SPIR-V options CompilerOptions { version: V3_00Es, force_temporary: false, vulkan_seman
tics: false, separate_shader_objects: false, flatten_multidimensional_arrays: false, enable_420_pack_extension: true, emit_push_constant_as
_uniform_buffer: false, emit_uniform_buffer_as_plain_uniforms: false, emit_line_directives: false, enable_storage_image_qualifier_deduction
: true, force_zero_initialized_variables: true, vertex: CompilerVertexOptions { invert_y: false, transform_clip_space: false, support_nonze
ro_base_instance: true }, fragment: CompilerFragmentOptions { default_float_precision: Medium, default_int_precision: High }, entry_point: 
Some(("main", Fragment)) }
[2021-01-04T15:51:14Z DEBUG gfx_backend_gl::device] SPIRV-Cross generated shader: <see gist>

https://gist.github.com/torokati44/a0404ee80f99645fe2242a00a68b97ec

[2021-01-04T15:51:14Z INFO  gfx_backend_gl::device]     Compiled shader 27
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: CompilationFailed("0:5(16): error: illegal use of reserved word `readonly\'\n0:5(16): error: syntax error, unexpected ERROR_TOK\n")', /home/attila/.cargo/git/checkouts/gfx-e86e7f3ebdbc4218/0244e34/src/backend/gl/src/device.rs:560:61
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:483
   1: core::panicking::panic_fmt
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:85
   2: core::option::expect_none_failed
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/option.rs:1234
   3: gfx_backend_gl::device::Device::compile_shader
   4: gfx_backend_gl::device::Device::create_shader_program
   5: <gfx_backend_gl::device::Device as gfx_hal::device::Device<gfx_backend_gl::Backend>>::create_graphics_pipeline
   6: wgpu_core::device::Device<B>::create_render_pipeline
   7: wgpu_core::device::<impl wgpu_core::hub::Global<G>>::device_create_render_pipeline
   8: <wgpu::backend::direct::Context as wgpu::Context>::device_create_render_pipeline
   9: wgpu::Device::create_render_pipeline
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Aborted (core dumped)

Running with the Vulkan backend works flawlessly.

kvark commented 3 years ago

Are you using storage buffers/textures? The backend uses GLES 3.0 target (V3_00Es), which needs to be fixed.

torokati44 commented 3 years ago

To be honest, I'm not familiar with the rendering internals of Ruffle, so I can't really tell, I'm just seeing this symptom.

torokati44 commented 3 years ago

However, since the generated shader indeed appears to be invalid, could this be an issue with SPIRV-Cross itself? Or just with the way it is invoked?

kvark commented 3 years ago

I think it's the same issue as was blocking our compute example to run on GL - https://github.com/grovesNL/spirv_cross/issues/159 Now that it's addressed, we can update the GL backend and select the proper version.

kvark commented 3 years ago

Code is meant to go here - https://github.com/gfx-rs/gfx/blob/9428cf7fbf27472a3809188eb24fd3812882d735/src/backend/gl/src/device.rs#L293 Would you be interested in making this PR?

torokati44 commented 3 years ago

Sure... I'm just trying to figure out how to make cargo use a locally updated version of a single (indirect) dependency throughout the whole project, so I can test it first. EDIT: I think this part is kinda working now.

torokati44 commented 3 years ago

Why is there both a (3, 20) .. (4, 30) version tuple format and a (3, 2) .. (4, 3) as well, all over the place? :thinking:

kvark commented 3 years ago

possibly a mistake! beware, and see if it needs fixing, please