Repository: glium/glium (language: rust)

Issue:
gpgpu example reports GL_INVALID_OPERATION
I'm trying to run the GPGPU example and while the output *looks* correct, I get two debug messages that say the following. Are they important or can I ignore them, and is there a way to fix them?

```
Debug message with high or medium severity: `GL_INVALID_OPERATION in glGetProgramStageiv`.
Please report this error: https://github.com/tomaka/glium/issues
Backtrace:
   1 - 0x560d20924506
         _ZN9backtrace9backtrace9libunwind5trace17hd30c041716104ea8E at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.13/src/backtrace/libunwind.rs:52
         _ZN9backtrace9backtrace20trace_unsynchronized17h69454b7084e02f09E at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.13/src/backtrace/mod.rs:57
   2 - 0x560d208b1d94
         _ZN9backtrace9backtrace5trace17h796329675076027dE at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.13/src/backtrace/mod.rs:47
         _ZN5glium7context22default_debug_callback17hfd175c526bdb0bf0E at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/glium-0.23.0/src/context/mod.rs:854
   3 - 0x560d2091a014
         _ZN4core3ops8function5FnMut8call_mut17h31b4262547d52346E at libcore/ops/function.rs:156
   4 - 0x560d208b30f4
         _ZN5glium7context19init_debug_callback16callback_wrapper17hb8433b4ab7b6c86bE at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/glium-0.23.0/src/context/mod.rs:941
   5 - 0x7f924105c9f8
         <unknown> at <unknown>:??
   6 - 0x560d209a8e6c
         _ZN5glium2gl2Gl17GetProgramStageiv17h650718f336a3ce01E at /home/frans/Documents/rust/gpgpu/target/debug/build/glium-911ed9a1ecb91ed8/out/gl_bindings.rs:6846
   7 - 0x560d2089865c
         _ZN5glium7program10reflection23reflect_subroutine_data17h7c049c609b61b9b8E at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/glium-0.23.0/src/program/reflection.rs:1176
   8 - 0x560d2085b507
         _ZN5glium7program3raw10RawProgram12from_shaders17h600ce51995b409b5E at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/glium-0.23.0/src/program/raw.rs:172
   9 - 0x560d208610c9
         _ZN5glium7program7compute13ComputeShader11from_source17h67264351cf811d3fE at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/glium-0.23.0/src/program/compute.rs:52
  10 - 0x560d2087a919
         _ZN5gpgpu4main17h3ec799c9cfc76f35E at src/main.rs:28
  11 - 0x560d2087c96f
         _ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h675a17d48305490bE at libstd/rt.rs:74
  12 - 0x560d20ca6c32
         _ZN3std2rt19lang_start_internal28_$u7b$$u7b$closure$u7d$$u7d$17hfa55fa3abac97f1cE at libstd/rt.rs:59
         _ZN3std9panicking3try7do_call17hbafbcad10c689c73E at libstd/panicking.rs:310
  13 - 0x560d20cb6e19
         __rust_maybe_catch_panic at libpanic_unwind/lib.rs:102
  14 - 0x560d20c988ca
         _ZN3std9panicking3try17hcad0d43659dae567E at libstd/panicking.rs:289
         _ZN3std5panic12catch_unwind17h87a4b99f7a6774fdE at libstd/panic.rs:392
         _ZN3std2rt19lang_start_internal17hbcd5a990678800b9E at libstd/rt.rs:58
  15 - 0x560d2087c948
         _ZN3std2rt10lang_start17h2e7a9d9a9f3e876bE at libstd/rt.rs:74
  16 - 0x560d2087c7f9
         main at <unknown>:??
  17 - 0x7f9243dea222
         __libc_start_main at <unknown>:??
  18 - 0x560d2084325d
         _start at <unknown>:??
  19 - 0x0
         <unknown> at <unknown>:??

Debug message with high or medium severity: `GL_INVALID_OPERATION in glGetProgramStageiv`.
Please report this error: https://github.com/tomaka/glium/issues
Backtrace:
   1 - 0x560d20924506
         _ZN9backtrace9backtrace9libunwind5trace17hd30c041716104ea8E at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.13/src/backtrace/libunwind.rs:52
         _ZN9backtrace9backtrace20trace_unsynchronized17h69454b7084e02f09E at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.13/src/backtrace/mod.rs:57
   2 - 0x560d208b1d94
         _ZN9backtrace9backtrace5trace17h796329675076027dE at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.13/src/backtrace/mod.rs:47
         _ZN5glium7context22default_debug_callback17hfd175c526bdb0bf0E at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/glium-0.23.0/src/context/mod.rs:854
   3 - 0x560d2091a014
         _ZN4core3ops8function5FnMut8call_mut17h31b4262547d52346E at libcore/ops/function.rs:156
   4 - 0x560d208b30f4
         _ZN5glium7context19init_debug_callback16callback_wrapper17hb8433b4ab7b6c86bE at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/glium-0.23.0/src/context/mod.rs:941
   5 - 0x7f924105c9f8
         <unknown> at <unknown>:??
   6 - 0x560d209a8e6c
         _ZN5glium2gl2Gl17GetProgramStageiv17h650718f336a3ce01E at /home/frans/Documents/rust/gpgpu/target/debug/build/glium-911ed9a1ecb91ed8/out/gl_bindings.rs:6846
   7 - 0x560d2089865c
         _ZN5glium7program10reflection23reflect_subroutine_data17h7c049c609b61b9b8E at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/glium-0.23.0/src/program/reflection.rs:1176
   8 - 0x560d2085b507
         _ZN5glium7program3raw10RawProgram12from_shaders17h600ce51995b409b5E at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/glium-0.23.0/src/program/raw.rs:172
   9 - 0x560d208610c9
         _ZN5glium7program7compute13ComputeShader11from_source17h67264351cf811d3fE at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/glium-0.23.0/src/program/compute.rs:52
  10 - 0x560d2087a919
         _ZN5gpgpu4main17h3ec799c9cfc76f35E at src/main.rs:28
  11 - 0x560d2087c96f
         _ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h675a17d48305490bE at libstd/rt.rs:74
  12 - 0x560d20ca6c32
         _ZN3std2rt19lang_start_internal28_$u7b$$u7b$closure$u7d$$u7d$17hfa55fa3abac97f1cE at libstd/rt.rs:59
         _ZN3std9panicking3try7do_call17hbafbcad10c689c73E at libstd/panicking.rs:310
  13 - 0x560d20cb6e19
         __rust_maybe_catch_panic at libpanic_unwind/lib.rs:102
  14 - 0x560d20c988ca
         _ZN3std9panicking3try17hcad0d43659dae567E at libstd/panicking.rs:289
         _ZN3std5panic12catch_unwind17h87a4b99f7a6774fdE at libstd/panic.rs:392
         _ZN3std2rt19lang_start_internal17hbcd5a990678800b9E at libstd/rt.rs:58
  15 - 0x560d2087c948
         _ZN3std2rt10lang_start17h2e7a9d9a9f3e876bE at libstd/rt.rs:74
  16 - 0x560d2087c7f9
         main at <unknown>:??
  17 - 0x7f9243dea222
         __libc_start_main at <unknown>:??
  18 - 0x560d2084325d
         _start at <unknown>:??
  19 - 0x0
         <unknown> at <unknown>:??
```

I had to modify the code slightly in order to get it to run on my system, I believe that I made the changes suggested in #1310 which means that I changed the intialiation from headless to this:

```rust
    let window = glutin::WindowBuilder::new().with_visibility(false)
        .with_visibility(false);
    let display = glium::Display::new(window, context_builder, &event_loop)
        .unwrap();
```

This is running on an rx 590 on a mainline linux kernel version 4.20. glxinfo reports the following:
```
OpenGL vendor string: X.Org
OpenGL renderer string: AMD POLARIS10 (DRM 3.27.0, 4.20.0-mainline, LLVM 7.0.0)
OpenGL core profile version string: 4.5 (Core Profile) Mesa 18.3.1
```

For reference, this is the full code

```rust
use glium;
use rand;

use glium::{
    // Macros
    implement_buffer_content,
    implement_uniform_block,
    uniform,
    // Children
    glutin::{
        self,
        GlRequest,
        Api,
        GlProfile
    },
    uniforms::UniformBuffer,
    program::ComputeShader,
};

fn main() {
    let event_loop = glutin::EventsLoop::new();
    let context_builder = glutin::ContextBuilder::new();
    let window = glutin::WindowBuilder::new().with_visibility(false)
        .with_visibility(false);
    let display = glium::Display::new(window, context_builder, &event_loop)
        .unwrap();

    let program = glium::program::ComputeShader::from_source(&display, r#"\
            #version 430
            layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
            layout(std140) buffer MyBlock {
                float power;
                vec4 values[4096/4];
            };
            void main() {
                vec4 val = values[gl_GlobalInvocationID.x];
                values[gl_GlobalInvocationID.x] = pow(val, vec4(power));
            }
        "#).unwrap();

    struct Data {
        power: f32,
        _padding: [f32; 3],
        values: [[f32;4]],
    }

    implement_buffer_content!(Data);
    implement_uniform_block!(Data, power, values);

    const NUM_VALUES: usize = 4096;

    let mut buffer: glium::uniforms::UniformBuffer<Data> =
              glium::uniforms::UniformBuffer::empty_unsized(&display, 4 + 4*3 + 4 * NUM_VALUES).unwrap();

    {
        let mut mapping = buffer.map();
        mapping.power = rand::random();
        for val in mapping.values.iter_mut() {
            *val = [rand::random::<f32>(),rand::random::<f32>(),rand::random::<f32>(),rand::random::<f32>()];
        }
    }

    program.execute(uniform! { MyBlock: &*buffer }, 4096, 1, 1);

    {
        let mapping = buffer.map();
        println!("Power is: {:?}", mapping.power);
        for val in mapping.values.iter().take(3) {
            println!("{:?}", val[0]);
            println!("{:?}", val[1]);
            println!("{:?}", val[2]);
            println!("{:?}", val[3]);
        }
        println!("...");
    }
}
```


Discussion / hints:
I also tried uncommenting most parts of the shader, the layout line is required for it to compile and if it's there along with an empty main function, I still get the same error
I'm noticing that this is still an issue. It seems to be that these two calls to `GetProgramStageiv` starting on https://github.com/glium/glium/blob/e44b97ceb959873c6ecce9590dfb4cf7340a665b/src/program/reflection.rs#L1175 don't work on compute shaders. 
This happens for me too.

My system:
```
OpenGL vendor string: X.Org
OpenGL renderer string: Radeon RX 570 Series (POLARIS10, DRM 3.23.0, 4.15.0-200-generic, LLVM 9.0.0)
OpenGL core profile version string: 4.5 (Core Profile) Mesa 19.2.8
```

According to https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGetProgramStage.xhtml, it's invalid to call this function for compute shader.

Fix patch:
diff --git a/src/program/reflection.rs b/src/program/reflection.rs
index 23026a2c1f..330edbaeca 100644
--- a/src/program/reflection.rs
+++ b/src/program/reflection.rs
@@ -1120,7 +1120,7 @@ fn glenum_to_transform_feedback_mode(value: gl::types::GLenum) -> TransformFeedb
 }
 
 /// Contains all subroutine data of a program.
-#[derive(Debug, Clone)]
+#[derive(Debug, Default, Clone)]
 pub struct SubroutineData {
     /// Number of subroutine uniform locations per shader stage.
     /// This is *not* equal to the number of subroutine uniforms per stage,
@@ -1215,21 +1215,22 @@ pub unsafe fn reflect_subroutine_data(ctxt: &mut CommandContext<'_>, program: Ha
                                       -> SubroutineData
 {
     if !program::is_subroutine_supported(ctxt) {
-        return SubroutineData {
-            location_counts: HashMap::with_hasher(Default::default()),
-            subroutine_uniforms: HashMap::with_hasher(Default::default()),
-        }
+        return Default::default();
     }
 
     let program = match program {
         // subroutines not supported.
-        Handle::Handle(_) => return SubroutineData {
-            location_counts: HashMap::with_hasher(Default::default()),
-            subroutine_uniforms: HashMap::with_hasher(Default::default()),
-        },
+        Handle::Handle(_) => return Default::default(),
         Handle::Id(id) => id
     };
 
+    // Compute shader programs are not handled: #1718
+    let mut shader_count = 0;
+    ctxt.gl.GetProgramiv(program, gl::ATTACHED_SHADERS, &mut shader_count);
+    if shader_count < 2 {
+        return Default::default();
+    }
+
     let shader_stages = get_shader_stages(has_geometry_shader,
                                           has_tessellation_control_shader,
                                           has_tessellation_evaluation_shader);


Test patch: