Browse Source

Add gsg.make_current() call to do before dispatch_compute()

rdb 1 year ago
parent
commit
2c1eb847fd

+ 9 - 0
panda/src/display/graphicsStateGuardian.cxx

@@ -317,6 +317,15 @@ get_engine() const {
   return _engine;
   return _engine;
 }
 }
 
 
+/**
+ * Attempts to make the context current on this thread without an associated
+ * window, if possible.  Returns false if that is not supported.
+ */
+bool GraphicsStateGuardian::
+make_current() const {
+  return false;
+}
+
 /**
 /**
  * Returns true if this particular GSG supports using the multisample bits to
  * Returns true if this particular GSG supports using the multisample bits to
  * provide antialiasing, and also supports M_multisample and
  * provide antialiasing, and also supports M_multisample and

+ 2 - 0
panda/src/display/graphicsStateGuardian.h

@@ -115,6 +115,8 @@ PUBLISHED:
   INLINE const GraphicsThreadingModel &get_threading_model() const;
   INLINE const GraphicsThreadingModel &get_threading_model() const;
   MAKE_PROPERTY(pipe, get_pipe);
   MAKE_PROPERTY(pipe, get_pipe);
 
 
+  virtual bool make_current() const;
+
   INLINE bool is_hardware() const;
   INLINE bool is_hardware() const;
   virtual INLINE bool prefers_triangle_strips() const;
   virtual INLINE bool prefers_triangle_strips() const;
   virtual INLINE int get_max_vertices_per_array() const;
   virtual INLINE int get_max_vertices_per_array() const;

+ 21 - 0
panda/src/egldisplay/eglGraphicsStateGuardian.cxx

@@ -52,6 +52,27 @@ eglGraphicsStateGuardian::
   }
   }
 }
 }
 
 
+/**
+ * Attempts to make the context current on this thread without an associated
+ * window, if possible.  Returns false if that is not supported.
+ */
+bool eglGraphicsStateGuardian::
+make_current() const {
+  if (_context == (EGLContext)nullptr) {
+    return false;
+  }
+#ifdef OPENGLES
+  if (!has_extension("GL_OES_surfaceless_context")) {
+    return false;
+  }
+#else
+  if (!is_at_least_gl_version(3, 0)) {
+    return false;
+  }
+#endif
+  return eglMakeCurrent(_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, _context);
+}
+
 /**
 /**
  * Gets the FrameBufferProperties to match the indicated config.
  * Gets the FrameBufferProperties to match the indicated config.
  */
  */

+ 2 - 0
panda/src/egldisplay/eglGraphicsStateGuardian.h

@@ -48,6 +48,8 @@ public:
 
 
   virtual ~eglGraphicsStateGuardian();
   virtual ~eglGraphicsStateGuardian();
 
 
+  virtual bool make_current() const;
+
   virtual void reset();
   virtual void reset();
 
 
   bool egl_is_at_least_version(int major_version, int minor_version) const;
   bool egl_is_at_least_version(int major_version, int minor_version) const;

+ 11 - 0
panda/src/glxdisplay/glxGraphicsStateGuardian.cxx

@@ -77,6 +77,17 @@ glxGraphicsStateGuardian::
   }
   }
 }
 }
 
 
+/**
+ * Attempts to make the context current on this thread without an associated
+ * window, if possible.  Returns false if that is not supported.
+ */
+bool glxGraphicsStateGuardian::
+make_current() const {
+  return _context != nullptr
+      && is_at_least_gl_version(3, 0)
+      && glXMakeCurrent(_display, None, _context);
+}
+
 /**
 /**
  * Gets the FrameBufferProperties to match the indicated visual.
  * Gets the FrameBufferProperties to match the indicated visual.
  */
  */

+ 2 - 0
panda/src/glxdisplay/glxGraphicsStateGuardian.h

@@ -88,6 +88,8 @@ public:
 
 
   virtual ~glxGraphicsStateGuardian();
   virtual ~glxGraphicsStateGuardian();
 
 
+  virtual bool make_current() const;
+
   bool glx_is_at_least_version(int major_version, int minor_version) const;
   bool glx_is_at_least_version(int major_version, int minor_version) const;
 
 
   GLXContext _share_context;
   GLXContext _share_context;

+ 2 - 1
tests/display/conftest.py

@@ -304,6 +304,7 @@ class ShaderEnvironment:
         # Run the shader.
         # Run the shader.
         if use_compute:
         if use_compute:
             try:
             try:
+                gsg.make_current()
                 engine.dispatch_compute((1, 1, 1), state, gsg)
                 engine.dispatch_compute((1, 1, 1), state, gsg)
             except AssertionError as exc:
             except AssertionError as exc:
                 assert False, "Error executing compute shader:\n" + code
                 assert False, "Error executing compute shader:\n" + code
@@ -573,7 +574,6 @@ def env(request):
         props,
         props,
         core.GraphicsPipe.BF_refuse_window
         core.GraphicsPipe.BF_refuse_window
     )
     )
-    engine.open_windows()
 
 
     if buffer is None:
     if buffer is None:
         # Try making a window instead, putting it in the background so it
         # Try making a window instead, putting it in the background so it
@@ -593,6 +593,7 @@ def env(request):
     if buffer is None:
     if buffer is None:
         pytest.skip("GraphicsPipe cannot make offscreen buffers or windows")
         pytest.skip("GraphicsPipe cannot make offscreen buffers or windows")
 
 
+    engine.open_windows()
     gsg = buffer.gsg
     gsg = buffer.gsg
 
 
     # Check if the environment is actually supported.
     # Check if the environment is actually supported.