display: Make context current before dispatching compute shader

This commit is contained in:
rdb
2026-01-29 21:09:19 +01:00
parent 74360ccd78
commit 252c0a6f37
9 changed files with 66 additions and 0 deletions
@@ -39,6 +39,8 @@ public:
virtual ~CocoaGLGraphicsStateGuardian();
virtual bool make_current();
INLINE void lock_context();
INLINE void unlock_context();
@@ -297,6 +297,18 @@ choose_pixel_format(const FrameBufferProperties &properties,
}
}
/**
* Ensures that the context is current. May return false if the context cannot
* be bound without a window.
*/
bool CocoaGLGraphicsStateGuardian::
make_current() {
lock_context();
[_context makeCurrentContext];
unlock_context();
return true;
}
/**
* Queries the runtime version of OpenGL in use.
*/
+1
View File
@@ -1206,6 +1206,7 @@ dispatch_compute(const LVecBase3i &work_groups, const RenderState *state, Graphi
nassertv(gsg != nullptr);
run_on_draw_thread([=] () {
gsg->make_current();
gsg->push_group_marker(std::string("Compute ") + shader->get_filename(Shader::ST_compute).get_basename());
gsg->set_state_and_transform(state, TransformState::make_identity());
gsg->dispatch_compute(work_groups[0], work_groups[1], work_groups[2]);
@@ -3084,6 +3084,15 @@ reset() {
_is_valid = true;
}
/**
* Ensures that the context is current. May return false if the context cannot
* be bound without a window.
*/
bool GraphicsStateGuardian::
make_current() {
return false;
}
/**
* Simultaneously resets the render state and the transform state.
*
@@ -421,6 +421,7 @@ public:
INLINE bool reset_if_new();
INLINE void mark_new();
virtual void reset();
virtual bool make_current();
INLINE CPT(TransformState) get_external_transform() const;
INLINE CPT(TransformState) get_internal_transform() const;
@@ -280,12 +280,36 @@ void eglGraphicsStateGuardian::
reset() {
BaseGraphicsStateGuardian::reset();
#ifdef OPENGLES
_supports_surfaceless = has_extension("GL_OES_surfaceless_context") &&
#else
_supports_surfaceless =
#endif
has_extension("EGL_KHR_surfaceless_context");
if (_gl_renderer == "Software Rasterizer") {
_fbprops.set_force_software(1);
_fbprops.set_force_hardware(0);
}
}
/**
* Ensures that the context is current. May return false if the context cannot
* be bound without a window.
*/
bool eglGraphicsStateGuardian::
make_current() {
if (eglGetCurrentContext() == _context) {
return true;
}
if (_supports_surfaceless) {
return eglMakeCurrent(_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, _context) != EGL_FALSE;
}
return false;
}
/**
* Returns true if the runtime GLX version number is at least the indicated
* value, false otherwise.
@@ -49,6 +49,7 @@ public:
virtual ~eglGraphicsStateGuardian();
virtual void reset();
virtual bool make_current();
bool egl_is_at_least_version(int major_version, int minor_version) const;
@@ -60,6 +61,7 @@ public:
#endif
EGLConfig _fbconfig;
FrameBufferProperties _fbprops;
bool _supports_surfaceless = false;
protected:
virtual void gl_flush() const;
@@ -434,6 +434,19 @@ choose_pixel_format(const FrameBufferProperties &properties,
_context_has_pbuffer = false;
}
/**
* Ensures that the context is current. May return false if the context cannot
* be bound without a window.
*/
bool glxGraphicsStateGuardian::
make_current() {
if (glXGetCurrentContext() == _context) {
return true;
}
return false;
}
/**
* Returns true if the runtime GLX version number is at least the indicated
* value, false otherwise.
@@ -88,6 +88,8 @@ public:
virtual ~glxGraphicsStateGuardian();
virtual bool make_current();
bool glx_is_at_least_version(int major_version, int minor_version) const;
GLXContext _share_context;