OLD | NEW |
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 <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
10 #include <GLES2/gl2ext.h> | 10 #include <GLES2/gl2ext.h> |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 public: | 420 public: |
421 TestContext() : commands_(NULL), token_(0) {} | 421 TestContext() : commands_(NULL), token_(0) {} |
422 | 422 |
423 bool Initialize(ShareGroup* share_group, | 423 bool Initialize(ShareGroup* share_group, |
424 bool bind_generates_resource_client, | 424 bool bind_generates_resource_client, |
425 bool bind_generates_resource_service, | 425 bool bind_generates_resource_service, |
426 bool lose_context_when_out_of_memory, | 426 bool lose_context_when_out_of_memory, |
427 bool transfer_buffer_initialize_fail, | 427 bool transfer_buffer_initialize_fail, |
428 bool sync_query, | 428 bool sync_query, |
429 bool occlusion_query_boolean, | 429 bool occlusion_query_boolean, |
430 bool timer_queries) { | 430 bool timer_queries, |
| 431 int major_version, |
| 432 int minor_version) { |
431 command_buffer_.reset(new StrictMock<MockClientCommandBuffer>()); | 433 command_buffer_.reset(new StrictMock<MockClientCommandBuffer>()); |
432 if (!command_buffer_->Initialize()) | 434 if (!command_buffer_->Initialize()) |
433 return false; | 435 return false; |
434 | 436 |
435 transfer_buffer_.reset( | 437 transfer_buffer_.reset( |
436 new MockTransferBuffer(command_buffer_.get(), | 438 new MockTransferBuffer(command_buffer_.get(), |
437 kTransferBufferSize, | 439 kTransferBufferSize, |
438 GLES2Implementation::kStartingOffset, | 440 GLES2Implementation::kStartingOffset, |
439 GLES2Implementation::kAlignment, | 441 GLES2Implementation::kAlignment, |
440 transfer_buffer_initialize_fail)); | 442 transfer_buffer_initialize_fail)); |
(...skipping 25 matching lines...) Expand all Loading... |
466 kNumCompressedTextureFormats; | 468 kNumCompressedTextureFormats; |
467 capabilities.num_shader_binary_formats = kNumShaderBinaryFormats; | 469 capabilities.num_shader_binary_formats = kNumShaderBinaryFormats; |
468 capabilities.max_transform_feedback_separate_attribs = | 470 capabilities.max_transform_feedback_separate_attribs = |
469 kMaxTransformFeedbackSeparateAttribs; | 471 kMaxTransformFeedbackSeparateAttribs; |
470 capabilities.max_uniform_buffer_bindings = kMaxUniformBufferBindings; | 472 capabilities.max_uniform_buffer_bindings = kMaxUniformBufferBindings; |
471 capabilities.bind_generates_resource_chromium = | 473 capabilities.bind_generates_resource_chromium = |
472 bind_generates_resource_service ? 1 : 0; | 474 bind_generates_resource_service ? 1 : 0; |
473 capabilities.sync_query = sync_query; | 475 capabilities.sync_query = sync_query; |
474 capabilities.occlusion_query_boolean = occlusion_query_boolean; | 476 capabilities.occlusion_query_boolean = occlusion_query_boolean; |
475 capabilities.timer_queries = timer_queries; | 477 capabilities.timer_queries = timer_queries; |
| 478 capabilities.major_version = major_version; |
| 479 capabilities.minor_version = minor_version; |
476 EXPECT_CALL(*gpu_control_, GetCapabilities()) | 480 EXPECT_CALL(*gpu_control_, GetCapabilities()) |
477 .WillOnce(testing::Return(capabilities)); | 481 .WillOnce(testing::Return(capabilities)); |
478 | 482 |
479 { | 483 { |
480 InSequence sequence; | 484 InSequence sequence; |
481 | 485 |
482 const bool support_client_side_arrays = true; | 486 const bool support_client_side_arrays = true; |
483 gl_.reset(new GLES2Implementation(helper_.get(), | 487 gl_.reset(new GLES2Implementation(helper_.get(), |
484 share_group, | 488 share_group, |
485 transfer_buffer_.get(), | 489 transfer_buffer_.get(), |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 } | 568 } |
565 | 569 |
566 struct ContextInitOptions { | 570 struct ContextInitOptions { |
567 ContextInitOptions() | 571 ContextInitOptions() |
568 : bind_generates_resource_client(true), | 572 : bind_generates_resource_client(true), |
569 bind_generates_resource_service(true), | 573 bind_generates_resource_service(true), |
570 lose_context_when_out_of_memory(false), | 574 lose_context_when_out_of_memory(false), |
571 transfer_buffer_initialize_fail(false), | 575 transfer_buffer_initialize_fail(false), |
572 sync_query(true), | 576 sync_query(true), |
573 occlusion_query_boolean(true), | 577 occlusion_query_boolean(true), |
574 timer_queries(true) {} | 578 timer_queries(true), |
| 579 major_version(2), |
| 580 minor_version(0) {} |
575 | 581 |
576 bool bind_generates_resource_client; | 582 bool bind_generates_resource_client; |
577 bool bind_generates_resource_service; | 583 bool bind_generates_resource_service; |
578 bool lose_context_when_out_of_memory; | 584 bool lose_context_when_out_of_memory; |
579 bool transfer_buffer_initialize_fail; | 585 bool transfer_buffer_initialize_fail; |
580 bool sync_query; | 586 bool sync_query; |
581 bool occlusion_query_boolean; | 587 bool occlusion_query_boolean; |
582 bool timer_queries; | 588 bool timer_queries; |
| 589 int major_version; |
| 590 int minor_version; |
583 }; | 591 }; |
584 | 592 |
585 bool Initialize(const ContextInitOptions& init_options) { | 593 bool Initialize(const ContextInitOptions& init_options) { |
586 bool success = true; | 594 bool success = true; |
587 share_group_ = new ShareGroup(init_options.bind_generates_resource_client, | 595 share_group_ = new ShareGroup(init_options.bind_generates_resource_client, |
588 0 /* tracing_id */); | 596 0 /* tracing_id */); |
589 | 597 |
590 for (int i = 0; i < kNumTestContexts; i++) { | 598 for (int i = 0; i < kNumTestContexts; i++) { |
591 if (!test_contexts_[i].Initialize( | 599 if (!test_contexts_[i].Initialize( |
592 share_group_.get(), | 600 share_group_.get(), |
593 init_options.bind_generates_resource_client, | 601 init_options.bind_generates_resource_client, |
594 init_options.bind_generates_resource_service, | 602 init_options.bind_generates_resource_service, |
595 init_options.lose_context_when_out_of_memory, | 603 init_options.lose_context_when_out_of_memory, |
596 init_options.transfer_buffer_initialize_fail, | 604 init_options.transfer_buffer_initialize_fail, |
597 init_options.sync_query, | 605 init_options.sync_query, |
598 init_options.occlusion_query_boolean, | 606 init_options.occlusion_query_boolean, |
599 init_options.timer_queries)) | 607 init_options.timer_queries, |
| 608 init_options.major_version, |
| 609 init_options.minor_version)) |
600 success = false; | 610 success = false; |
601 } | 611 } |
602 | 612 |
603 // Default to test context 0. | 613 // Default to test context 0. |
604 gpu_control_ = test_contexts_[0].gpu_control_.get(); | 614 gpu_control_ = test_contexts_[0].gpu_control_.get(); |
605 helper_ = test_contexts_[0].helper_.get(); | 615 helper_ = test_contexts_[0].helper_.get(); |
606 transfer_buffer_ = test_contexts_[0].transfer_buffer_.get(); | 616 transfer_buffer_ = test_contexts_[0].transfer_buffer_.get(); |
607 gl_ = test_contexts_[0].gl_.get(); | 617 gl_ = test_contexts_[0].gl_.get(); |
608 commands_ = test_contexts_[0].commands_; | 618 commands_ = test_contexts_[0].commands_; |
609 return success; | 619 return success; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 } | 802 } |
793 }; | 803 }; |
794 | 804 |
795 void GLES2ImplementationStrictSharedTest::SetUp() { | 805 void GLES2ImplementationStrictSharedTest::SetUp() { |
796 ContextInitOptions init_options; | 806 ContextInitOptions init_options; |
797 init_options.bind_generates_resource_client = false; | 807 init_options.bind_generates_resource_client = false; |
798 init_options.bind_generates_resource_service = false; | 808 init_options.bind_generates_resource_service = false; |
799 ASSERT_TRUE(Initialize(init_options)); | 809 ASSERT_TRUE(Initialize(init_options)); |
800 } | 810 } |
801 | 811 |
| 812 class GLES3ImplementationTest : public GLES2ImplementationTest { |
| 813 protected: |
| 814 void SetUp() override; |
| 815 }; |
| 816 |
| 817 void GLES3ImplementationTest::SetUp() { |
| 818 ContextInitOptions init_options; |
| 819 init_options.major_version = 3; |
| 820 init_options.minor_version = 0; |
| 821 ASSERT_TRUE(Initialize(init_options)); |
| 822 } |
| 823 |
802 // GCC requires these declarations, but MSVC requires they not be present | 824 // GCC requires these declarations, but MSVC requires they not be present |
803 #ifndef _MSC_VER | 825 #ifndef _MSC_VER |
804 const uint8_t GLES2ImplementationTest::kInitialValue; | 826 const uint8_t GLES2ImplementationTest::kInitialValue; |
805 const int32_t GLES2ImplementationTest::kNumCommandEntries; | 827 const int32_t GLES2ImplementationTest::kNumCommandEntries; |
806 const int32_t GLES2ImplementationTest::kCommandBufferSizeBytes; | 828 const int32_t GLES2ImplementationTest::kCommandBufferSizeBytes; |
807 const size_t GLES2ImplementationTest::kTransferBufferSize; | 829 const size_t GLES2ImplementationTest::kTransferBufferSize; |
808 const GLint GLES2ImplementationTest::kMaxCombinedTextureImageUnits; | 830 const GLint GLES2ImplementationTest::kMaxCombinedTextureImageUnits; |
809 const GLint GLES2ImplementationTest::kMaxCubeMapTextureSize; | 831 const GLint GLES2ImplementationTest::kMaxCubeMapTextureSize; |
810 const GLint GLES2ImplementationTest::kMaxFragmentUniformVectors; | 832 const GLint GLES2ImplementationTest::kMaxFragmentUniformVectors; |
811 const GLint GLES2ImplementationTest::kMaxRenderbufferSize; | 833 const GLint GLES2ImplementationTest::kMaxRenderbufferSize; |
(...skipping 1683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2495 | 2517 |
2496 gl_->TexImage2D( | 2518 gl_->TexImage2D( |
2497 kTarget, kLevel, kFormat, kWidth, kHeight, kBorder, kFormat, kType, | 2519 kTarget, kLevel, kFormat, kWidth, kHeight, kBorder, kFormat, kType, |
2498 pixels.get()); | 2520 pixels.get()); |
2499 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); | 2521 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); |
2500 EXPECT_TRUE(CheckRect( | 2522 EXPECT_TRUE(CheckRect( |
2501 kWidth, kHeight / 2, kFormat, kType, kPixelStoreUnpackAlignment, | 2523 kWidth, kHeight / 2, kFormat, kType, kPixelStoreUnpackAlignment, |
2502 pixels.get() + kHeight / 2 * padded_row_size, mem2.ptr)); | 2524 pixels.get() + kHeight / 2 * padded_row_size, mem2.ptr)); |
2503 } | 2525 } |
2504 | 2526 |
2505 TEST_F(GLES2ImplementationTest, SubImageUnpack) { | 2527 TEST_F(GLES3ImplementationTest, SubImage2DUnpack) { |
2506 static const GLint unpack_alignments[] = { 1, 2, 4, 8 }; | 2528 static const GLint unpack_alignments[] = { 1, 2, 4, 8 }; |
2507 | 2529 |
2508 static const GLenum kFormat = GL_RGB; | 2530 static const GLenum kFormat = GL_RGB; |
2509 static const GLenum kType = GL_UNSIGNED_BYTE; | 2531 static const GLenum kType = GL_UNSIGNED_BYTE; |
2510 static const GLint kLevel = 0; | 2532 static const GLint kLevel = 0; |
2511 static const GLint kBorder = 0; | 2533 static const GLint kBorder = 0; |
2512 // We're testing using the unpack params to pull a subimage out of a larger | 2534 // We're testing using the unpack params to pull a subimage out of a larger |
2513 // source of pixels. Here we specify the subimage by its border rows / | 2535 // source of pixels. Here we specify the subimage by its border rows / |
2514 // columns. | 2536 // columns. |
2515 static const GLint kSrcWidth = 33; | 2537 static const GLint kSrcWidth = 33; |
2516 static const GLint kSrcSubImageX0 = 11; | 2538 static const GLint kSrcSubImageX0 = 11; |
2517 static const GLint kSrcSubImageX1 = 20; | 2539 static const GLint kSrcSubImageX1 = 20; |
2518 static const GLint kSrcSubImageY0 = 18; | 2540 static const GLint kSrcSubImageY0 = 18; |
2519 static const GLint kSrcSubImageY1 = 23; | 2541 static const GLint kSrcSubImageY1 = 23; |
2520 static const GLint kSrcSubImageWidth = kSrcSubImageX1 - kSrcSubImageX0; | 2542 static const GLint kSrcSubImageWidth = kSrcSubImageX1 - kSrcSubImageX0; |
2521 static const GLint kSrcSubImageHeight = kSrcSubImageY1 - kSrcSubImageY0; | 2543 static const GLint kSrcSubImageHeight = kSrcSubImageY1 - kSrcSubImageY0; |
2522 | 2544 |
2523 // these are only used in the texsubimage tests | 2545 // these are only used in the texsubimage tests |
2524 static const GLint kTexWidth = 1023; | 2546 static const GLint kTexWidth = 1023; |
2525 static const GLint kTexHeight = 511; | 2547 static const GLint kTexHeight = 511; |
2526 static const GLint kTexSubXOffset = 419; | 2548 static const GLint kTexSubXOffset = 419; |
2527 static const GLint kTexSubYOffset = 103; | 2549 static const GLint kTexSubYOffset = 103; |
2528 | 2550 |
2529 struct { | 2551 struct { |
2530 cmds::PixelStorei pixel_store_i[4]; | 2552 cmds::PixelStorei pixel_store_i[2]; |
2531 cmds::TexImage2D tex_image_2d; | 2553 cmds::TexImage2D tex_image_2d; |
2532 } texImageExpected; | 2554 } texImageExpected; |
2533 | 2555 |
2534 struct { | 2556 struct { |
2535 cmds::PixelStorei pixel_store_i[4]; | 2557 cmds::PixelStorei pixel_store_i[2]; |
2536 cmds::TexImage2D tex_image_2d; | 2558 cmds::TexImage2D tex_image_2d; |
2537 cmds::TexSubImage2D tex_sub_image_2d; | 2559 cmds::TexSubImage2D tex_sub_image_2d; |
2538 } texSubImageExpected; | 2560 } texSubImageExpected; |
2539 | 2561 |
2540 uint32_t src_size; | 2562 uint32_t pixel_size; |
2541 ASSERT_TRUE(GLES2Util::ComputeImageDataSizes( | 2563 PixelStoreParams pixel_params; |
2542 kSrcWidth, kSrcSubImageY1, 1, kFormat, kType, 8, &src_size, NULL, NULL)); | 2564 // Makes sure the pixels size is large enough for all tests. |
| 2565 pixel_params.alignment = 8; |
| 2566 ASSERT_TRUE(GLES2Util::ComputeImageDataSizesES3( |
| 2567 kSrcWidth, kSrcSubImageY1, 1, kFormat, kType, |
| 2568 pixel_params, &pixel_size, nullptr, nullptr, nullptr, nullptr)); |
2543 scoped_ptr<uint8_t[]> src_pixels; | 2569 scoped_ptr<uint8_t[]> src_pixels; |
2544 src_pixels.reset(new uint8_t[src_size]); | 2570 src_pixels.reset(new uint8_t[pixel_size]); |
2545 for (size_t i = 0; i < src_size; ++i) { | 2571 for (size_t i = 0; i < pixel_size; ++i) { |
2546 src_pixels[i] = static_cast<int8_t>(i); | 2572 src_pixels[i] = static_cast<uint8_t>(i % 255); |
2547 } | 2573 } |
2548 | 2574 |
2549 for (int sub = 0; sub < 2; ++sub) { | 2575 for (int sub = 0; sub < 2; ++sub) { |
2550 for (size_t a = 0; a < arraysize(unpack_alignments); ++a) { | 2576 for (size_t a = 0; a < arraysize(unpack_alignments); ++a) { |
| 2577 const void* commands = GetPut(); |
| 2578 |
2551 GLint alignment = unpack_alignments[a]; | 2579 GLint alignment = unpack_alignments[a]; |
2552 uint32_t size; | 2580 gl_->PixelStorei(GL_UNPACK_ALIGNMENT, alignment); |
2553 uint32_t unpadded_row_size; | 2581 gl_->PixelStorei(GL_UNPACK_ROW_LENGTH, kSrcWidth); |
2554 uint32_t padded_row_size; | 2582 gl_->PixelStorei(GL_UNPACK_SKIP_PIXELS, kSrcSubImageX0); |
2555 ASSERT_TRUE(GLES2Util::ComputeImageDataSizes( | 2583 gl_->PixelStorei(GL_UNPACK_SKIP_ROWS, kSrcSubImageY0); |
2556 kSrcSubImageWidth, kSrcSubImageHeight, 1, kFormat, kType, alignment, | |
2557 &size, &unpadded_row_size, &padded_row_size)); | |
2558 ASSERT_TRUE(size <= MaxTransferBufferSize()); | |
2559 ExpectedMemoryInfo mem = GetExpectedMemory(size); | |
2560 | 2584 |
2561 const void* commands = GetPut(); | 2585 uint32_t client_size; |
2562 gl_->PixelStorei(GL_UNPACK_ALIGNMENT, alignment); | 2586 uint32_t client_unpadded_row_size; |
2563 gl_->PixelStorei(GL_UNPACK_ROW_LENGTH_EXT, kSrcWidth); | 2587 uint32_t client_padded_row_size; |
2564 gl_->PixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, kSrcSubImageX0); | 2588 uint32_t client_skip_size; |
2565 gl_->PixelStorei(GL_UNPACK_SKIP_ROWS_EXT, kSrcSubImageY0); | 2589 { |
| 2590 PixelStoreParams params; |
| 2591 params.alignment = alignment; |
| 2592 params.row_length = kSrcWidth; |
| 2593 params.skip_pixels = kSrcSubImageX0; |
| 2594 params.skip_rows = kSrcSubImageY0; |
| 2595 ASSERT_TRUE(GLES2Util::ComputeImageDataSizesES3( |
| 2596 kSrcSubImageWidth, kSrcSubImageHeight, 1, kFormat, kType, params, |
| 2597 &client_size, &client_unpadded_row_size, &client_padded_row_size, |
| 2598 &client_skip_size, nullptr)); |
| 2599 ASSERT_TRUE(client_size + client_skip_size <= pixel_size); |
| 2600 } |
| 2601 |
| 2602 uint32_t service_size; |
| 2603 uint32_t service_unpadded_row_size; |
| 2604 uint32_t service_padded_row_size; |
| 2605 uint32_t service_skip_size; |
| 2606 { |
| 2607 PixelStoreParams params; |
| 2608 // For pixels we send to service side, we already applied all unpack |
| 2609 // parameters except for UNPACK_ALIGNMENT. |
| 2610 params.alignment = alignment; |
| 2611 ASSERT_TRUE(GLES2Util::ComputeImageDataSizesES3( |
| 2612 kSrcSubImageWidth, kSrcSubImageHeight, 1, kFormat, kType, params, |
| 2613 &service_size, &service_unpadded_row_size, &service_padded_row_size, |
| 2614 &service_skip_size, nullptr)); |
| 2615 ASSERT_TRUE(service_size <= MaxTransferBufferSize()); |
| 2616 ASSERT_TRUE(service_skip_size == 0); |
| 2617 ASSERT_TRUE(client_unpadded_row_size == service_unpadded_row_size); |
| 2618 } |
| 2619 |
| 2620 ExpectedMemoryInfo mem = GetExpectedMemory(service_size); |
2566 if (sub) { | 2621 if (sub) { |
2567 gl_->TexImage2D( | 2622 gl_->TexImage2D( |
2568 GL_TEXTURE_2D, kLevel, kFormat, kTexWidth, kTexHeight, kBorder, | 2623 GL_TEXTURE_2D, kLevel, kFormat, kTexWidth, kTexHeight, kBorder, |
2569 kFormat, kType, NULL); | 2624 kFormat, kType, nullptr); |
2570 gl_->TexSubImage2D( | 2625 gl_->TexSubImage2D( |
2571 GL_TEXTURE_2D, kLevel, kTexSubXOffset, kTexSubYOffset, | 2626 GL_TEXTURE_2D, kLevel, kTexSubXOffset, kTexSubYOffset, |
2572 kSrcSubImageWidth, kSrcSubImageHeight, kFormat, kType, | 2627 kSrcSubImageWidth, kSrcSubImageHeight, kFormat, kType, |
2573 src_pixels.get()); | 2628 src_pixels.get()); |
2574 texSubImageExpected.pixel_store_i[0].Init( | 2629 texSubImageExpected.pixel_store_i[0].Init( |
2575 GL_UNPACK_ALIGNMENT, alignment); | 2630 GL_UNPACK_ALIGNMENT, alignment); |
2576 texSubImageExpected.pixel_store_i[1].Init( | 2631 texSubImageExpected.pixel_store_i[1].Init( |
2577 GL_UNPACK_ROW_LENGTH_EXT, kSrcWidth); | 2632 GL_UNPACK_ROW_LENGTH, kSrcWidth); |
2578 texSubImageExpected.pixel_store_i[2].Init( | |
2579 GL_UNPACK_SKIP_PIXELS_EXT, kSrcSubImageX0); | |
2580 texSubImageExpected.pixel_store_i[3].Init( | |
2581 GL_UNPACK_SKIP_ROWS_EXT, kSrcSubImageY0); | |
2582 texSubImageExpected.tex_image_2d.Init( | 2633 texSubImageExpected.tex_image_2d.Init( |
2583 GL_TEXTURE_2D, kLevel, kFormat, kTexWidth, kTexHeight, | 2634 GL_TEXTURE_2D, kLevel, kFormat, kTexWidth, kTexHeight, |
2584 kFormat, kType, 0, 0); | 2635 kFormat, kType, 0, 0); |
2585 texSubImageExpected.tex_sub_image_2d.Init( | 2636 texSubImageExpected.tex_sub_image_2d.Init( |
2586 GL_TEXTURE_2D, kLevel, kTexSubXOffset, kTexSubYOffset, | 2637 GL_TEXTURE_2D, kLevel, kTexSubXOffset, kTexSubYOffset, |
2587 kSrcSubImageWidth, kSrcSubImageHeight, kFormat, kType, mem.id, | 2638 kSrcSubImageWidth, kSrcSubImageHeight, kFormat, kType, mem.id, |
2588 mem.offset, GL_FALSE); | 2639 mem.offset, GL_FALSE); |
2589 EXPECT_EQ(0, memcmp( | 2640 EXPECT_EQ(0, memcmp(&texSubImageExpected, commands, |
2590 &texSubImageExpected, commands, sizeof(texSubImageExpected))); | 2641 sizeof(texSubImageExpected))); |
2591 } else { | 2642 } else { |
2592 gl_->TexImage2D( | 2643 gl_->TexImage2D( |
2593 GL_TEXTURE_2D, kLevel, kFormat, | 2644 GL_TEXTURE_2D, kLevel, kFormat, |
2594 kSrcSubImageWidth, kSrcSubImageHeight, kBorder, kFormat, kType, | 2645 kSrcSubImageWidth, kSrcSubImageHeight, kBorder, kFormat, kType, |
2595 src_pixels.get()); | 2646 src_pixels.get()); |
2596 texImageExpected.pixel_store_i[0].Init(GL_UNPACK_ALIGNMENT, alignment); | 2647 texImageExpected.pixel_store_i[0].Init(GL_UNPACK_ALIGNMENT, alignment); |
2597 texImageExpected.pixel_store_i[1].Init( | 2648 texImageExpected.pixel_store_i[1].Init( |
2598 GL_UNPACK_ROW_LENGTH_EXT, kSrcWidth); | 2649 GL_UNPACK_ROW_LENGTH, kSrcWidth); |
2599 texImageExpected.pixel_store_i[2].Init( | |
2600 GL_UNPACK_SKIP_PIXELS_EXT, kSrcSubImageX0); | |
2601 texImageExpected.pixel_store_i[3].Init( | |
2602 GL_UNPACK_SKIP_ROWS_EXT, kSrcSubImageY0); | |
2603 texImageExpected.tex_image_2d.Init( | 2650 texImageExpected.tex_image_2d.Init( |
2604 GL_TEXTURE_2D, kLevel, kFormat, kSrcSubImageWidth, | 2651 GL_TEXTURE_2D, kLevel, kFormat, kSrcSubImageWidth, |
2605 kSrcSubImageHeight, kFormat, kType, mem.id, mem.offset); | 2652 kSrcSubImageHeight, kFormat, kType, mem.id, mem.offset); |
2606 EXPECT_EQ(0, memcmp( | 2653 EXPECT_EQ(0, memcmp(&texImageExpected, commands, |
2607 &texImageExpected, commands, sizeof(texImageExpected))); | 2654 sizeof(texImageExpected))); |
2608 } | 2655 } |
2609 uint32_t src_padded_row_size; | |
2610 ASSERT_TRUE(GLES2Util::ComputeImagePaddedRowSize( | |
2611 kSrcWidth, kFormat, kType, alignment, &src_padded_row_size)); | |
2612 uint32_t bytes_per_group = | |
2613 GLES2Util::ComputeImageGroupSize(kFormat, kType); | |
2614 for (int y = 0; y < kSrcSubImageHeight; ++y) { | 2656 for (int y = 0; y < kSrcSubImageHeight; ++y) { |
2615 const uint8_t* src_row = src_pixels.get() + | 2657 const uint8_t* src_row = |
2616 (kSrcSubImageY0 + y) * src_padded_row_size + | 2658 src_pixels.get() + client_skip_size + y * client_padded_row_size; |
2617 bytes_per_group * kSrcSubImageX0; | 2659 const uint8_t* dst_row = mem.ptr + y * service_padded_row_size; |
2618 const uint8_t* dst_row = mem.ptr + y * padded_row_size; | 2660 EXPECT_EQ(0, memcmp(src_row, dst_row, service_unpadded_row_size)); |
2619 EXPECT_EQ(0, memcmp(src_row, dst_row, unpadded_row_size)); | |
2620 } | 2661 } |
2621 ClearCommands(); | 2662 ClearCommands(); |
2622 } | 2663 } |
| 2664 } |
| 2665 } |
| 2666 |
| 2667 TEST_F(GLES3ImplementationTest, SubImage3DUnpack) { |
| 2668 static const GLint unpack_alignments[] = { 1, 2, 4, 8 }; |
| 2669 |
| 2670 static const GLenum kFormat = GL_RGB; |
| 2671 static const GLenum kType = GL_UNSIGNED_BYTE; |
| 2672 static const GLint kLevel = 0; |
| 2673 static const GLint kBorder = 0; |
| 2674 // We're testing using the unpack params to pull a subimage out of a larger |
| 2675 // source of pixels. Here we specify the subimage by its border rows / |
| 2676 // columns. |
| 2677 static const GLint kSrcWidth = 23; |
| 2678 static const GLint kSrcHeight = 7; |
| 2679 static const GLint kSrcSubImageX0 = 11; |
| 2680 static const GLint kSrcSubImageX1 = 16; |
| 2681 static const GLint kSrcSubImageY0 = 20; |
| 2682 static const GLint kSrcSubImageY1 = 23; |
| 2683 static const GLint kSrcSubImageZ0 = 2; |
| 2684 static const GLint kSrcSubImageZ1 = 5; |
| 2685 static const GLint kSrcSubImageWidth = kSrcSubImageX1 - kSrcSubImageX0; |
| 2686 static const GLint kSrcSubImageHeight = kSrcSubImageY1 - kSrcSubImageY0; |
| 2687 static const GLint kSrcSubImageDepth = kSrcSubImageZ1 - kSrcSubImageZ0; |
| 2688 |
| 2689 // these are only used in the texsubimage tests |
| 2690 static const GLint kTexWidth = 255; |
| 2691 static const GLint kTexHeight = 127; |
| 2692 static const GLint kTexDepth = 11; |
| 2693 static const GLint kTexSubXOffset = 119; |
| 2694 static const GLint kTexSubYOffset = 63; |
| 2695 static const GLint kTexSubZOffset = 1; |
| 2696 |
| 2697 struct { |
| 2698 cmds::PixelStorei pixel_store_i[3]; |
| 2699 cmds::TexImage3D tex_image_3d; |
| 2700 } texImageExpected; |
| 2701 |
| 2702 struct { |
| 2703 cmds::PixelStorei pixel_store_i[3]; |
| 2704 cmds::TexImage3D tex_image_3d; |
| 2705 cmds::TexSubImage3D tex_sub_image_3d; |
| 2706 } texSubImageExpected; |
| 2707 |
| 2708 uint32_t pixel_size; |
| 2709 PixelStoreParams pixel_params; |
| 2710 // Makes sure the pixels size is large enough for all tests. |
| 2711 pixel_params.alignment = 8; |
| 2712 ASSERT_TRUE(GLES2Util::ComputeImageDataSizesES3( |
| 2713 kSrcWidth, kSrcSubImageY1, kSrcSubImageZ1, kFormat, kType, |
| 2714 pixel_params, &pixel_size, nullptr, nullptr, nullptr, nullptr)); |
| 2715 scoped_ptr<uint8_t[]> src_pixels; |
| 2716 src_pixels.reset(new uint8_t[pixel_size]); |
| 2717 for (size_t i = 0; i < pixel_size; ++i) { |
| 2718 src_pixels[i] = static_cast<uint8_t>(i % 255); |
| 2719 } |
| 2720 |
| 2721 for (int sub = 0; sub < 2; ++sub) { |
| 2722 for (size_t a = 0; a < arraysize(unpack_alignments); ++a) { |
| 2723 const void* commands = GetPut(); |
| 2724 |
| 2725 GLint alignment = unpack_alignments[a]; |
| 2726 gl_->PixelStorei(GL_UNPACK_ALIGNMENT, alignment); |
| 2727 gl_->PixelStorei(GL_UNPACK_ROW_LENGTH, kSrcWidth); |
| 2728 gl_->PixelStorei(GL_UNPACK_IMAGE_HEIGHT, kSrcHeight); |
| 2729 gl_->PixelStorei(GL_UNPACK_SKIP_PIXELS, kSrcSubImageX0); |
| 2730 gl_->PixelStorei(GL_UNPACK_SKIP_ROWS, kSrcSubImageY0); |
| 2731 gl_->PixelStorei(GL_UNPACK_SKIP_IMAGES, kSrcSubImageZ0); |
| 2732 |
| 2733 uint32_t client_size; |
| 2734 uint32_t client_unpadded_row_size; |
| 2735 uint32_t client_padded_row_size; |
| 2736 uint32_t client_skip_size; |
| 2737 { |
| 2738 PixelStoreParams params; |
| 2739 params.alignment = alignment; |
| 2740 params.row_length = kSrcWidth; |
| 2741 params.image_height = kSrcHeight; |
| 2742 params.skip_pixels = kSrcSubImageX0; |
| 2743 params.skip_rows = kSrcSubImageY0; |
| 2744 params.skip_images = kSrcSubImageZ0; |
| 2745 ASSERT_TRUE(GLES2Util::ComputeImageDataSizesES3( |
| 2746 kSrcSubImageWidth, kSrcSubImageHeight, kSrcSubImageDepth, |
| 2747 kFormat, kType, params, |
| 2748 &client_size, &client_unpadded_row_size, &client_padded_row_size, |
| 2749 &client_skip_size, nullptr)); |
| 2750 ASSERT_TRUE(client_size + client_skip_size <= pixel_size); |
| 2751 } |
| 2752 |
| 2753 uint32_t service_size; |
| 2754 uint32_t service_unpadded_row_size; |
| 2755 uint32_t service_padded_row_size; |
| 2756 uint32_t service_skip_size; |
| 2757 { |
| 2758 PixelStoreParams params; |
| 2759 // For pixels we send to service side, we already applied all unpack |
| 2760 // parameters except for UNPACK_ALIGNMENT. |
| 2761 params.alignment = alignment; |
| 2762 ASSERT_TRUE(GLES2Util::ComputeImageDataSizesES3( |
| 2763 kSrcSubImageWidth, kSrcSubImageHeight, kSrcSubImageDepth, |
| 2764 kFormat, kType, params, |
| 2765 &service_size, &service_unpadded_row_size, &service_padded_row_size, |
| 2766 &service_skip_size, nullptr)); |
| 2767 ASSERT_TRUE(service_size <= MaxTransferBufferSize()); |
| 2768 ASSERT_TRUE(service_skip_size == 0); |
| 2769 ASSERT_TRUE(client_unpadded_row_size == service_unpadded_row_size); |
| 2770 } |
| 2771 |
| 2772 ExpectedMemoryInfo mem = GetExpectedMemory(service_size); |
| 2773 if (sub) { |
| 2774 gl_->TexImage3D( |
| 2775 GL_TEXTURE_3D, kLevel, kFormat, kTexWidth, kTexHeight, kTexDepth, |
| 2776 kBorder, kFormat, kType, nullptr); |
| 2777 gl_->TexSubImage3D( |
| 2778 GL_TEXTURE_3D, kLevel, |
| 2779 kTexSubXOffset, kTexSubYOffset, kTexSubZOffset, |
| 2780 kSrcSubImageWidth, kSrcSubImageHeight, kSrcSubImageDepth, |
| 2781 kFormat, kType, src_pixels.get()); |
| 2782 texSubImageExpected.pixel_store_i[0].Init( |
| 2783 GL_UNPACK_ALIGNMENT, alignment); |
| 2784 texSubImageExpected.pixel_store_i[1].Init( |
| 2785 GL_UNPACK_ROW_LENGTH, kSrcWidth); |
| 2786 texSubImageExpected.pixel_store_i[2].Init( |
| 2787 GL_UNPACK_IMAGE_HEIGHT, kSrcHeight); |
| 2788 texSubImageExpected.tex_image_3d.Init( |
| 2789 GL_TEXTURE_3D, kLevel, kFormat, kTexWidth, kTexHeight, kTexDepth, |
| 2790 kFormat, kType, 0, 0); |
| 2791 texSubImageExpected.tex_sub_image_3d.Init( |
| 2792 GL_TEXTURE_3D, kLevel, |
| 2793 kTexSubXOffset, kTexSubYOffset, kTexSubZOffset, |
| 2794 kSrcSubImageWidth, kSrcSubImageHeight, kSrcSubImageDepth, |
| 2795 kFormat, kType, mem.id, mem.offset, GL_FALSE); |
| 2796 EXPECT_EQ(0, memcmp(&texSubImageExpected, commands, |
| 2797 sizeof(texSubImageExpected))); |
| 2798 } else { |
| 2799 gl_->TexImage3D( |
| 2800 GL_TEXTURE_3D, kLevel, kFormat, |
| 2801 kSrcSubImageWidth, kSrcSubImageHeight, kSrcSubImageDepth, |
| 2802 kBorder, kFormat, kType, src_pixels.get()); |
| 2803 texImageExpected.pixel_store_i[0].Init(GL_UNPACK_ALIGNMENT, alignment); |
| 2804 texImageExpected.pixel_store_i[1].Init( |
| 2805 GL_UNPACK_ROW_LENGTH, kSrcWidth); |
| 2806 texImageExpected.pixel_store_i[2].Init( |
| 2807 GL_UNPACK_IMAGE_HEIGHT, kSrcHeight); |
| 2808 texImageExpected.tex_image_3d.Init( |
| 2809 GL_TEXTURE_3D, kLevel, kFormat, |
| 2810 kSrcSubImageWidth, kSrcSubImageHeight, kSrcSubImageDepth, |
| 2811 kFormat, kType, mem.id, mem.offset); |
| 2812 EXPECT_EQ(0, memcmp(&texImageExpected, commands, |
| 2813 sizeof(texImageExpected))); |
| 2814 } |
| 2815 for (int z = 0; z < kSrcSubImageDepth; ++z) { |
| 2816 for (int y = 0; y < kSrcSubImageHeight; ++y) { |
| 2817 const uint8_t* src_row = src_pixels.get() + client_skip_size + |
| 2818 (kSrcHeight * z + y) * client_padded_row_size; |
| 2819 const uint8_t* dst_row = mem.ptr + |
| 2820 (kSrcSubImageHeight * z + y) * service_padded_row_size; |
| 2821 EXPECT_EQ(0, memcmp(src_row, dst_row, service_unpadded_row_size)); |
| 2822 } |
| 2823 } |
| 2824 ClearCommands(); |
| 2825 } |
2623 } | 2826 } |
2624 } | 2827 } |
2625 | 2828 |
2626 // Test texture related calls with invalid arguments. | 2829 // Test texture related calls with invalid arguments. |
2627 TEST_F(GLES2ImplementationTest, TextureInvalidArguments) { | 2830 TEST_F(GLES2ImplementationTest, TextureInvalidArguments) { |
2628 struct Cmds { | 2831 struct Cmds { |
2629 cmds::TexImage2D tex_image_2d; | 2832 cmds::TexImage2D tex_image_2d; |
2630 cmd::SetToken set_token; | 2833 cmd::SetToken set_token; |
2631 }; | 2834 }; |
2632 const GLenum kTarget = GL_TEXTURE_2D; | 2835 const GLenum kTarget = GL_TEXTURE_2D; |
(...skipping 1668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4301 ContextInitOptions init_options; | 4504 ContextInitOptions init_options; |
4302 init_options.transfer_buffer_initialize_fail = true; | 4505 init_options.transfer_buffer_initialize_fail = true; |
4303 EXPECT_FALSE(Initialize(init_options)); | 4506 EXPECT_FALSE(Initialize(init_options)); |
4304 } | 4507 } |
4305 | 4508 |
4306 #include "base/macros.h" | 4509 #include "base/macros.h" |
4307 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" | 4510 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" |
4308 | 4511 |
4309 } // namespace gles2 | 4512 } // namespace gles2 |
4310 } // namespace gpu | 4513 } // namespace gpu |
OLD | NEW |