Browse Source

display: Allow passing RenderState to compute shader dispatch

This makes it possible to extend our GLSL unit tests to access render state attributes.
rdb 5 years ago
parent
commit
1bb331b227

+ 10 - 0
panda/src/display/graphicsEngine.I

@@ -162,3 +162,13 @@ make_parasite(GraphicsOutput *host, const std::string &name,
                                        host->get_gsg(), host);
   return result;
 }
+
+/**
+ * Deprecated variant of dispatch_compute() which takes only a ShaderAttrib
+ * instead of a whole RenderState.
+ */
+void GraphicsEngine::
+dispatch_compute(const LVecBase3i &work_groups, const ShaderAttrib *sattr, GraphicsStateGuardian *gsg) {
+  CPT(RenderState) state = RenderState::make(sattr);
+  dispatch_compute(work_groups, state, gsg);
+}

+ 4 - 4
panda/src/display/graphicsEngine.cxx

@@ -1184,15 +1184,15 @@ extract_texture_data(Texture *tex, GraphicsStateGuardian *gsg) {
  * The return value is true if the operation is successful, false otherwise.
  */
 void GraphicsEngine::
-dispatch_compute(const LVecBase3i &work_groups, const ShaderAttrib *sattr, GraphicsStateGuardian *gsg) {
+dispatch_compute(const LVecBase3i &work_groups, const RenderState *state, GraphicsStateGuardian *gsg) {
+  const ShaderAttrib *sattr;
+  state->get_attrib_def(sattr);
   const Shader *shader = sattr->get_shader();
   nassertv(shader != nullptr);
   nassertv(gsg != nullptr);
 
   ReMutexHolder holder(_lock);
 
-  CPT(RenderState) state = RenderState::make(sattr);
-
   string draw_name = gsg->get_threading_model().get_draw_name();
   if (draw_name.empty()) {
     // A single-threaded environment.  No problem.
@@ -1219,7 +1219,7 @@ dispatch_compute(const LVecBase3i &work_groups, const ShaderAttrib *sattr, Graph
 
     // Now that the draw thread is idle, signal it to do the compute task.
     thread->_gsg = gsg;
-    thread->_state = state.p();
+    thread->_state = state;
     thread->_work_groups = work_groups;
     thread->_thread_state = TS_do_compute;
     thread->_cv_start.notify();

+ 4 - 1
panda/src/display/graphicsEngine.h

@@ -111,8 +111,11 @@ PUBLISHED:
 
   bool extract_texture_data(Texture *tex, GraphicsStateGuardian *gsg);
   void dispatch_compute(const LVecBase3i &work_groups,
-                        const ShaderAttrib *sattr,
+                        const RenderState *state,
                         GraphicsStateGuardian *gsg);
+  INLINE void dispatch_compute(const LVecBase3i &work_groups,
+                               const ShaderAttrib *sattr,
+                               GraphicsStateGuardian *gsg);
 
   static GraphicsEngine *get_global_ptr();