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

Side by Side Diff: gpu/command_buffer/client/cmd_buffer_helper.h

Issue 427003008: Use placement new to allocate GPU command buffer entries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file contains the command buffer helper class. 5 // This file contains the command buffer helper class.
6 6
7 #ifndef GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ 7 #ifndef GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_
8 #define GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ 8 #define GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_
9 9
10 #include <string.h> 10 #include <string.h>
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 128
129 // Allocate space and advance put_. 129 // Allocate space and advance put_.
130 CommandBufferEntry* space = &entries_[put_]; 130 CommandBufferEntry* space = &entries_[put_];
131 put_ += entries; 131 put_ += entries;
132 immediate_entry_count_ -= entries; 132 immediate_entry_count_ -= entries;
133 133
134 DCHECK_LE(put_, total_entry_count_); 134 DCHECK_LE(put_, total_entry_count_);
135 return space; 135 return space;
136 } 136 }
137 137
138 template <typename T>
139 void ForceNullCheck(T* data) {
140 #if defined(OS_WIN) && defined(ARCH_CPU_64_BITS)
141 // 64-bit MSVC's alias analysis was determining that the command buffer
142 // entry couldn't be NULL, so it optimized out the NULL check.
143 // Dereferencing the same datatype through a volatile pointer seems to
144 // prevent that from happening. http://crbug.com/361936
145 if (data)
146 static_cast<volatile T*>(data)->header;
147 #endif
148 }
149
150 // Typed version of GetSpace. Gets enough room for the given type and returns 138 // Typed version of GetSpace. Gets enough room for the given type and returns
151 // a reference to it. 139 // a reference to it.
152 template <typename T> 140 template <typename T>
153 T* GetCmdSpace() { 141 T* GetCmdSpace() {
154 COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed); 142 COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed);
155 int32 space_needed = ComputeNumEntries(sizeof(T)); 143 int32 space_needed = ComputeNumEntries(sizeof(T));
156 T* data = static_cast<T*>(GetSpace(space_needed)); 144 return new (GetSpace(space_needed)) T;
157 ForceNullCheck(data);
158 return data;
159 } 145 }
160 146
161 // Typed version of GetSpace for immediate commands. 147 // Typed version of GetSpace for immediate commands.
162 template <typename T> 148 template <typename T>
163 T* GetImmediateCmdSpace(size_t data_space) { 149 T* GetImmediateCmdSpace(size_t data_space) {
164 COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN); 150 COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN);
165 int32 space_needed = ComputeNumEntries(sizeof(T) + data_space); 151 int32 space_needed = ComputeNumEntries(sizeof(T) + data_space);
166 T* data = static_cast<T*>(GetSpace(space_needed)); 152 return new (GetSpace(space_needed)) T;
167 ForceNullCheck(data);
168 return data;
169 } 153 }
170 154
171 // Typed version of GetSpace for immediate commands. 155 // Typed version of GetSpace for immediate commands.
172 template <typename T> 156 template <typename T>
173 T* GetImmediateCmdSpaceTotalSize(size_t total_space) { 157 T* GetImmediateCmdSpaceTotalSize(size_t total_space) {
174 COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN); 158 COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN);
175 int32 space_needed = ComputeNumEntries(total_space); 159 int32 space_needed = ComputeNumEntries(total_space);
176 T* data = static_cast<T*>(GetSpace(space_needed)); 160 return new (GetSpace(space_needed)) T;
177 ForceNullCheck(data);
178 return data;
179 } 161 }
180 162
181 int32 last_token_read() const { 163 int32 last_token_read() const {
182 return command_buffer_->GetLastToken(); 164 return command_buffer_->GetLastToken();
183 } 165 }
184 166
185 int32 get_offset() const { 167 int32 get_offset() const {
186 return command_buffer_->GetLastState().get_offset; 168 return command_buffer_->GetLastState().get_offset;
187 } 169 }
188 170
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // Can be used to track when prior commands have been flushed. 315 // Can be used to track when prior commands have been flushed.
334 uint32 flush_generation_; 316 uint32 flush_generation_;
335 317
336 friend class CommandBufferHelperTest; 318 friend class CommandBufferHelperTest;
337 DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper); 319 DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper);
338 }; 320 };
339 321
340 } // namespace gpu 322 } // namespace gpu
341 323
342 #endif // GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ 324 #endif // GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698