| 
									
										
										
										
											2020-08-07 17:00:28 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright 2020, Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup gpu | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 03:01:45 +02:00
										 |  |  | #include "gpu_context_private.hh"
 | 
					
						
							| 
									
										
										
										
											2020-08-07 17:00:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-11 01:31:40 +02:00
										 |  |  | #include "GPU_framebuffer.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  | #include "BLI_set.hh"
 | 
					
						
							| 
									
										
										
										
											2020-08-08 03:01:45 +02:00
										 |  |  | #include "BLI_vector.hh"
 | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | #include "gl_state.hh"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 17:00:28 +02:00
										 |  |  | #include "glew-mx.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <mutex>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  | namespace blender { | 
					
						
							|  |  |  | namespace gpu { | 
					
						
							| 
									
										
										
										
											2020-08-07 17:00:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-21 12:30:55 +02:00
										 |  |  | class GLVaoCache; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  | class GLSharedOrphanLists { | 
					
						
							| 
									
										
										
										
											2020-08-07 17:00:28 +02:00
										 |  |  |  public: | 
					
						
							| 
									
										
										
										
											2021-02-05 19:07:03 -08:00
										 |  |  |   /** Mutex for the below structures. */ | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  |   std::mutex lists_mutex; | 
					
						
							|  |  |  |   /** Buffers and textures are shared across context. Any context can free them. */ | 
					
						
							|  |  |  |   Vector<GLuint> textures; | 
					
						
							|  |  |  |   Vector<GLuint> buffers; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   void orphans_clear(void); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-08-07 17:00:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-08 04:12:12 +02:00
										 |  |  | class GLContext : public Context { | 
					
						
							| 
									
										
										
										
											2020-09-01 02:41:29 +02:00
										 |  |  |  public: | 
					
						
							| 
									
										
										
										
											2020-09-07 18:52:30 +02:00
										 |  |  |   /** Capabilities. */ | 
					
						
							|  |  |  |   static GLint max_cubemap_size; | 
					
						
							| 
									
										
										
										
											2020-09-12 06:10:11 +02:00
										 |  |  |   static GLint max_texture_3d_size; | 
					
						
							| 
									
										
										
										
											2020-09-07 18:52:30 +02:00
										 |  |  |   static GLint max_ubo_size; | 
					
						
							|  |  |  |   static GLint max_ubo_binds; | 
					
						
							|  |  |  |   /** Extensions. */ | 
					
						
							|  |  |  |   static bool base_instance_support; | 
					
						
							| 
									
										
										
										
											2020-09-10 14:18:19 +02:00
										 |  |  |   static bool clear_texture_support; | 
					
						
							|  |  |  |   static bool copy_image_support; | 
					
						
							| 
									
										
										
										
											2020-09-09 00:23:48 +02:00
										 |  |  |   static bool debug_layer_support; | 
					
						
							| 
									
										
										
										
											2020-09-10 14:18:19 +02:00
										 |  |  |   static bool direct_state_access_support; | 
					
						
							|  |  |  |   static bool fixed_restart_index_support; | 
					
						
							|  |  |  |   static bool multi_bind_support; | 
					
						
							|  |  |  |   static bool multi_draw_indirect_support; | 
					
						
							|  |  |  |   static bool shader_draw_parameters_support; | 
					
						
							| 
									
										
										
										
											2020-09-07 18:52:30 +02:00
										 |  |  |   static bool texture_cube_map_array_support; | 
					
						
							| 
									
										
										
										
											2020-09-10 14:18:19 +02:00
										 |  |  |   static bool texture_filter_anisotropic_support; | 
					
						
							|  |  |  |   static bool texture_gather_support; | 
					
						
							|  |  |  |   static bool vertex_attrib_binding_support; | 
					
						
							| 
									
										
										
										
											2020-09-07 18:52:30 +02:00
										 |  |  |   /** Workarounds. */ | 
					
						
							| 
									
										
										
										
											2020-09-09 00:47:59 +02:00
										 |  |  |   static bool debug_layer_workaround; | 
					
						
							| 
									
										
										
										
											2020-09-07 18:52:30 +02:00
										 |  |  |   static bool unused_fb_slot_workaround; | 
					
						
							|  |  |  |   static float derivative_signs[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-07 23:52:55 +02:00
										 |  |  |   /** VBO for missing vertex attrib binding. Avoid undefined behavior on some implementation. */ | 
					
						
							|  |  |  |   GLuint default_attr_vbo_; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-01 02:41:29 +02:00
										 |  |  |   /** Used for debugging purpose. Bitflags of all bound slots. */ | 
					
						
							|  |  |  |   uint16_t bound_ubo_slots; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-07 23:52:55 +02:00
										 |  |  |  private: | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  |   /**
 | 
					
						
							| 
									
										
										
										
											2021-02-05 16:23:34 +11:00
										 |  |  |    * #GPUBatch & #GPUFramebuffer have references to the context they are from, in the case the | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  |    * context is destroyed, we need to remove any reference to it. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2020-08-11 01:31:40 +02:00
										 |  |  |   Set<GLVaoCache *> vao_caches_; | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  |   Set<GPUFrameBuffer *> framebuffers_; | 
					
						
							| 
									
										
										
										
											2021-02-05 19:07:03 -08:00
										 |  |  |   /** Mutex for the below structures. */ | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  |   std::mutex lists_mutex_; | 
					
						
							|  |  |  |   /** VertexArrays and framebuffers are not shared across context. */ | 
					
						
							|  |  |  |   Vector<GLuint> orphaned_vertarrays_; | 
					
						
							|  |  |  |   Vector<GLuint> orphaned_framebuffers_; | 
					
						
							| 
									
										
										
										
											2021-02-05 16:23:34 +11:00
										 |  |  |   /** #GLBackend owns this data. */ | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  |   GLSharedOrphanLists &shared_orphan_list_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list); | 
					
						
							|  |  |  |   ~GLContext(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-25 14:47:23 +02:00
										 |  |  |   static void check_error(const char *info); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  |   void activate(void) override; | 
					
						
							|  |  |  |   void deactivate(void) override; | 
					
						
							| 
									
										
										
										
											2020-09-08 00:10:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-08 16:04:31 +02:00
										 |  |  |   void flush(void) override; | 
					
						
							|  |  |  |   void finish(void) override; | 
					
						
							| 
									
										
										
										
											2020-09-08 00:10:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-07 19:53:48 +02:00
										 |  |  |   void memory_statistics_get(int *total_mem, int *free_mem) override; | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-08 04:12:12 +02:00
										 |  |  |   static GLContext *get() | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   { | 
					
						
							| 
									
										
										
										
											2020-09-08 04:12:12 +02:00
										 |  |  |     return static_cast<GLContext *>(Context::get()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static GLStateManager *state_manager_active_get() | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     GLContext *ctx = GLContext::get(); | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     return static_cast<GLStateManager *>(ctx->state_manager); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-07 20:08:25 +02:00
										 |  |  |   /* These need to be called with the context the id was created with. */ | 
					
						
							|  |  |  |   void vao_free(GLuint vao_id); | 
					
						
							|  |  |  |   void fbo_free(GLuint fbo_id); | 
					
						
							|  |  |  |   /* These can be called by any threads even without OpenGL ctx. Deletion will be delayed. */ | 
					
						
							|  |  |  |   static void buf_free(GLuint buf_id); | 
					
						
							|  |  |  |   static void tex_free(GLuint tex_id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-11 01:31:40 +02:00
										 |  |  |   void vao_cache_register(GLVaoCache *cache); | 
					
						
							|  |  |  |   void vao_cache_unregister(GLVaoCache *cache); | 
					
						
							| 
									
										
										
										
											2020-09-07 23:52:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 19:52:49 +02:00
										 |  |  |   void debug_group_begin(const char *name, int index) override; | 
					
						
							|  |  |  |   void debug_group_end(void) override; | 
					
						
							| 
									
										
										
										
											2020-09-14 17:29:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-07 23:52:55 +02:00
										 |  |  |  private: | 
					
						
							|  |  |  |   static void orphans_add(Vector<GLuint> &orphan_list, std::mutex &list_mutex, GLuint id); | 
					
						
							|  |  |  |   void orphans_clear(void); | 
					
						
							| 
									
										
										
										
											2020-09-08 04:12:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   MEM_CXX_CLASS_ALLOC_FUNCS("GLContext") | 
					
						
							| 
									
										
										
										
											2020-08-07 17:00:28 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 01:18:18 +02:00
										 |  |  | }  // namespace gpu
 | 
					
						
							|  |  |  | }  // namespace blender
 |