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

Side by Side Diff: gpu/command_buffer/client/gles2_implementation_unittest.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
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 // Tests for GLES2Implementation. 5 // Tests for GLES2Implementation.
6 6
7 #include "gpu/command_buffer/client/gles2_implementation.h" 7 #include "gpu/command_buffer/client/gles2_implementation.h"
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 unsigned int alignment, 126 unsigned int alignment,
127 unsigned int size_to_flush) override; 127 unsigned int size_to_flush) override;
128 int GetShmId() override; 128 int GetShmId() override;
129 void* GetResultBuffer() override; 129 void* GetResultBuffer() override;
130 int GetResultOffset() override; 130 int GetResultOffset() override;
131 void Free() override; 131 void Free() override;
132 bool HaveBuffer() const override; 132 bool HaveBuffer() const override;
133 void* AllocUpTo(unsigned int size, unsigned int* size_allocated) override; 133 void* AllocUpTo(unsigned int size, unsigned int* size_allocated) override;
134 void* Alloc(unsigned int size) override; 134 void* Alloc(unsigned int size) override;
135 RingBuffer::Offset GetOffset(void* pointer) const override; 135 RingBuffer::Offset GetOffset(void* pointer) const override;
136 void DiscardBlock(void* p) override;
136 void FreePendingToken(void* p, unsigned int /* token */) override; 137 void FreePendingToken(void* p, unsigned int /* token */) override;
137 138
138 size_t MaxTransferBufferSize() { 139 size_t MaxTransferBufferSize() {
139 return size_ - result_size_; 140 return size_ - result_size_;
140 } 141 }
141 142
142 unsigned int RoundToAlignment(unsigned int size) { 143 unsigned int RoundToAlignment(unsigned int size) {
143 return (size + alignment_ - 1) & ~(alignment_ - 1); 144 return (size + alignment_ - 1) & ~(alignment_ - 1);
144 } 145 }
145 146
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 void* p = AllocUpTo(size, &temp); 290 void* p = AllocUpTo(size, &temp);
290 EXPECT_EQ(temp, size); 291 EXPECT_EQ(temp, size);
291 return p; 292 return p;
292 } 293 }
293 294
294 RingBuffer::Offset MockTransferBuffer::GetOffset(void* pointer) const { 295 RingBuffer::Offset MockTransferBuffer::GetOffset(void* pointer) const {
295 // Make sure each buffer has a different offset. 296 // Make sure each buffer has a different offset.
296 return static_cast<uint8*>(pointer) - actual_buffer(); 297 return static_cast<uint8*>(pointer) - actual_buffer();
297 } 298 }
298 299
300 void MockTransferBuffer::DiscardBlock(void* p) {
301 EXPECT_EQ(last_alloc_, p);
302 last_alloc_ = NULL;
303 }
304
299 void MockTransferBuffer::FreePendingToken(void* p, unsigned int /* token */) { 305 void MockTransferBuffer::FreePendingToken(void* p, unsigned int /* token */) {
300 EXPECT_EQ(last_alloc_, p); 306 EXPECT_EQ(last_alloc_, p);
301 last_alloc_ = NULL; 307 last_alloc_ = NULL;
302 } 308 }
303 309
304 // API wrapper for Buffers. 310 // API wrapper for Buffers.
305 class GenBuffersAPI { 311 class GenBuffersAPI {
306 public: 312 public:
307 static void Gen(GLES2Implementation* gl_impl, GLsizei n, GLuint* ids) { 313 static void Gen(GLES2Implementation* gl_impl, GLsizei n, GLuint* ids) {
308 gl_impl->GenBuffers(n, ids); 314 gl_impl->GenBuffers(n, ids);
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 584
579 void ClearCommands() { 585 void ClearCommands() {
580 scoped_refptr<Buffer> ring_buffer = helper_->get_ring_buffer(); 586 scoped_refptr<Buffer> ring_buffer = helper_->get_ring_buffer();
581 memset(ring_buffer->memory(), kInitialValue, ring_buffer->size()); 587 memset(ring_buffer->memory(), kInitialValue, ring_buffer->size());
582 } 588 }
583 589
584 size_t MaxTransferBufferSize() { 590 size_t MaxTransferBufferSize() {
585 return transfer_buffer_->MaxTransferBufferSize(); 591 return transfer_buffer_->MaxTransferBufferSize();
586 } 592 }
587 593
594 void SetMappedMemoryLimit(size_t limit) {
595 gl_->mapped_memory_->set_max_allocated_bytes(limit);
596 }
597
588 ExpectedMemoryInfo GetExpectedMemory(size_t size) { 598 ExpectedMemoryInfo GetExpectedMemory(size_t size) {
589 return transfer_buffer_->GetExpectedMemory(size); 599 return transfer_buffer_->GetExpectedMemory(size);
590 } 600 }
591 601
592 ExpectedMemoryInfo GetExpectedResultMemory(size_t size) { 602 ExpectedMemoryInfo GetExpectedResultMemory(size_t size) {
593 return transfer_buffer_->GetExpectedResultMemory(size); 603 return transfer_buffer_->GetExpectedResultMemory(size);
594 } 604 }
595 605
606 ExpectedMemoryInfo GetExpectedMappedMemory(size_t size) {
607 ExpectedMemoryInfo mem;
608
609 // Temporarily allocate memory and expect that memory block to be reused.
610 mem.ptr = static_cast<uint8*>(gl_->mapped_memory_->Alloc(size,
611 &mem.id,
612 &mem.offset));
613 gl_->mapped_memory_->Free(mem.ptr);
614
615 return mem;
616 }
617
596 // Sets the ProgramInfoManager. The manager will be owned 618 // Sets the ProgramInfoManager. The manager will be owned
597 // by the ShareGroup. 619 // by the ShareGroup.
598 void SetProgramInfoManager(ProgramInfoManager* manager) { 620 void SetProgramInfoManager(ProgramInfoManager* manager) {
599 gl_->share_group()->set_program_info_manager(manager); 621 gl_->share_group()->set_program_info_manager(manager);
600 } 622 }
601 623
602 int CheckError() { 624 int CheckError() {
603 ExpectedMemoryInfo result = 625 ExpectedMemoryInfo result =
604 GetExpectedResultMemory(sizeof(cmds::GetError::Result)); 626 GetExpectedResultMemory(sizeof(cmds::GetError::Result));
605 EXPECT_CALL(*command_buffer(), OnFlush()) 627 EXPECT_CALL(*command_buffer(), OnFlush())
(...skipping 1688 matching lines...) Expand 10 before | Expand all | Expand 10 after
2294 const void* commands2 = GetPut(); 2316 const void* commands2 = GetPut();
2295 gl_->TexImage2D( 2317 gl_->TexImage2D(
2296 kTarget, kLevel, kFormat, kWidth, kHeight, kBorder, kFormat, kType, 2318 kTarget, kLevel, kFormat, kWidth, kHeight, kBorder, kFormat, kType,
2297 pixels); 2319 pixels);
2298 EXPECT_EQ(0, memcmp(&expected2, commands2, sizeof(expected2))); 2320 EXPECT_EQ(0, memcmp(&expected2, commands2, sizeof(expected2)));
2299 EXPECT_TRUE(CheckRect( 2321 EXPECT_TRUE(CheckRect(
2300 kWidth, kHeight, kFormat, kType, kPixelStoreUnpackAlignment, true, 2322 kWidth, kHeight, kFormat, kType, kPixelStoreUnpackAlignment, true,
2301 pixels, mem2.ptr)); 2323 pixels, mem2.ptr));
2302 } 2324 }
2303 2325
2326 TEST_F(GLES2ImplementationTest, TexImage2DViaMappedMem) {
2327 struct Cmds {
2328 cmds::TexImage2D tex_image_2d;
2329 cmd::SetToken set_token;
2330 };
2331 const GLenum kTarget = GL_TEXTURE_2D;
2332 const GLint kLevel = 0;
2333 const GLenum kFormat = GL_RGB;
2334 const GLsizei kWidth = 3;
2335 const GLint kBorder = 0;
2336 const GLenum kType = GL_UNSIGNED_BYTE;
2337 const GLint kPixelStoreUnpackAlignment = 4;
2338
2339 uint32 size = 0;
2340 uint32 unpadded_row_size = 0;
2341 uint32 padded_row_size = 0;
2342 ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
2343 kWidth, 2, 1, kFormat, kType, kPixelStoreUnpackAlignment,
2344 &size, &unpadded_row_size, &padded_row_size));
2345 const GLsizei kMaxHeight = (MaxTransferBufferSize() / padded_row_size) * 2;
2346 const GLsizei kHeight = kMaxHeight * 2;
2347 ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
2348 kWidth, kHeight, 1, kFormat, kType, kPixelStoreUnpackAlignment,
2349 &size, &unpadded_row_size, &padded_row_size));
2350
2351 scoped_ptr<uint8[]> pixels(new uint8[size]);
2352 for (uint32 ii = 0; ii < size; ++ii) {
2353 pixels[ii] = static_cast<uint8>(ii);
2354 }
2355
2356 ExpectedMemoryInfo mem1 = GetExpectedMappedMemory(size);
2357
2358 Cmds expected;
2359 expected.tex_image_2d.Init(
2360 kTarget, kLevel, kFormat, kWidth, kHeight, kFormat, kType,
2361 mem1.id, mem1.offset);
2362 expected.set_token.Init(GetNextToken());
2363 gl_->TexImage2D(
2364 kTarget, kLevel, kFormat, kWidth, kHeight, kBorder, kFormat, kType,
2365 pixels.get());
2366 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
2367 EXPECT_TRUE(CheckRect(
2368 kWidth, kHeight, kFormat, kType, kPixelStoreUnpackAlignment, false,
2369 pixels.get(), mem1.ptr));
2370 }
2371
2304 // Test TexImage2D with 2 writes 2372 // Test TexImage2D with 2 writes
2305 TEST_F(GLES2ImplementationTest, TexImage2D2Writes) { 2373 TEST_F(GLES2ImplementationTest, TexImage2DViaTexSubImage2D) {
2374 // Set limit to 1 to effectively disable mapped memory.
2375 SetMappedMemoryLimit(1);
2376
2306 struct Cmds { 2377 struct Cmds {
2307 cmds::TexImage2D tex_image_2d; 2378 cmds::TexImage2D tex_image_2d;
2308 cmds::TexSubImage2D tex_sub_image_2d1; 2379 cmds::TexSubImage2D tex_sub_image_2d1;
2309 cmd::SetToken set_token1; 2380 cmd::SetToken set_token1;
2310 cmds::TexSubImage2D tex_sub_image_2d2; 2381 cmds::TexSubImage2D tex_sub_image_2d2;
2311 cmd::SetToken set_token2; 2382 cmd::SetToken set_token2;
2312 }; 2383 };
2313 const GLenum kTarget = GL_TEXTURE_2D; 2384 const GLenum kTarget = GL_TEXTURE_2D;
2314 const GLint kLevel = 0; 2385 const GLint kLevel = 0;
2315 const GLenum kFormat = GL_RGB; 2386 const GLenum kFormat = GL_RGB;
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
2719 gl_->TexImage3D( 2790 gl_->TexImage3D(
2720 kTarget, kLevel, kFormat, kWidth, kHeight, kDepth, kBorder, 2791 kTarget, kLevel, kFormat, kWidth, kHeight, kDepth, kBorder,
2721 kFormat, kType, pixels.get()); 2792 kFormat, kType, pixels.get());
2722 2793
2723 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); 2794 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
2724 EXPECT_TRUE(CheckRect( 2795 EXPECT_TRUE(CheckRect(
2725 kWidth, kHeight * kDepth, kFormat, kType, kPixelStoreUnpackAlignment, 2796 kWidth, kHeight * kDepth, kFormat, kType, kPixelStoreUnpackAlignment,
2726 false, reinterpret_cast<uint8*>(pixels.get()), mem.ptr)); 2797 false, reinterpret_cast<uint8*>(pixels.get()), mem.ptr));
2727 } 2798 }
2728 2799
2800 TEST_F(GLES2ImplementationTest, TexImage3DViaMappedMem) {
2801 struct Cmds {
2802 cmds::TexImage3D tex_image_3d;
2803 };
2804 const GLenum kTarget = GL_TEXTURE_3D;
2805 const GLint kLevel = 0;
2806 const GLint kBorder = 0;
2807 const GLenum kFormat = GL_RGB;
2808 const GLenum kType = GL_UNSIGNED_BYTE;
2809 const GLint kPixelStoreUnpackAlignment = 4;
2810 const GLsizei kWidth = 3;
2811 const GLsizei kDepth = 2;
2812
2813 uint32 size = 0;
2814 uint32 unpadded_row_size = 0;
2815 uint32 padded_row_size = 0;
2816 ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
2817 kWidth, 2, kDepth, kFormat, kType, kPixelStoreUnpackAlignment,
2818 &size, &unpadded_row_size, &padded_row_size));
2819 // Makes sure we can just send over the data in one command.
2820 const GLsizei kMaxHeight = MaxTransferBufferSize() / padded_row_size / kDepth;
2821 const GLsizei kHeight = kMaxHeight * 2;
2822 ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
2823 kWidth, kHeight, kDepth, kFormat, kType, kPixelStoreUnpackAlignment,
2824 &size, NULL, NULL));
2825
2826 scoped_ptr<uint8[]> pixels(new uint8[size]);
2827 for (uint32 ii = 0; ii < size; ++ii) {
2828 pixels[ii] = static_cast<uint8>(ii);
2829 }
2830
2831 ExpectedMemoryInfo mem = GetExpectedMappedMemory(size);
2832
2833 Cmds expected;
2834 expected.tex_image_3d.Init(
2835 kTarget, kLevel, kFormat, kWidth, kHeight, kDepth,
2836 kFormat, kType, mem.id, mem.offset);
2837
2838 gl_->TexImage3D(
2839 kTarget, kLevel, kFormat, kWidth, kHeight, kDepth, kBorder,
2840 kFormat, kType, pixels.get());
2841
2842 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
2843 EXPECT_TRUE(CheckRect(
2844 kWidth, kHeight * kDepth, kFormat, kType, kPixelStoreUnpackAlignment,
2845 false, reinterpret_cast<uint8*>(pixels.get()), mem.ptr));
2846 }
2847
2729 TEST_F(GLES2ImplementationTest, TexImage3DViaTexSubImage3D) { 2848 TEST_F(GLES2ImplementationTest, TexImage3DViaTexSubImage3D) {
2849 // Set limit to 1 to effectively disable mapped memory.
2850 SetMappedMemoryLimit(1);
2851
2730 struct Cmds { 2852 struct Cmds {
2731 cmds::TexImage3D tex_image_3d; 2853 cmds::TexImage3D tex_image_3d;
2732 cmds::TexSubImage3D tex_sub_image_3d1; 2854 cmds::TexSubImage3D tex_sub_image_3d1;
2733 cmd::SetToken set_token; 2855 cmd::SetToken set_token;
2734 cmds::TexSubImage3D tex_sub_image_3d2; 2856 cmds::TexSubImage3D tex_sub_image_3d2;
2735 }; 2857 };
2736 const GLenum kTarget = GL_TEXTURE_3D; 2858 const GLenum kTarget = GL_TEXTURE_3D;
2737 const GLint kLevel = 0; 2859 const GLint kLevel = 0;
2738 const GLint kBorder = 0; 2860 const GLint kBorder = 0;
2739 const GLenum kFormat = GL_RGB; 2861 const GLenum kFormat = GL_RGB;
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
3817 TEST_F(GLES2ImplementationManualInitTest, FailInitOnTransferBufferFail) { 3939 TEST_F(GLES2ImplementationManualInitTest, FailInitOnTransferBufferFail) {
3818 ContextInitOptions init_options; 3940 ContextInitOptions init_options;
3819 init_options.transfer_buffer_initialize_fail = true; 3941 init_options.transfer_buffer_initialize_fail = true;
3820 EXPECT_FALSE(Initialize(init_options)); 3942 EXPECT_FALSE(Initialize(init_options));
3821 } 3943 }
3822 3944
3823 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" 3945 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h"
3824 3946
3825 } // namespace gles2 3947 } // namespace gles2
3826 } // namespace gpu 3948 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation.cc ('k') | gpu/command_buffer/client/mapped_memory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698