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

Side by Side Diff: gpu/command_buffer/client/gles2_implementation.cc

Issue 1168853002: Use mapped memory for uploading large textures. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added dcheck and improved other error messages Created 5 years, 6 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
« no previous file with comments | « no previous file | gpu/command_buffer/client/gles2_implementation_unittest.cc » ('j') | 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 // A class to emulate GLES2 over command buffers. 5 // A class to emulate GLES2 over command buffers.
6 6
7 #include "gpu/command_buffer/client/gles2_implementation.h" 7 #include "gpu/command_buffer/client/gles2_implementation.h"
8 8
9 #include <GLES2/gl2ext.h> 9 #include <GLES2/gl2ext.h>
10 #include <GLES2/gl2extchromium.h> 10 #include <GLES2/gl2extchromium.h>
(...skipping 2169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2180 // advance pixels pointer past the skip rows and skip pixels 2180 // advance pixels pointer past the skip rows and skip pixels
2181 pixels = reinterpret_cast<const int8*>(pixels) + 2181 pixels = reinterpret_cast<const int8*>(pixels) +
2182 unpack_skip_rows_ * src_padded_row_size; 2182 unpack_skip_rows_ * src_padded_row_size;
2183 if (unpack_skip_pixels_) { 2183 if (unpack_skip_pixels_) {
2184 uint32 group_size = GLES2Util::ComputeImageGroupSize(format, type); 2184 uint32 group_size = GLES2Util::ComputeImageGroupSize(format, type);
2185 pixels = reinterpret_cast<const int8*>(pixels) + 2185 pixels = reinterpret_cast<const int8*>(pixels) +
2186 unpack_skip_pixels_ * group_size; 2186 unpack_skip_pixels_ * group_size;
2187 } 2187 }
2188 2188
2189 // Check if we can send it all at once. 2189 // Check if we can send it all at once.
2190 ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_); 2190 int32_t shm_id = 0;
2191 if (!buffer.valid()) { 2191 uint32_t shm_offset = 0;
2192 return; 2192 void* buffer_pointer = nullptr;
2193
2194 ScopedTransferBufferPtr transfer_alloc(size, helper_, transfer_buffer_);
2195 ScopedMappedMemoryPtr mapped_alloc(0, helper_, mapped_memory_.get());
2196
2197 if (transfer_alloc.valid() && transfer_alloc.size() >= size) {
2198 shm_id = transfer_alloc.shm_id();
2199 shm_offset = transfer_alloc.offset();
2200 buffer_pointer = transfer_alloc.address();
2201 } else {
2202 mapped_alloc.Reset(size);
2203 if (mapped_alloc.valid()) {
2204 transfer_alloc.Discard();
2205
2206 mapped_alloc.SetFlushAfterRelease(true);
2207 shm_id = mapped_alloc.shm_id();
2208 shm_offset = mapped_alloc.offset();
2209 buffer_pointer = mapped_alloc.address();
2210 }
2193 } 2211 }
2194 2212
2195 if (buffer.size() >= size) { 2213 if (buffer_pointer) {
2196 CopyRectToBuffer( 2214 CopyRectToBuffer(
2197 pixels, height, unpadded_row_size, src_padded_row_size, unpack_flip_y_, 2215 pixels, height, unpadded_row_size, src_padded_row_size, unpack_flip_y_,
2198 buffer.address(), padded_row_size); 2216 buffer_pointer, padded_row_size);
2199 helper_->TexImage2D( 2217 helper_->TexImage2D(
2200 target, level, internalformat, width, height, format, type, 2218 target, level, internalformat, width, height, format, type,
2201 buffer.shm_id(), buffer.offset()); 2219 shm_id, shm_offset);
2202 CheckGLError(); 2220 CheckGLError();
2203 return; 2221 return;
2204 } 2222 }
2205 2223
2206 // No, so send it using TexSubImage2D. 2224 // No, so send it using TexSubImage2D.
2207 helper_->TexImage2D( 2225 helper_->TexImage2D(
2208 target, level, internalformat, width, height, format, type, 2226 target, level, internalformat, width, height, format, type,
2209 0, 0); 2227 0, 0);
2210 TexSubImage2DImpl( 2228 TexSubImage2DImpl(
2211 target, level, 0, 0, width, height, format, type, unpadded_row_size, 2229 target, level, 0, 0, width, height, format, type, unpadded_row_size,
2212 pixels, src_padded_row_size, GL_TRUE, &buffer, padded_row_size); 2230 pixels, src_padded_row_size, GL_TRUE, &transfer_alloc, padded_row_size);
2213 CheckGLError(); 2231 CheckGLError();
2214 } 2232 }
2215 2233
2216 void GLES2Implementation::TexImage3D( 2234 void GLES2Implementation::TexImage3D(
2217 GLenum target, GLint level, GLint internalformat, GLsizei width, 2235 GLenum target, GLint level, GLint internalformat, GLsizei width,
2218 GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, 2236 GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type,
2219 const void* pixels) { 2237 const void* pixels) {
2220 GPU_CLIENT_SINGLE_THREAD_CHECK(); 2238 GPU_CLIENT_SINGLE_THREAD_CHECK();
2221 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glTexImage3D(" 2239 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glTexImage3D("
2222 << GLES2Util::GetStringTextureTarget(target) << ", " 2240 << GLES2Util::GetStringTextureTarget(target) << ", "
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2288 pixels = reinterpret_cast<const int8*>(pixels) + 2306 pixels = reinterpret_cast<const int8*>(pixels) +
2289 unpack_skip_images_ * src_padded_row_size * src_height + 2307 unpack_skip_images_ * src_padded_row_size * src_height +
2290 unpack_skip_rows_ * src_padded_row_size; 2308 unpack_skip_rows_ * src_padded_row_size;
2291 if (unpack_skip_pixels_) { 2309 if (unpack_skip_pixels_) {
2292 uint32 group_size = GLES2Util::ComputeImageGroupSize(format, type); 2310 uint32 group_size = GLES2Util::ComputeImageGroupSize(format, type);
2293 pixels = reinterpret_cast<const int8*>(pixels) + 2311 pixels = reinterpret_cast<const int8*>(pixels) +
2294 unpack_skip_pixels_ * group_size; 2312 unpack_skip_pixels_ * group_size;
2295 } 2313 }
2296 2314
2297 // Check if we can send it all at once. 2315 // Check if we can send it all at once.
2298 ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_); 2316 int32_t shm_id = 0;
2299 if (!buffer.valid()) { 2317 uint32_t shm_offset = 0;
2300 return; 2318 void* buffer_pointer = nullptr;
2319
2320 ScopedTransferBufferPtr transfer_alloc(size, helper_, transfer_buffer_);
2321 ScopedMappedMemoryPtr mapped_alloc(0, helper_, mapped_memory_.get());
2322
2323 if (transfer_alloc.valid() && transfer_alloc.size() >= size) {
2324 shm_id = transfer_alloc.shm_id();
2325 shm_offset = transfer_alloc.offset();
2326 buffer_pointer = transfer_alloc.address();
2327 } else {
2328 mapped_alloc.Reset(size);
2329 if (mapped_alloc.valid()) {
2330 transfer_alloc.Discard();
2331
2332 mapped_alloc.SetFlushAfterRelease(true);
2333 shm_id = mapped_alloc.shm_id();
2334 shm_offset = mapped_alloc.offset();
2335 buffer_pointer = mapped_alloc.address();
2336 }
2301 } 2337 }
2302 2338
2303 if (buffer.size() >= size) { 2339 if (buffer_pointer) {
2304 void* buffer_pointer = buffer.address();
2305 for (GLsizei z = 0; z < depth; ++z) { 2340 for (GLsizei z = 0; z < depth; ++z) {
2306 // Only the last row of the last image is unpadded. 2341 // Only the last row of the last image is unpadded.
2307 uint32 src_unpadded_row_size = 2342 uint32 src_unpadded_row_size =
2308 (z == depth - 1) ? unpadded_row_size : src_padded_row_size; 2343 (z == depth - 1) ? unpadded_row_size : src_padded_row_size;
2309 // TODO(zmo): Ignore flip_y flag for now. 2344 // TODO(zmo): Ignore flip_y flag for now.
2310 CopyRectToBuffer( 2345 CopyRectToBuffer(
2311 pixels, height, src_unpadded_row_size, src_padded_row_size, false, 2346 pixels, height, src_unpadded_row_size, src_padded_row_size, false,
2312 buffer_pointer, padded_row_size); 2347 buffer_pointer, padded_row_size);
2313 pixels = reinterpret_cast<const int8*>(pixels) + 2348 pixels = reinterpret_cast<const int8*>(pixels) +
2314 src_padded_row_size * src_height; 2349 src_padded_row_size * src_height;
2315 buffer_pointer = reinterpret_cast<int8*>(buffer_pointer) + 2350 buffer_pointer = reinterpret_cast<int8*>(buffer_pointer) +
2316 padded_row_size * height; 2351 padded_row_size * height;
2317 } 2352 }
2318 helper_->TexImage3D( 2353 helper_->TexImage3D(
2319 target, level, internalformat, width, height, depth, format, type, 2354 target, level, internalformat, width, height, depth, format, type,
2320 buffer.shm_id(), buffer.offset()); 2355 shm_id, shm_offset);
2321 CheckGLError(); 2356 CheckGLError();
2322 return; 2357 return;
2323 } 2358 }
2324 2359
2325 // No, so send it using TexSubImage3D. 2360 // No, so send it using TexSubImage3D.
2326 helper_->TexImage3D( 2361 helper_->TexImage3D(
2327 target, level, internalformat, width, height, depth, format, type, 2362 target, level, internalformat, width, height, depth, format, type,
2328 0, 0); 2363 0, 0);
2329 TexSubImage3DImpl( 2364 TexSubImage3DImpl(
2330 target, level, 0, 0, 0, width, height, depth, format, type, 2365 target, level, 0, 0, 0, width, height, depth, format, type,
2331 unpadded_row_size, pixels, src_padded_row_size, GL_TRUE, &buffer, 2366 unpadded_row_size, pixels, src_padded_row_size, GL_TRUE, &transfer_alloc,
2332 padded_row_size); 2367 padded_row_size);
2333 CheckGLError(); 2368 CheckGLError();
2334 } 2369 }
2335 2370
2336 void GLES2Implementation::TexSubImage2D( 2371 void GLES2Implementation::TexSubImage2D(
2337 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, 2372 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width,
2338 GLsizei height, GLenum format, GLenum type, const void* pixels) { 2373 GLsizei height, GLenum format, GLenum type, const void* pixels) {
2339 GPU_CLIENT_SINGLE_THREAD_CHECK(); 2374 GPU_CLIENT_SINGLE_THREAD_CHECK();
2340 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glTexSubImage2D(" 2375 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glTexSubImage2D("
2341 << GLES2Util::GetStringTextureTarget(target) << ", " 2376 << GLES2Util::GetStringTextureTarget(target) << ", "
(...skipping 3403 matching lines...) Expand 10 before | Expand all | Expand 10 after
5745 CheckGLError(); 5780 CheckGLError();
5746 } 5781 }
5747 5782
5748 // Include the auto-generated part of this file. We split this because it means 5783 // Include the auto-generated part of this file. We split this because it means
5749 // we can easily edit the non-auto generated parts right here in this file 5784 // we can easily edit the non-auto generated parts right here in this file
5750 // instead of having to edit some template or the code generator. 5785 // instead of having to edit some template or the code generator.
5751 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" 5786 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h"
5752 5787
5753 } // namespace gles2 5788 } // namespace gles2
5754 } // namespace gpu 5789 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | gpu/command_buffer/client/gles2_implementation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698