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

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

Issue 13004003: gpu: Cache results of GetShaderPrecisionFormat client-side (Closed) Base URL: http://git.chromium.org/chromium/src.git@shp3
Patch Set: re-upload Created 7 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/gl2ext.h> 9 #include <GLES2/gl2ext.h>
10 #include <GLES2/gl2extchromium.h> 10 #include <GLES2/gl2extchromium.h>
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 kTestSize - MaxTransferBufferSize())) 575 kTestSize - MaxTransferBufferSize()))
576 .RetiresOnSaturation(); 576 .RetiresOnSaturation();
577 577
578 std::vector<int8> data; 578 std::vector<int8> data;
579 GetBucketContents(kBucketId, &data); 579 GetBucketContents(kBucketId, &data);
580 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); 580 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
581 ASSERT_EQ(kTestSize, data.size()); 581 ASSERT_EQ(kTestSize, data.size());
582 EXPECT_EQ(0, memcmp(expected_data, &data[0], data.size())); 582 EXPECT_EQ(0, memcmp(expected_data, &data[0], data.size()));
583 } 583 }
584 584
585 // We need to implement a fake server-side GetShaderPrecisionFormat
586 // so that it can look like the request succeded. If the call fails, the
587 // client-side GetShaderPrecisionFormat will not cache the results.
588 class FakeGetShaderPrecisionFormatServer {
589 public:
590 FakeGetShaderPrecisionFormatServer(
591 cmds::GetShaderPrecisionFormat::Result* destination,
592 const cmds::GetShaderPrecisionFormat::Result &source)
593 : destination_(destination), source_(source) {
594 }
595
596 void operator()() {
597 *destination_ = source_;
598 }
599
600 private:
601 cmds::GetShaderPrecisionFormat::Result* destination_;
602 cmds::GetShaderPrecisionFormat::Result source_;
603 };
604
605 TEST_F(GLES2ImplementationTest, GetShaderPrecisionFormat) {
606 struct Cmds {
607 cmds::GetShaderPrecisionFormat cmd;
608 };
609 typedef cmds::GetShaderPrecisionFormat::Result Result;
610
611 // The first call for mediump should trigger a command buffer request.
612 GLint range1[2] = {0, 0};
613 GLint precision1 = 0;
614 Cmds expected1;
615 ExpectedMemoryInfo result1 = GetExpectedResultMemory(4);
616 expected1.cmd.Init(GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT,
617 result1.id, result1.offset);
618 Result result1_source = {true, 14, 14, 10};
619 FakeGetShaderPrecisionFormatServer run_server1(
620 reinterpret_cast<Result*>(result1.ptr), result1_source);
621 EXPECT_CALL(*command_buffer(), OnFlush())
622 .WillOnce(Invoke(run_server1))
greggman 2013/03/22 22:06:14 Could you have just used SetMemory?
brianderson 2013/03/22 23:11:27 So much easier.
623 .RetiresOnSaturation();
624 gl_->GetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT,
625 range1, &precision1);
626 EXPECT_EQ(0, memcmp(&expected1, commands_, sizeof(expected1)));
627 EXPECT_EQ(range1[0], 14);
628 EXPECT_EQ(range1[1], 14);
629 EXPECT_EQ(precision1, 10);
630
631 // The second call for mediump should use the cached value and avoid
632 // triggering a command buffer request, so we do not expect a call to
633 // OnFlush() here. We do expect the results to be correct though.
634 GLint range2[2] = {0, 0};
635 GLint precision2 = 0;
636 gl_->GetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT,
637 range2, &precision2);
638 EXPECT_EQ(range2[0], 14);
639 EXPECT_EQ(range2[1], 14);
640 EXPECT_EQ(precision2, 10);
641
642 // If we then make a request for highp, we should get another command
643 // buffer request since it hasn't been cached yet.
644 GLint range3[2] = {0, 0};
645 GLint precision3 = 0;
646 Cmds expected3;
647 ExpectedMemoryInfo result3 = GetExpectedResultMemory(4);
648 expected3.cmd.Init(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT,
649 result3.id, result3.offset);
650 Result result3_source = {true, 62, 62, 16};
651 FakeGetShaderPrecisionFormatServer run_server3(
652 reinterpret_cast<Result*>(result3.ptr), result3_source);
653 EXPECT_CALL(*command_buffer(), OnFlush())
654 .WillOnce(Invoke(run_server3))
655 .RetiresOnSaturation();
656 gl_->GetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT,
657 range3, &precision3);
658 EXPECT_EQ(0, memcmp(&expected3,
659 ((char*)commands_) + sizeof(expected1),
brianderson 2013/03/22 18:18:17 Is there a better way of getting a pointer to the
greggman 2013/03/22 22:06:14 yes, before calling gl_>GetShaderPrecisionFormat c
brianderson 2013/03/22 23:11:27 Done.
660 sizeof(expected3)));
661 EXPECT_EQ(range3[0], 62);
662 EXPECT_EQ(range3[1], 62);
663 EXPECT_EQ(precision3, 16);
664 }
665
585 TEST_F(GLES2ImplementationTest, ShaderSource) { 666 TEST_F(GLES2ImplementationTest, ShaderSource) {
586 const uint32 kBucketId = GLES2Implementation::kResultBucketId; 667 const uint32 kBucketId = GLES2Implementation::kResultBucketId;
587 const GLuint kShaderId = 456; 668 const GLuint kShaderId = 456;
588 const char* kString1 = "foobar"; 669 const char* kString1 = "foobar";
589 const char* kString2 = "barfoo"; 670 const char* kString2 = "barfoo";
590 const size_t kString1Size = strlen(kString1); 671 const size_t kString1Size = strlen(kString1);
591 const size_t kString2Size = strlen(kString2); 672 const size_t kString2Size = strlen(kString2);
592 const size_t kString3Size = 1; // Want the NULL; 673 const size_t kString3Size = 1; // Want the NULL;
593 const size_t kSourceSize = kString1Size + kString2Size + kString3Size; 674 const size_t kSourceSize = kString1Size + kString2Size + kString3Size;
594 const size_t kPaddedString1Size = 675 const size_t kPaddedString1Size =
(...skipping 2208 matching lines...) Expand 10 before | Expand all | Expand 10 after
2803 gl_->Enable(GL_BLEND); 2884 gl_->Enable(GL_BLEND);
2804 EXPECT_TRUE(NoCommandsWritten()); 2885 EXPECT_TRUE(NoCommandsWritten());
2805 } 2886 }
2806 2887
2807 2888
2808 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" 2889 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h"
2809 2890
2810 } // namespace gles2 2891 } // namespace gles2
2811 } // namespace gpu 2892 } // namespace gpu
2812 2893
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698