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

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

Issue 1750123002: Upgrade Tex{Sub}Image{2|3}D to handle ES3 unpack parameters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Attemp to fix random crashes on windows Created 4 years, 9 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 <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
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
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
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
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 1818 matching lines...) Expand 10 before | Expand all | Expand 10 after
2630 const uint8_t* src_row = 2652 const uint8_t* src_row =
2631 src_pixels.get() + client_skip_size + y * client_padded_row_size; 2653 src_pixels.get() + client_skip_size + y * client_padded_row_size;
2632 const uint8_t* dst_row = mem.ptr + y * service_padded_row_size; 2654 const uint8_t* dst_row = mem.ptr + y * service_padded_row_size;
2633 EXPECT_EQ(0, memcmp(src_row, dst_row, service_unpadded_row_size)); 2655 EXPECT_EQ(0, memcmp(src_row, dst_row, service_unpadded_row_size));
2634 } 2656 }
2635 ClearCommands(); 2657 ClearCommands();
2636 } 2658 }
2637 } 2659 }
2638 } 2660 }
2639 2661
2662 TEST_F(GLES3ImplementationTest, SubImage3DUnpack) {
2663 static const GLint unpack_alignments[] = { 1, 2, 4, 8 };
2664
2665 static const GLenum kFormat = GL_RGB;
2666 static const GLenum kType = GL_UNSIGNED_BYTE;
2667 static const GLint kLevel = 0;
2668 static const GLint kBorder = 0;
2669 // We're testing using the unpack params to pull a subimage out of a larger
2670 // source of pixels. Here we specify the subimage by its border rows /
2671 // columns.
2672 static const GLint kSrcWidth = 23;
2673 static const GLint kSrcHeight = 7;
2674 static const GLint kSrcSubImageX0 = 11;
2675 static const GLint kSrcSubImageX1 = 16;
2676 static const GLint kSrcSubImageY0 = 20;
2677 static const GLint kSrcSubImageY1 = 23;
2678 static const GLint kSrcSubImageZ0 = 2;
2679 static const GLint kSrcSubImageZ1 = 5;
2680 static const GLint kSrcSubImageWidth = kSrcSubImageX1 - kSrcSubImageX0;
2681 static const GLint kSrcSubImageHeight = kSrcSubImageY1 - kSrcSubImageY0;
2682 static const GLint kSrcSubImageDepth = kSrcSubImageZ1 - kSrcSubImageZ0;
2683
2684 // these are only used in the texsubimage tests
2685 static const GLint kTexWidth = 255;
2686 static const GLint kTexHeight = 127;
2687 static const GLint kTexDepth = 11;
2688 static const GLint kTexSubXOffset = 119;
2689 static const GLint kTexSubYOffset = 63;
2690 static const GLint kTexSubZOffset = 1;
2691
2692 struct {
2693 cmds::PixelStorei pixel_store_i[3];
2694 cmds::TexImage3D tex_image_3d;
2695 } texImageExpected;
2696
2697 struct {
2698 cmds::PixelStorei pixel_store_i[3];
2699 cmds::TexImage3D tex_image_3d;
2700 cmds::TexSubImage3D tex_sub_image_3d;
2701 } texSubImageExpected;
2702
2703 uint32_t pixel_size;
2704 PixelStoreParams pixel_params;
2705 // Makes sure the pixels size is large enough for all tests.
2706 pixel_params.alignment = 8;
2707 ASSERT_TRUE(GLES2Util::ComputeImageDataSizesES3(
2708 kSrcWidth, kSrcSubImageY1, kSrcSubImageZ1, kFormat, kType,
2709 pixel_params, &pixel_size, nullptr, nullptr, nullptr, nullptr));
2710 scoped_ptr<uint8_t[]> src_pixels;
2711 src_pixels.reset(new uint8_t[pixel_size]);
2712 for (size_t i = 0; i < pixel_size; ++i) {
2713 src_pixels[i] = static_cast<uint8_t>(i % 255);
2714 }
2715
2716 for (int sub = 0; sub < 2; ++sub) {
2717 for (size_t a = 0; a < arraysize(unpack_alignments); ++a) {
2718 const void* commands = GetPut();
2719
2720 GLint alignment = unpack_alignments[a];
2721 gl_->PixelStorei(GL_UNPACK_ALIGNMENT, alignment);
2722 gl_->PixelStorei(GL_UNPACK_ROW_LENGTH, kSrcWidth);
2723 gl_->PixelStorei(GL_UNPACK_IMAGE_HEIGHT, kSrcHeight);
2724 gl_->PixelStorei(GL_UNPACK_SKIP_PIXELS, kSrcSubImageX0);
2725 gl_->PixelStorei(GL_UNPACK_SKIP_ROWS, kSrcSubImageY0);
2726 gl_->PixelStorei(GL_UNPACK_SKIP_IMAGES, kSrcSubImageZ0);
2727
2728 uint32_t client_size;
2729 uint32_t client_unpadded_row_size;
2730 uint32_t client_padded_row_size;
2731 uint32_t client_skip_size;
2732 {
2733 PixelStoreParams params;
2734 params.alignment = alignment;
2735 params.row_length = kSrcWidth;
2736 params.image_height = kSrcHeight;
2737 params.skip_pixels = kSrcSubImageX0;
2738 params.skip_rows = kSrcSubImageY0;
2739 params.skip_images = kSrcSubImageZ0;
2740 ASSERT_TRUE(GLES2Util::ComputeImageDataSizesES3(
2741 kSrcSubImageWidth, kSrcSubImageHeight, kSrcSubImageDepth,
2742 kFormat, kType, params,
2743 &client_size, &client_unpadded_row_size, &client_padded_row_size,
2744 &client_skip_size, nullptr));
2745 ASSERT_TRUE(client_size + client_skip_size <= pixel_size);
2746 }
2747
2748 uint32_t service_size;
2749 uint32_t service_unpadded_row_size;
2750 uint32_t service_padded_row_size;
2751 uint32_t service_skip_size;
2752 {
2753 PixelStoreParams params;
2754 // For pixels we send to service side, we already applied all unpack
2755 // parameters except for UNPACK_ALIGNMENT.
2756 params.alignment = alignment;
2757 ASSERT_TRUE(GLES2Util::ComputeImageDataSizesES3(
2758 kSrcSubImageWidth, kSrcSubImageHeight, kSrcSubImageDepth,
2759 kFormat, kType, params,
2760 &service_size, &service_unpadded_row_size, &service_padded_row_size,
2761 &service_skip_size, nullptr));
2762 ASSERT_TRUE(service_size <= MaxTransferBufferSize());
2763 ASSERT_TRUE(service_skip_size == 0);
2764 ASSERT_TRUE(client_unpadded_row_size == service_unpadded_row_size);
2765 }
2766
2767 ExpectedMemoryInfo mem = GetExpectedMemory(service_size);
2768 if (sub) {
2769 gl_->TexImage3D(
2770 GL_TEXTURE_3D, kLevel, kFormat, kTexWidth, kTexHeight, kTexDepth,
2771 kBorder, kFormat, kType, nullptr);
2772 gl_->TexSubImage3D(
2773 GL_TEXTURE_3D, kLevel,
2774 kTexSubXOffset, kTexSubYOffset, kTexSubZOffset,
2775 kSrcSubImageWidth, kSrcSubImageHeight, kSrcSubImageDepth,
2776 kFormat, kType, src_pixels.get());
2777 texSubImageExpected.pixel_store_i[0].Init(
2778 GL_UNPACK_ALIGNMENT, alignment);
2779 texSubImageExpected.pixel_store_i[1].Init(
2780 GL_UNPACK_ROW_LENGTH, kSrcWidth);
2781 texSubImageExpected.pixel_store_i[2].Init(
2782 GL_UNPACK_IMAGE_HEIGHT, kSrcHeight);
2783 texSubImageExpected.tex_image_3d.Init(
2784 GL_TEXTURE_3D, kLevel, kFormat, kTexWidth, kTexHeight, kTexDepth,
2785 kFormat, kType, 0, 0);
2786 texSubImageExpected.tex_sub_image_3d.Init(
2787 GL_TEXTURE_3D, kLevel,
2788 kTexSubXOffset, kTexSubYOffset, kTexSubZOffset,
2789 kSrcSubImageWidth, kSrcSubImageHeight, kSrcSubImageDepth,
2790 kFormat, kType, mem.id, mem.offset, GL_FALSE);
2791 EXPECT_EQ(0, memcmp(&texSubImageExpected, commands,
2792 sizeof(texSubImageExpected)));
2793 } else {
2794 gl_->TexImage3D(
2795 GL_TEXTURE_3D, kLevel, kFormat,
2796 kSrcSubImageWidth, kSrcSubImageHeight, kSrcSubImageDepth,
2797 kBorder, kFormat, kType, src_pixels.get());
2798 texImageExpected.pixel_store_i[0].Init(GL_UNPACK_ALIGNMENT, alignment);
2799 texImageExpected.pixel_store_i[1].Init(
2800 GL_UNPACK_ROW_LENGTH, kSrcWidth);
2801 texImageExpected.pixel_store_i[2].Init(
2802 GL_UNPACK_IMAGE_HEIGHT, kSrcHeight);
2803 texImageExpected.tex_image_3d.Init(
2804 GL_TEXTURE_3D, kLevel, kFormat,
2805 kSrcSubImageWidth, kSrcSubImageHeight, kSrcSubImageDepth,
2806 kFormat, kType, mem.id, mem.offset);
2807 EXPECT_EQ(0, memcmp(&texImageExpected, commands,
2808 sizeof(texImageExpected)));
2809 }
2810 for (int z = 0; z < kSrcSubImageDepth; ++z) {
2811 for (int y = 0; y < kSrcSubImageHeight; ++y) {
2812 const uint8_t* src_row = src_pixels.get() + client_skip_size +
2813 (kSrcHeight * z + y) * client_padded_row_size;
2814 const uint8_t* dst_row = mem.ptr +
2815 (kSrcSubImageHeight * z + y) * service_padded_row_size;
2816 EXPECT_EQ(0, memcmp(src_row, dst_row, service_unpadded_row_size));
2817 }
2818 }
2819 ClearCommands();
2820 }
2821 }
2822 }
2823
2640 // Test texture related calls with invalid arguments. 2824 // Test texture related calls with invalid arguments.
2641 TEST_F(GLES2ImplementationTest, TextureInvalidArguments) { 2825 TEST_F(GLES2ImplementationTest, TextureInvalidArguments) {
2642 struct Cmds { 2826 struct Cmds {
2643 cmds::TexImage2D tex_image_2d; 2827 cmds::TexImage2D tex_image_2d;
2644 cmd::SetToken set_token; 2828 cmd::SetToken set_token;
2645 }; 2829 };
2646 const GLenum kTarget = GL_TEXTURE_2D; 2830 const GLenum kTarget = GL_TEXTURE_2D;
2647 const GLint kLevel = 0; 2831 const GLint kLevel = 0;
2648 const GLenum kFormat = GL_RGB; 2832 const GLenum kFormat = GL_RGB;
2649 const GLsizei kWidth = 3; 2833 const GLsizei kWidth = 3;
(...skipping 1665 matching lines...) Expand 10 before | Expand all | Expand 10 after
4315 ContextInitOptions init_options; 4499 ContextInitOptions init_options;
4316 init_options.transfer_buffer_initialize_fail = true; 4500 init_options.transfer_buffer_initialize_fail = true;
4317 EXPECT_FALSE(Initialize(init_options)); 4501 EXPECT_FALSE(Initialize(init_options));
4318 } 4502 }
4319 4503
4320 #include "base/macros.h" 4504 #include "base/macros.h"
4321 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" 4505 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h"
4322 4506
4323 } // namespace gles2 4507 } // namespace gles2
4324 } // namespace gpu 4508 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation.cc ('k') | gpu/command_buffer/common/gles2_cmd_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698