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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/client/gles2_implementation_unittest.cc
diff --git a/gpu/command_buffer/client/gles2_implementation_unittest.cc b/gpu/command_buffer/client/gles2_implementation_unittest.cc
index edc7c6a08b920d1aabd338fef8b678c58bcdd6b9..f775a6fb0fe54a7ce086ec063a4b40329f47a4f1 100644
--- a/gpu/command_buffer/client/gles2_implementation_unittest.cc
+++ b/gpu/command_buffer/client/gles2_implementation_unittest.cc
@@ -582,6 +582,87 @@ TEST_F(GLES2ImplementationTest, GetBucketContents) {
EXPECT_EQ(0, memcmp(expected_data, &data[0], data.size()));
}
+// We need to implement a fake server-side GetShaderPrecisionFormat
+// so that it can look like the request succeded. If the call fails, the
+// client-side GetShaderPrecisionFormat will not cache the results.
+class FakeGetShaderPrecisionFormatServer {
+public:
+ FakeGetShaderPrecisionFormatServer(
+ cmds::GetShaderPrecisionFormat::Result* destination,
+ const cmds::GetShaderPrecisionFormat::Result &source)
+ : destination_(destination), source_(source) {
+ }
+
+ void operator()() {
+ *destination_ = source_;
+ }
+
+private:
+ cmds::GetShaderPrecisionFormat::Result* destination_;
+ cmds::GetShaderPrecisionFormat::Result source_;
+};
+
+TEST_F(GLES2ImplementationTest, GetShaderPrecisionFormat) {
+ struct Cmds {
+ cmds::GetShaderPrecisionFormat cmd;
+ };
+ typedef cmds::GetShaderPrecisionFormat::Result Result;
+
+ // The first call for mediump should trigger a command buffer request.
+ GLint range1[2] = {0, 0};
+ GLint precision1 = 0;
+ Cmds expected1;
+ ExpectedMemoryInfo result1 = GetExpectedResultMemory(4);
+ expected1.cmd.Init(GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT,
+ result1.id, result1.offset);
+ Result result1_source = {true, 14, 14, 10};
+ FakeGetShaderPrecisionFormatServer run_server1(
+ reinterpret_cast<Result*>(result1.ptr), result1_source);
+ EXPECT_CALL(*command_buffer(), OnFlush())
+ .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.
+ .RetiresOnSaturation();
+ gl_->GetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT,
+ range1, &precision1);
+ EXPECT_EQ(0, memcmp(&expected1, commands_, sizeof(expected1)));
+ EXPECT_EQ(range1[0], 14);
+ EXPECT_EQ(range1[1], 14);
+ EXPECT_EQ(precision1, 10);
+
+ // The second call for mediump should use the cached value and avoid
+ // triggering a command buffer request, so we do not expect a call to
+ // OnFlush() here. We do expect the results to be correct though.
+ GLint range2[2] = {0, 0};
+ GLint precision2 = 0;
+ gl_->GetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT,
+ range2, &precision2);
+ EXPECT_EQ(range2[0], 14);
+ EXPECT_EQ(range2[1], 14);
+ EXPECT_EQ(precision2, 10);
+
+ // If we then make a request for highp, we should get another command
+ // buffer request since it hasn't been cached yet.
+ GLint range3[2] = {0, 0};
+ GLint precision3 = 0;
+ Cmds expected3;
+ ExpectedMemoryInfo result3 = GetExpectedResultMemory(4);
+ expected3.cmd.Init(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT,
+ result3.id, result3.offset);
+ Result result3_source = {true, 62, 62, 16};
+ FakeGetShaderPrecisionFormatServer run_server3(
+ reinterpret_cast<Result*>(result3.ptr), result3_source);
+ EXPECT_CALL(*command_buffer(), OnFlush())
+ .WillOnce(Invoke(run_server3))
+ .RetiresOnSaturation();
+ gl_->GetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT,
+ range3, &precision3);
+ EXPECT_EQ(0, memcmp(&expected3,
+ ((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.
+ sizeof(expected3)));
+ EXPECT_EQ(range3[0], 62);
+ EXPECT_EQ(range3[1], 62);
+ EXPECT_EQ(precision3, 16);
+}
+
TEST_F(GLES2ImplementationTest, ShaderSource) {
const uint32 kBucketId = GLES2Implementation::kResultBucketId;
const GLuint kShaderId = 456;

Powered by Google App Engine
This is Rietveld 408576698