Commit 661ced98 authored by jbauman@chromium.org's avatar jbauman@chromium.org

Use placement new to allocate GPU command buffer entries.

This isn't as ugly as the crazy null check, and it seems to be compiled correctly.

BUG=

Review URL: https://codereview.chromium.org/427003008

Cr-Commit-Position: refs/heads/master@{#288481}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288481 0039d316-1c4b-4281-b951-d872f2087c98
parent 91150da9
......@@ -135,27 +135,13 @@ class GPU_EXPORT CommandBufferHelper {
return space;
}
template <typename T>
void ForceNullCheck(T* data) {
#if defined(OS_WIN) && defined(ARCH_CPU_64_BITS)
// 64-bit MSVC's alias analysis was determining that the command buffer
// entry couldn't be NULL, so it optimized out the NULL check.
// Dereferencing the same datatype through a volatile pointer seems to
// prevent that from happening. http://crbug.com/361936
if (data)
static_cast<volatile T*>(data)->header;
#endif
}
// Typed version of GetSpace. Gets enough room for the given type and returns
// a reference to it.
template <typename T>
T* GetCmdSpace() {
COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed);
int32 space_needed = ComputeNumEntries(sizeof(T));
T* data = static_cast<T*>(GetSpace(space_needed));
ForceNullCheck(data);
return data;
return new (GetSpace(space_needed)) T;
}
// Typed version of GetSpace for immediate commands.
......@@ -163,9 +149,7 @@ class GPU_EXPORT CommandBufferHelper {
T* GetImmediateCmdSpace(size_t data_space) {
COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN);
int32 space_needed = ComputeNumEntries(sizeof(T) + data_space);
T* data = static_cast<T*>(GetSpace(space_needed));
ForceNullCheck(data);
return data;
return new (GetSpace(space_needed)) T;
}
// Typed version of GetSpace for immediate commands.
......@@ -173,9 +157,7 @@ class GPU_EXPORT CommandBufferHelper {
T* GetImmediateCmdSpaceTotalSize(size_t total_space) {
COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN);
int32 space_needed = ComputeNumEntries(total_space);
T* data = static_cast<T*>(GetSpace(space_needed));
ForceNullCheck(data);
return data;
return new (GetSpace(space_needed)) T;
}
int32 last_token_read() const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment