| 
									
										
										
										
											2015-05-24 06:55:12 +02:00
										 |  |  | // Copyright 2008 Dolphin Emulator Project
 | 
					
						
							| 
									
										
										
										
											2015-05-18 01:08:10 +02:00
										 |  |  | // Licensed under GPLv2+
 | 
					
						
							| 
									
										
										
										
											2013-04-17 23:29:41 -04:00
										 |  |  | // Refer to the license.txt file included.
 | 
					
						
							| 
									
										
										
										
											2013-01-31 23:11:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-10 13:54:46 -05:00
										 |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2013-01-31 23:11:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-21 10:06:40 -05:00
										 |  |  | #include <array>
 | 
					
						
							| 
									
										
										
										
											2015-12-21 10:15:17 -05:00
										 |  |  | #include <memory>
 | 
					
						
							| 
									
										
										
										
											2014-01-23 00:47:49 +01:00
										 |  |  | #include <utility>
 | 
					
						
							| 
									
										
										
										
											2015-09-19 04:40:00 +12:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 10:56:13 -05:00
										 |  |  | #include "Common/CommonTypes.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-19 04:40:00 +12:00
										 |  |  | #include "Common/GL/GLUtil.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 23:11:53 +01:00
										 |  |  | namespace OGL | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-15 14:09:53 -04:00
										 |  |  | class StreamBuffer | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-01-31 23:11:53 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   static std::unique_ptr<StreamBuffer> Create(u32 type, u32 size); | 
					
						
							|  |  |  |   virtual ~StreamBuffer(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* This mapping function will return a pair of:
 | 
					
						
							|  |  |  |    * - the pointer to the mapped buffer | 
					
						
							|  |  |  |    * - the offset into the real GPU buffer (always multiple of stride) | 
					
						
							|  |  |  |    * On mapping, the maximum of size for allocation has to be set. | 
					
						
							|  |  |  |    * The size really pushed into this fifo only has to be known on Unmapping. | 
					
						
							|  |  |  |    * Mapping invalidates the current buffer content, | 
					
						
							|  |  |  |    * so it isn't allowed to access the old content any more. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   virtual std::pair<u8*, u32> Map(u32 size) = 0; | 
					
						
							|  |  |  |   virtual void Unmap(u32 used_size) = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   std::pair<u8*, u32> Map(u32 size, u32 stride) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     u32 padding = m_iterator % stride; | 
					
						
							|  |  |  |     if (padding) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       m_iterator += stride - padding; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return Map(size); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const u32 m_buffer; | 
					
						
							| 
									
										
										
										
											2014-01-23 00:47:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   StreamBuffer(u32 type, u32 size); | 
					
						
							|  |  |  |   void CreateFences(); | 
					
						
							|  |  |  |   void DeleteFences(); | 
					
						
							|  |  |  |   void AllocMemory(u32 size); | 
					
						
							| 
									
										
										
										
											2013-10-29 01:23:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   const u32 m_buffertype; | 
					
						
							|  |  |  |   const u32 m_size; | 
					
						
							| 
									
										
										
										
											2014-03-29 11:05:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   u32 m_iterator; | 
					
						
							|  |  |  |   u32 m_used_iterator; | 
					
						
							|  |  |  |   u32 m_free_iterator; | 
					
						
							| 
									
										
										
										
											2014-01-23 00:47:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   static constexpr int SYNC_POINTS = 16; | 
					
						
							|  |  |  |   int Slot(u32 x) const { return x >> m_bit_per_slot; } | 
					
						
							|  |  |  |   const int m_bit_per_slot; | 
					
						
							| 
									
										
										
										
											2014-06-05 11:06:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   std::array<GLsync, SYNC_POINTS> m_fences{}; | 
					
						
							| 
									
										
										
										
											2013-01-31 23:11:53 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | } |