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

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: Discard blocks by simply marking them as padding. 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 592 }
587 593
588 ExpectedMemoryInfo GetExpectedMemory(size_t size) { 594 ExpectedMemoryInfo GetExpectedMemory(size_t size) {
589 return transfer_buffer_->GetExpectedMemory(size); 595 return transfer_buffer_->GetExpectedMemory(size);
590 } 596 }
591 597
592 ExpectedMemoryInfo GetExpectedResultMemory(size_t size) { 598 ExpectedMemoryInfo GetExpectedResultMemory(size_t size) {
593 return transfer_buffer_->GetExpectedResultMemory(size); 599 return transfer_buffer_->GetExpectedResultMemory(size);
594 } 600 }
595 601
602 ExpectedMemoryInfo GetExpectedMappedMemory(size_t size) {
603 ExpectedMemoryInfo mem;
604
605 // Temporarily allocate memory and expect that memory block to be reused.
606 mem.ptr = static_cast<uint8*>(gl_->mapped_memory_->Alloc(size,
607 &mem.id,
608 &mem.offset));
609 gl_->mapped_memory_->Free(mem.ptr);
610
611 return mem;
612 }
613
596 // Sets the ProgramInfoManager. The manager will be owned 614 // Sets the ProgramInfoManager. The manager will be owned
597 // by the ShareGroup. 615 // by the ShareGroup.
598 void SetProgramInfoManager(ProgramInfoManager* manager) { 616 void SetProgramInfoManager(ProgramInfoManager* manager) {
599 gl_->share_group()->set_program_info_manager(manager); 617 gl_->share_group()->set_program_info_manager(manager);
600 } 618 }
601 619
602 int CheckError() { 620 int CheckError() {
603 ExpectedMemoryInfo result = 621 ExpectedMemoryInfo result =
604 GetExpectedResultMemory(sizeof(cmds::GetError::Result)); 622 GetExpectedResultMemory(sizeof(cmds::GetError::Result));
605 EXPECT_CALL(*command_buffer(), OnFlush()) 623 EXPECT_CALL(*command_buffer(), OnFlush())
(...skipping 1688 matching lines...) Expand 10 before | Expand all | Expand 10 after
2294 const void* commands2 = GetPut(); 2312 const void* commands2 = GetPut();
2295 gl_->TexImage2D( 2313 gl_->TexImage2D(
2296 kTarget, kLevel, kFormat, kWidth, kHeight, kBorder, kFormat, kType, 2314 kTarget, kLevel, kFormat, kWidth, kHeight, kBorder, kFormat, kType,
2297 pixels); 2315 pixels);
2298 EXPECT_EQ(0, memcmp(&expected2, commands2, sizeof(expected2))); 2316 EXPECT_EQ(0, memcmp(&expected2, commands2, sizeof(expected2)));
2299 EXPECT_TRUE(CheckRect( 2317 EXPECT_TRUE(CheckRect(
2300 kWidth, kHeight, kFormat, kType, kPixelStoreUnpackAlignment, true, 2318 kWidth, kHeight, kFormat, kType, kPixelStoreUnpackAlignment, true,
2301 pixels, mem2.ptr)); 2319 pixels, mem2.ptr));
2302 } 2320 }
2303 2321
2322 TEST_F(GLES2ImplementationTest, TexImage2DViaMappedMem) {
2323 struct Cmds {
2324 cmds::TexImage2D tex_image_2d;
2325 cmd::SetToken set_token;
2326 };
2327 const GLenum kTarget = GL_TEXTURE_2D;
2328 const GLint kLevel = 0;
2329 const GLenum kFormat = GL_RGB;
2330 const GLsizei kWidth = 3;
2331 const GLint kBorder = 0;
2332 const GLenum kType = GL_UNSIGNED_BYTE;
2333 const GLint kPixelStoreUnpackAlignment = 4;
2334
2335 uint32 size = 0;
2336 uint32 unpadded_row_size = 0;
2337 uint32 padded_row_size = 0;
2338 ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
2339 kWidth, 2, 1, kFormat, kType, kPixelStoreUnpackAlignment,
2340 &size, &unpadded_row_size, &padded_row_size));
2341 const GLsizei kMaxHeight = (MaxTransferBufferSize() / padded_row_size) * 2;
2342 const GLsizei kHeight = kMaxHeight * 2;
2343 ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
2344 kWidth, kHeight, 1, kFormat, kType, kPixelStoreUnpackAlignment,
2345 &size, &unpadded_row_size, &padded_row_size));
2346
2347 scoped_ptr<uint8[]> pixels(new uint8[size]);
2348 for (uint32 ii = 0; ii < size; ++ii) {
2349 pixels[ii] = static_cast<uint8>(ii);
2350 }
2351
2352 ExpectedMemoryInfo mem1 = GetExpectedMappedMemory(size);
2353
2354 Cmds expected;
2355 expected.tex_image_2d.Init(
2356 kTarget, kLevel, kFormat, kWidth, kHeight, kFormat, kType,
2357 mem1.id, mem1.offset);
2358 expected.set_token.Init(GetNextToken());
2359 gl_->TexImage2D(
2360 kTarget, kLevel, kFormat, kWidth, kHeight, kBorder, kFormat, kType,
2361 pixels.get());
2362 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
2363 EXPECT_TRUE(CheckRect(
2364 kWidth, kHeight, kFormat, kType, kPixelStoreUnpackAlignment, false,
2365 pixels.get(), mem1.ptr));
2366 }
2367
2304 // Test TexImage2D with 2 writes 2368 // Test TexImage2D with 2 writes
2305 TEST_F(GLES2ImplementationTest, TexImage2D2Writes) { 2369 TEST_F(GLES2ImplementationTest, TexImage2DViaTexSubImage2D) {
2370 // Reinitialize GLES2Implementation with max mapped memory of 1 to force
2371 // TexSubImage2D code path.
2372 ASSERT_TRUE(gl_->Initialize(kTransferBufferSize,
2373 kTransferBufferSize,
2374 kTransferBufferSize,
2375 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 // Reinitialize GLES2Implementation with max mapped memory of 1 to force
2850 // TexSubImage3D code path.
2851 ASSERT_TRUE(gl_->Initialize(kTransferBufferSize,
2852 kTransferBufferSize,
2853 kTransferBufferSize,
2854 1));
2730 struct Cmds { 2855 struct Cmds {
2731 cmds::TexImage3D tex_image_3d; 2856 cmds::TexImage3D tex_image_3d;
2732 cmds::TexSubImage3D tex_sub_image_3d1; 2857 cmds::TexSubImage3D tex_sub_image_3d1;
2733 cmd::SetToken set_token; 2858 cmd::SetToken set_token;
2734 cmds::TexSubImage3D tex_sub_image_3d2; 2859 cmds::TexSubImage3D tex_sub_image_3d2;
2735 }; 2860 };
2736 const GLenum kTarget = GL_TEXTURE_3D; 2861 const GLenum kTarget = GL_TEXTURE_3D;
2737 const GLint kLevel = 0; 2862 const GLint kLevel = 0;
2738 const GLint kBorder = 0; 2863 const GLint kBorder = 0;
2739 const GLenum kFormat = GL_RGB; 2864 const GLenum kFormat = GL_RGB;
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
3817 TEST_F(GLES2ImplementationManualInitTest, FailInitOnTransferBufferFail) { 3942 TEST_F(GLES2ImplementationManualInitTest, FailInitOnTransferBufferFail) {
3818 ContextInitOptions init_options; 3943 ContextInitOptions init_options;
3819 init_options.transfer_buffer_initialize_fail = true; 3944 init_options.transfer_buffer_initialize_fail = true;
3820 EXPECT_FALSE(Initialize(init_options)); 3945 EXPECT_FALSE(Initialize(init_options));
3821 } 3946 }
3822 3947
3823 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" 3948 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h"
3824 3949
3825 } // namespace gles2 3950 } // namespace gles2
3826 } // namespace gpu 3951 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698