Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Unified Diff: gpu/command_buffer/service/sync_point_manager.h

Issue 1339203002: Added global order numbers to in process command buffers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor changes Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/service/sync_point_manager.h
diff --git a/gpu/command_buffer/service/sync_point_manager.h b/gpu/command_buffer/service/sync_point_manager.h
index 98e849b76ced244c3400b171d12cf513c4f4f739..3f11e05dabbe407ea9c27e018c759701e3fedbb3 100644
--- a/gpu/command_buffer/service/sync_point_manager.h
+++ b/gpu/command_buffer/service/sync_point_manager.h
@@ -7,15 +7,103 @@
#include <vector>
+#include "base/atomic_sequence_num.h"
#include "base/callback.h"
#include "base/containers/hash_tables.h"
+#include "base/logging.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
+#include "base/threading/thread_checker.h"
+#include "gpu/command_buffer/common/constants.h"
#include "gpu/gpu_export.h"
namespace gpu {
+class SyncPointClient;
+class SyncPointManager;
+
+class GPU_EXPORT SyncPointClientState
+ : public base::RefCountedThreadSafe<SyncPointClientState> {
+ public:
+ static scoped_refptr<SyncPointClientState> Create();
+ uint32_t GenerateUnprocessedOrderNumber(SyncPointManager* sync_point_manager);
+
+ void BeginProcessingOrderNumber(uint32_t order_num) {
+ DCHECK(processing_thread_checker_.CalledOnValidThread());
+ DCHECK_GE(order_num, current_order_num_);
+ current_order_num_ = order_num;
+ }
+
+ void FinishProcessingOrderNumber(uint32_t order_num) {
+ DCHECK(processing_thread_checker_.CalledOnValidThread());
+ DCHECK_EQ(current_order_num_, order_num);
+ DCHECK_GT(order_num, processed_order_num());
+ base::subtle::Release_Store(&processed_order_num_, order_num);
+ }
+
+ uint32_t processed_order_num() const {
+ return base::subtle::Acquire_Load(&processed_order_num_);
+ }
+
+ uint32_t unprocessed_order_num() const {
+ return base::subtle::Acquire_Load(&unprocessed_order_num_);
+ }
+
+ uint32_t current_order_num() const {
+ DCHECK(processing_thread_checker_.CalledOnValidThread());
+ return current_order_num_;
+ }
+
+ protected:
+ friend class base::RefCountedThreadSafe<SyncPointClientState>;
+ friend class SyncPointClient;
+
+ SyncPointClientState();
+ virtual ~SyncPointClientState();
+
+ // Last finished IPC order number.
+ base::subtle::Atomic32 processed_order_num_;
+
+ // Unprocessed order number expected to be processed under normal execution.
+ base::subtle::Atomic32 unprocessed_order_num_;
+
+ // Non thread-safe functions need to be called from a single thread.
+ base::ThreadChecker processing_thread_checker_;
+
+ // Current IPC order number being processed (only used on processing thread).
+ uint32_t current_order_num_;
+
+ DISALLOW_COPY_AND_ASSIGN(SyncPointClientState);
+};
+
+class GPU_EXPORT SyncPointClient {
+ public:
+ ~SyncPointClient();
+
+ scoped_refptr<SyncPointClientState> client_state() { return client_state_; }
+
+ private:
+ friend class SyncPointManager;
+
+ SyncPointClient(SyncPointManager* sync_point_manager,
+ scoped_refptr<SyncPointClientState> state,
+ CommandBufferNamespace namespace_id, uint64_t client_id);
+
+ // Sync point manager is guaranteed to exist in the lifetime of the client.
+ SyncPointManager* sync_point_manager_;
+
+ // Keep the state that is sharable across multiple threads.
+ scoped_refptr<SyncPointClientState> client_state_;
+
+ // Unique namespace/client id pair for this sync point client.
+ CommandBufferNamespace namespace_id_;
+ uint64_t client_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(SyncPointClient);
+};
+
// This class manages the sync points, which allow cross-channel
// synchronization.
class GPU_EXPORT SyncPointManager {
@@ -23,6 +111,15 @@ class GPU_EXPORT SyncPointManager {
explicit SyncPointManager(bool allow_threaded_wait);
~SyncPointManager();
+ // Creates/Destroy a sync point client which message processors should hold.
+ scoped_ptr<SyncPointClient> CreateSyncPointClient(
+ scoped_refptr<SyncPointClientState> client_state,
+ CommandBufferNamespace namespace_id, uint64_t client_id);
+
+ // Finds the state of an already created sync point client.
+ scoped_refptr<SyncPointClientState> GetSyncPointClientState(
+ CommandBufferNamespace namespace_id, uint64_t client_id);
+
// Generates a sync point, returning its ID. This can me called on any thread.
// IDs start at a random number. Never return 0.
uint32 GenerateSyncPoint();
@@ -44,14 +141,27 @@ class GPU_EXPORT SyncPointManager {
void WaitSyncPoint(uint32 sync_point);
private:
+ friend class SyncPointClient;
+ friend class SyncPointClientState;
+
typedef std::vector<base::Closure> ClosureList;
typedef base::hash_map<uint32, ClosureList> SyncPointMap;
-
+ typedef base::hash_map<uint64_t, SyncPointClient*> ClientMap;
bool IsSyncPointRetiredLocked(uint32 sync_point);
+ uint32_t GenerateOrderNumber();
+ void DestroySyncPointClient(CommandBufferNamespace namespace_id,
+ uint64_t client_id);
const bool allow_threaded_wait_;
+ // Order number is global for all clients.
+ base::AtomicSequenceNumber global_order_num_;
+
+ // Client map holds a map of clients id to client for each namespace.
+ base::Lock client_maps_lock_;
+ ClientMap client_maps_[NUM_COMMAND_BUFFER_NAMESPACES];
+
// Protects the 2 fields below. Note: callbacks shouldn't be called with this
// held.
base::Lock lock_;
« no previous file with comments | « gpu/command_buffer/service/in_process_command_buffer.cc ('k') | gpu/command_buffer/service/sync_point_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698