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

Unified 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: Same fix for TexImage3D, also share uploading code. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gpu/command_buffer/client/mapped_memory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/client/gles2_implementation.cc
diff --git a/gpu/command_buffer/client/gles2_implementation.cc b/gpu/command_buffer/client/gles2_implementation.cc
index e85929912f6af462e57c7e0ddbda2ee017f606fc..b4f645181a6a260e6ce6ab0950eaeeeb65ea8cf5 100644
--- a/gpu/command_buffer/client/gles2_implementation.cc
+++ b/gpu/command_buffer/client/gles2_implementation.cc
@@ -2187,19 +2187,51 @@ void GLES2Implementation::TexImage2D(
}
// Check if we can send it all at once.
- ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_);
- if (!buffer.valid()) {
+ int32_t shm_id = 0;
+ uint32_t shm_offset = 0;
+ void* buffer_pointer = nullptr;
+
+ ScopedTransferBufferPtr transfer_alloc(size, helper_, transfer_buffer_);
+ ScopedMappedMemoryPtr mapped_alloc(0, helper_, mapped_memory_.get());
+
+ if (transfer_alloc.valid() && transfer_alloc.size() >= size) {
+ shm_id = transfer_alloc.shm_id();
+ shm_offset = transfer_alloc.offset();
+ buffer_pointer = transfer_alloc.address();
+ } else {
+ mapped_alloc.Reset(size);
+ if (mapped_alloc.valid()) {
piman 2015/06/08 21:57:38 It would be good actually in this case, to free th
David Yen 2015/06/08 22:18:01 Is there a way to just mark blocks within the ring
David Yen 2015/06/09 02:03:52 I added a DiscardBlock() function but Maintaining
+ mapped_alloc.SetFlushAfterRelease(true);
+ shm_id = mapped_alloc.shm_id();
+ shm_offset = mapped_alloc.offset();
+ buffer_pointer = mapped_alloc.address();
+ }
+ }
+
+ if (buffer_pointer) {
+ CopyRectToBuffer(
+ pixels, height, unpadded_row_size, src_padded_row_size, unpack_flip_y_,
+ buffer_pointer, padded_row_size);
+ helper_->TexImage2D(
+ target, level, internalformat, width, height, format, type,
+ shm_id, shm_offset);
+ CheckGLError();
return;
}
- if (buffer.size() >= size) {
+ // Check if we can allocate from mapped memory.
piman 2015/06/08 21:57:38 You don't need this code any more, right? This is
David Yen 2015/06/08 22:18:01 Oops, forgot to delete. Done.
+ int32 mapped_shm_id = 0;
+ unsigned int mapped_shm_offset = 0;
+ void* mem = mapped_memory_->Alloc(size, &mapped_shm_id, &mapped_shm_offset);
+ if (mem) {
CopyRectToBuffer(
pixels, height, unpadded_row_size, src_padded_row_size, unpack_flip_y_,
- buffer.address(), padded_row_size);
+ mem, padded_row_size);
helper_->TexImage2D(
target, level, internalformat, width, height, format, type,
- buffer.shm_id(), buffer.offset());
+ mapped_shm_id, mapped_shm_offset);
CheckGLError();
+ mapped_memory_->FreePendingToken(mem, helper_->InsertToken());
return;
}
@@ -2209,7 +2241,7 @@ void GLES2Implementation::TexImage2D(
0, 0);
TexSubImage2DImpl(
target, level, 0, 0, width, height, format, type, unpadded_row_size,
- pixels, src_padded_row_size, GL_TRUE, &buffer, padded_row_size);
+ pixels, src_padded_row_size, GL_TRUE, &transfer_alloc, padded_row_size);
CheckGLError();
}
@@ -2295,13 +2327,28 @@ void GLES2Implementation::TexImage3D(
}
// Check if we can send it all at once.
- ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_);
- if (!buffer.valid()) {
- return;
+ int32_t shm_id = 0;
+ uint32_t shm_offset = 0;
+ void* buffer_pointer = nullptr;
+
+ ScopedTransferBufferPtr transfer_alloc(size, helper_, transfer_buffer_);
+ ScopedMappedMemoryPtr mapped_alloc(0, helper_, mapped_memory_.get());
+
+ if (transfer_alloc.valid() && transfer_alloc.size() >= size) {
+ shm_id = transfer_alloc.shm_id();
+ shm_offset = transfer_alloc.offset();
+ buffer_pointer = transfer_alloc.address();
+ } else {
+ mapped_alloc.Reset(size);
+ if (mapped_alloc.valid()) {
+ mapped_alloc.SetFlushAfterRelease(true);
+ shm_id = mapped_alloc.shm_id();
+ shm_offset = mapped_alloc.offset();
+ buffer_pointer = mapped_alloc.address();
+ }
}
- if (buffer.size() >= size) {
- void* buffer_pointer = buffer.address();
+ if (buffer_pointer) {
for (GLsizei z = 0; z < depth; ++z) {
// Only the last row of the last image is unpadded.
uint32 src_unpadded_row_size =
@@ -2317,18 +2364,33 @@ void GLES2Implementation::TexImage3D(
}
helper_->TexImage3D(
target, level, internalformat, width, height, depth, format, type,
- buffer.shm_id(), buffer.offset());
+ shm_id, shm_offset);
CheckGLError();
return;
}
+ // Check if we can allocate from mapped memory.
+ int32 mapped_shm_id = 0;
+ unsigned int mapped_shm_offset = 0;
+ void* mem = mapped_memory_->Alloc(size, &mapped_shm_id, &mapped_shm_offset);
+ if (mem) {
+ CopyRectToBuffer(
+ pixels, height, unpadded_row_size, src_padded_row_size, unpack_flip_y_,
+ mem, padded_row_size);
+ helper_->TexImage2D(
+ target, level, internalformat, width, height, format, type,
+ mapped_shm_id, mapped_shm_offset);
+ CheckGLError();
+ mapped_memory_->FreePendingToken(mem, helper_->InsertToken());
+ }
+
// No, so send it using TexSubImage3D.
helper_->TexImage3D(
target, level, internalformat, width, height, depth, format, type,
0, 0);
TexSubImage3DImpl(
target, level, 0, 0, 0, width, height, depth, format, type,
- unpadded_row_size, pixels, src_padded_row_size, GL_TRUE, &buffer,
+ unpadded_row_size, pixels, src_padded_row_size, GL_TRUE, &transfer_alloc,
padded_row_size);
CheckGLError();
}
« no previous file with comments | « no previous file | gpu/command_buffer/client/mapped_memory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698