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

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

Issue 255403008: Fix miscompilation of NULL check. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 126
127 // Allocate space and advance put_. 127 // Allocate space and advance put_.
128 CommandBufferEntry* space = &entries_[put_]; 128 CommandBufferEntry* space = &entries_[put_];
129 put_ += entries; 129 put_ += entries;
130 immediate_entry_count_ -= entries; 130 immediate_entry_count_ -= entries;
131 131
132 DCHECK_LE(put_, total_entry_count_); 132 DCHECK_LE(put_, total_entry_count_);
133 return space; 133 return space;
134 } 134 }
135 135
136 template <typename T>
137 void ForceNullCheck(T* data) {
138 #if defined(OS_WIN) && defined(ARCH_CPU_64_BITS)
139 // 64-bit MSVC's alias analysis was determining that the command buffer
140 // entry couldn't be NULL, so it optimized out the NULL check.
141 // Dereferencing the same datatype through a volatile pointer seems to
142 // prevent that from happening. http://crbug.com/361936
143 if (data)
144 static_cast<volatile T*>(data)->header;
145 #endif
146 }
147
136 // Typed version of GetSpace. Gets enough room for the given type and returns 148 // Typed version of GetSpace. Gets enough room for the given type and returns
137 // a reference to it. 149 // a reference to it.
138 template <typename T> 150 template <typename T>
139 T* GetCmdSpace() { 151 T* GetCmdSpace() {
140 COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed); 152 COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed);
141 int32 space_needed = ComputeNumEntries(sizeof(T)); 153 int32 space_needed = ComputeNumEntries(sizeof(T));
142 void* data = GetSpace(space_needed); 154 T* data = static_cast<T*>(GetSpace(space_needed));
143 return static_cast<T*>(data); 155 ForceNullCheck(data);
156 return data;
144 } 157 }
145 158
146 // Typed version of GetSpace for immediate commands. 159 // Typed version of GetSpace for immediate commands.
147 template <typename T> 160 template <typename T>
148 T* GetImmediateCmdSpace(size_t data_space) { 161 T* GetImmediateCmdSpace(size_t data_space) {
149 COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN); 162 COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN);
150 int32 space_needed = ComputeNumEntries(sizeof(T) + data_space); 163 int32 space_needed = ComputeNumEntries(sizeof(T) + data_space);
151 void* data = GetSpace(space_needed); 164 T* data = static_cast<T*>(GetSpace(space_needed));
152 return static_cast<T*>(data); 165 ForceNullCheck(data);
166 return data;
153 } 167 }
154 168
155 // Typed version of GetSpace for immediate commands. 169 // Typed version of GetSpace for immediate commands.
156 template <typename T> 170 template <typename T>
157 T* GetImmediateCmdSpaceTotalSize(size_t total_space) { 171 T* GetImmediateCmdSpaceTotalSize(size_t total_space) {
158 COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN); 172 COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN);
159 int32 space_needed = ComputeNumEntries(total_space); 173 int32 space_needed = ComputeNumEntries(total_space);
160 void* data = GetSpace(space_needed); 174 T* data = static_cast<T*>(GetSpace(space_needed));
161 return static_cast<T*>(data); 175 ForceNullCheck(data);
176 return data;
162 } 177 }
163 178
164 int32 last_token_read() const { 179 int32 last_token_read() const {
165 return command_buffer_->GetLastToken(); 180 return command_buffer_->GetLastToken();
166 } 181 }
167 182
168 int32 get_offset() const { 183 int32 get_offset() const {
169 return command_buffer_->GetLastState().get_offset; 184 return command_buffer_->GetLastState().get_offset;
170 } 185 }
171 186
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // Can be used to track when prior commands have been flushed. 332 // Can be used to track when prior commands have been flushed.
318 uint32 flush_generation_; 333 uint32 flush_generation_;
319 334
320 friend class CommandBufferHelperTest; 335 friend class CommandBufferHelperTest;
321 DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper); 336 DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper);
322 }; 337 };
323 338
324 } // namespace gpu 339 } // namespace gpu
325 340
326 #endif // GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ 341 #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