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

Side by Side Diff: gpu/command_buffer/service/framebuffer_manager_unittest.cc

Issue 2142353002: Validate fbo color image format and fragment shader output variable type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revision addressed piman review comments Created 4 years, 5 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 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "gpu/command_buffer/service/error_state_mock.h" 8 #include "gpu/command_buffer/service/error_state_mock.h"
9 #include "gpu/command_buffer/service/feature_info.h" 9 #include "gpu/command_buffer/service/feature_info.h"
10 #include "gpu/command_buffer/service/framebuffer_manager.h" 10 #include "gpu/command_buffer/service/framebuffer_manager.h"
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 EXPECT_TRUE(attachment->cleared()); 997 EXPECT_TRUE(attachment->cleared());
998 EXPECT_FALSE(attachment->IsPartiallyCleared()); 998 EXPECT_FALSE(attachment->IsPartiallyCleared());
999 EXPECT_TRUE(framebuffer_->IsCleared()); 999 EXPECT_TRUE(framebuffer_->IsCleared());
1000 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); 1000 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
1001 EXPECT_FALSE(framebuffer_->HasUnclearedColorAttachments()); 1001 EXPECT_FALSE(framebuffer_->HasUnclearedColorAttachments());
1002 } 1002 }
1003 1003
1004 TEST_F(FramebufferInfoTest, DrawBuffers) { 1004 TEST_F(FramebufferInfoTest, DrawBuffers) {
1005 const GLuint kTextureClientId[] = { 33, 34 }; 1005 const GLuint kTextureClientId[] = { 33, 34 };
1006 const GLuint kTextureServiceId[] = { 333, 334 }; 1006 const GLuint kTextureServiceId[] = { 333, 334 };
1007
1008 for (GLenum i = GL_COLOR_ATTACHMENT0; 1007 for (GLenum i = GL_COLOR_ATTACHMENT0;
1009 i < GL_COLOR_ATTACHMENT0 + kMaxColorAttachments; ++i) { 1008 i < GL_COLOR_ATTACHMENT0 + kMaxColorAttachments; ++i) {
1010 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(i)); 1009 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(i));
1011 } 1010 }
1012 EXPECT_FALSE(framebuffer_->HasUnclearedColorAttachments()); 1011 EXPECT_FALSE(framebuffer_->HasUnclearedColorAttachments());
1013 1012
1014 EXPECT_EQ(static_cast<GLenum>(GL_COLOR_ATTACHMENT0), 1013 EXPECT_EQ(static_cast<GLenum>(GL_COLOR_ATTACHMENT0),
1015 framebuffer_->GetDrawBuffer(GL_DRAW_BUFFER0_ARB)); 1014 framebuffer_->GetDrawBuffer(GL_DRAW_BUFFER0_ARB));
1016 for (GLenum i = GL_DRAW_BUFFER1_ARB; 1015 for (GLenum i = GL_DRAW_BUFFER1_ARB;
1017 i < GL_DRAW_BUFFER0_ARB + kMaxDrawBuffers; ++i) { 1016 i < GL_DRAW_BUFFER0_ARB + kMaxDrawBuffers; ++i) {
1018 EXPECT_EQ(static_cast<GLenum>(GL_NONE), 1017 EXPECT_EQ(static_cast<GLenum>(GL_NONE),
1019 framebuffer_->GetDrawBuffer(i)); 1018 framebuffer_->GetDrawBuffer(i));
1020 } 1019 }
1021 1020
1022 for (size_t ii = 0; ii < arraysize(kTextureClientId); ++ii) { 1021 for (size_t ii = 0; ii < arraysize(kTextureClientId); ++ii) {
1023 texture_manager_->CreateTexture( 1022 texture_manager_->CreateTexture(
1024 kTextureClientId[ii], kTextureServiceId[ii]); 1023 kTextureClientId[ii], kTextureServiceId[ii]);
1025 scoped_refptr<TextureRef> texture( 1024 scoped_refptr<TextureRef> texture(
1026 texture_manager_->GetTexture(kTextureClientId[ii])); 1025 texture_manager_->GetTexture(kTextureClientId[ii]));
1027 ASSERT_TRUE(texture.get() != NULL); 1026 ASSERT_TRUE(texture.get());
1028 1027
1029 framebuffer_->AttachTexture( 1028 framebuffer_->AttachTexture(
1030 GL_COLOR_ATTACHMENT0 + ii, texture.get(), GL_TEXTURE_2D, 0, 0); 1029 GL_COLOR_ATTACHMENT0 + ii, texture.get(), GL_TEXTURE_2D, 0, 0);
1031 EXPECT_FALSE( 1030 EXPECT_FALSE(
1032 framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0 + ii)); 1031 framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0 + ii));
1033 1032
1034 const Framebuffer::Attachment* attachment = 1033 const Framebuffer::Attachment* attachment =
1035 framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0 + ii); 1034 framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0 + ii);
1036 ASSERT_TRUE(attachment != NULL); 1035 ASSERT_TRUE(attachment);
1037 EXPECT_TRUE(attachment->cleared()); 1036 EXPECT_TRUE(attachment->cleared());
1038 } 1037 }
1039 EXPECT_TRUE(framebuffer_->IsCleared()); 1038 EXPECT_TRUE(framebuffer_->IsCleared());
1040 EXPECT_FALSE(framebuffer_->HasUnclearedColorAttachments()); 1039 EXPECT_FALSE(framebuffer_->HasUnclearedColorAttachments());
1041 1040
1042 // Set draw buffer 1 as uncleared. 1041 // Set draw buffer 1 as uncleared.
1043 scoped_refptr<TextureRef> texture1( 1042 scoped_refptr<TextureRef> texture1(
1044 texture_manager_->GetTexture(kTextureClientId[1])); 1043 texture_manager_->GetTexture(kTextureClientId[1]));
1045 texture_manager_->SetTarget(texture1.get(), GL_TEXTURE_2D); 1044 texture_manager_->SetTarget(texture1.get(), GL_TEXTURE_2D);
1046 texture_manager_->SetLevelInfo(texture1.get(), GL_TEXTURE_2D, 0, GL_RGBA, 4, 1045 texture_manager_->SetLevelInfo(texture1.get(), GL_TEXTURE_2D, 0, GL_RGBA, 4,
1047 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 1046 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1048 gfx::Rect()); 1047 gfx::Rect());
1049 1048
1050 const Framebuffer::Attachment* attachment1 = 1049 const Framebuffer::Attachment* attachment1 =
1051 framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT1); 1050 framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT1);
1052 ASSERT_TRUE(attachment1 != NULL); 1051 ASSERT_TRUE(attachment1);
1053 EXPECT_FALSE(attachment1->cleared()); 1052 EXPECT_FALSE(attachment1->cleared());
1054 EXPECT_FALSE(framebuffer_->IsCleared()); 1053 EXPECT_FALSE(framebuffer_->IsCleared());
1055 EXPECT_TRUE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT1)); 1054 EXPECT_TRUE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT1));
1056 EXPECT_TRUE(framebuffer_->HasUnclearedColorAttachments()); 1055 EXPECT_TRUE(framebuffer_->HasUnclearedColorAttachments());
1057 1056
1058 GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 }; 1057 GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
1059 framebuffer_->SetDrawBuffers(2, buffers); 1058 framebuffer_->SetDrawBuffers(2, buffers);
1060 EXPECT_EQ(static_cast<GLenum>(GL_COLOR_ATTACHMENT0), 1059 EXPECT_EQ(static_cast<GLenum>(GL_COLOR_ATTACHMENT0),
1061 framebuffer_->GetDrawBuffer(GL_DRAW_BUFFER0_ARB)); 1060 framebuffer_->GetDrawBuffer(GL_DRAW_BUFFER0_ARB));
1062 EXPECT_EQ(static_cast<GLenum>(GL_COLOR_ATTACHMENT1), 1061 EXPECT_EQ(static_cast<GLenum>(GL_COLOR_ATTACHMENT1),
1063 framebuffer_->GetDrawBuffer(GL_DRAW_BUFFER1_ARB)); 1062 framebuffer_->GetDrawBuffer(GL_DRAW_BUFFER1_ARB));
1064 for (GLenum i = GL_DRAW_BUFFER2_ARB; 1063 for (GLenum i = GL_DRAW_BUFFER2_ARB;
1065 i < GL_DRAW_BUFFER0_ARB + kMaxDrawBuffers; ++i) { 1064 i < GL_DRAW_BUFFER0_ARB + kMaxDrawBuffers; ++i) {
1066 EXPECT_EQ(static_cast<GLenum>(GL_NONE), 1065 EXPECT_EQ(static_cast<GLenum>(GL_NONE),
1067 framebuffer_->GetDrawBuffer(i)); 1066 framebuffer_->GetDrawBuffer(i));
1068 } 1067 }
1069 1068
1070 // Only draw buffer 1 needs clearing, so we need to mask draw buffer 0. 1069 // Only draw buffer 1 needs clearing, so we need to mask draw buffer 0.
1071 EXPECT_CALL(*gl_, DrawBuffersARB(kMaxDrawBuffers, _)) 1070 EXPECT_CALL(*gl_, DrawBuffersARB(kMaxDrawBuffers, _))
1072 .Times(1) 1071 .Times(1)
1073 .RetiresOnSaturation(); 1072 .RetiresOnSaturation();
1074 EXPECT_TRUE(framebuffer_->PrepareDrawBuffersForClear()); 1073 EXPECT_TRUE(
1074 framebuffer_->PrepareDrawBuffersForClearingUninitializedAttachments());
1075 1075
1076 // Now we disable draw buffer 1. 1076 // Now we disable draw buffer 1.
1077 buffers[1] = GL_NONE; 1077 buffers[1] = GL_NONE;
1078 framebuffer_->SetDrawBuffers(2, buffers); 1078 framebuffer_->SetDrawBuffers(2, buffers);
1079 // We will enable the disabled draw buffer for clear(), and disable it 1079 // We will enable the disabled draw buffer for clear(), and disable it
1080 // after the clear. 1080 // after the clear.
1081 EXPECT_CALL(*gl_, DrawBuffersARB(kMaxDrawBuffers, _)) 1081 EXPECT_CALL(*gl_, DrawBuffersARB(kMaxDrawBuffers, _))
1082 .Times(1) 1082 .Times(1)
1083 .RetiresOnSaturation(); 1083 .RetiresOnSaturation();
1084 EXPECT_TRUE(framebuffer_->PrepareDrawBuffersForClear()); 1084 EXPECT_TRUE(
1085 framebuffer_->PrepareDrawBuffersForClearingUninitializedAttachments());
1085 1086
1086 // Now we disable draw buffer 0, enable draw buffer 1. 1087 // Now we disable draw buffer 0, enable draw buffer 1.
1087 buffers[0] = GL_NONE; 1088 buffers[0] = GL_NONE;
1088 buffers[1] = GL_COLOR_ATTACHMENT1; 1089 buffers[1] = GL_COLOR_ATTACHMENT1;
1089 framebuffer_->SetDrawBuffers(2, buffers); 1090 framebuffer_->SetDrawBuffers(2, buffers);
1090 // This is the perfect setting for clear. No need to call DrawBuffers(). 1091 // This is the perfect setting for clear. No need to call DrawBuffers().
1091 EXPECT_FALSE(framebuffer_->PrepareDrawBuffersForClear()); 1092 EXPECT_FALSE(
1093 framebuffer_->PrepareDrawBuffersForClearingUninitializedAttachments());
1094 }
1095
1096 TEST_F(FramebufferInfoTest, DrawBufferMasks) {
1097 const GLuint kTextureClientId[] = { 33, 34, 35, 36, 37 };
1098 const GLuint kTextureServiceId[] = { 333, 334, 335, 336, 337 };
1099 const GLenum kAttachment[] = {
1100 GL_COLOR_ATTACHMENT0,
1101 GL_COLOR_ATTACHMENT1,
1102 GL_COLOR_ATTACHMENT2,
1103 GL_COLOR_ATTACHMENT4,
1104 GL_DEPTH_ATTACHMENT};
1105 const GLenum kInternalFormat[] = {
1106 GL_RGBA8,
1107 GL_RG32UI,
1108 GL_R16I,
1109 GL_R16F,
1110 GL_DEPTH_COMPONENT24};
1111 const GLenum kFormat[] = {
1112 GL_RGBA,
1113 GL_RG_INTEGER,
1114 GL_RED_INTEGER,
1115 GL_RED,
1116 GL_DEPTH_COMPONENT};
1117 const GLenum kType[] = {
1118 GL_UNSIGNED_BYTE,
1119 GL_UNSIGNED_INT,
1120 GL_SHORT,
1121 GL_FLOAT,
1122 GL_UNSIGNED_INT};
1123
1124 for (size_t ii = 0; ii < arraysize(kTextureClientId); ++ii) {
1125 texture_manager_->CreateTexture(
1126 kTextureClientId[ii], kTextureServiceId[ii]);
1127 scoped_refptr<TextureRef> texture(
1128 texture_manager_->GetTexture(kTextureClientId[ii]));
1129 ASSERT_TRUE(texture.get());
1130 texture_manager_->SetTarget(texture.get(), GL_TEXTURE_2D);
1131 texture_manager_->SetLevelInfo(texture.get(), GL_TEXTURE_2D, 0,
1132 kInternalFormat[ii], 4, 4, 1, 0,
1133 kFormat[ii], kType[ii], gfx::Rect());
1134 framebuffer_->AttachTexture(
1135 kAttachment[ii], texture.get(), GL_TEXTURE_2D, 0, 0);
1136 ASSERT_TRUE(framebuffer_->GetAttachment(kAttachment[ii]));
1137 }
1138
1139 manager_.MarkAsComplete(framebuffer_);
1140
1141 { // Default draw buffer settings
1142 EXPECT_EQ(0x3u, framebuffer_->draw_buffer_type_mask());
1143 EXPECT_EQ(0x3u, framebuffer_->draw_buffer_bound_mask());
1144 EXPECT_FALSE(framebuffer_->ContainsActiveIntegerAttachments());
1145 }
1146
1147 { // Exact draw buffer settings.
1148 GLenum buffers[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1,
1149 GL_COLOR_ATTACHMENT2, GL_NONE, GL_COLOR_ATTACHMENT4};
1150 framebuffer_->SetDrawBuffers(5, buffers);
1151 EXPECT_EQ(0x31Bu, framebuffer_->draw_buffer_type_mask());
1152 EXPECT_EQ(0x33Fu, framebuffer_->draw_buffer_bound_mask());
1153 EXPECT_TRUE(framebuffer_->ContainsActiveIntegerAttachments());
1154 }
1155
1156 { // All disabled draw buffer settings.
1157 GLenum buffers[] = {GL_NONE};
1158 framebuffer_->SetDrawBuffers(1, buffers);
1159 EXPECT_EQ(0u, framebuffer_->draw_buffer_type_mask());
1160 EXPECT_EQ(0u, framebuffer_->draw_buffer_bound_mask());
1161 EXPECT_FALSE(framebuffer_->ContainsActiveIntegerAttachments());
1162 }
1163
1164 { // Filter out integer buffers.
1165 GLenum buffers[] = {GL_COLOR_ATTACHMENT0, GL_NONE, GL_NONE, GL_NONE,
1166 GL_COLOR_ATTACHMENT4};
1167 framebuffer_->SetDrawBuffers(5, buffers);
1168 EXPECT_EQ(0x303u, framebuffer_->draw_buffer_type_mask());
1169 EXPECT_EQ(0x303u, framebuffer_->draw_buffer_bound_mask());
1170 EXPECT_FALSE(framebuffer_->ContainsActiveIntegerAttachments());
1171 }
1172
1173 { // All enabled draw buffer settings.
1174 GLenum buffers[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1,
1175 GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
1176 GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5,
1177 GL_COLOR_ATTACHMENT6, GL_COLOR_ATTACHMENT7};
1178 framebuffer_->SetDrawBuffers(8, buffers);
1179 EXPECT_EQ(0x31Bu, framebuffer_->draw_buffer_type_mask());
1180 EXPECT_EQ(0x33Fu, framebuffer_->draw_buffer_bound_mask());
1181 EXPECT_TRUE(framebuffer_->ContainsActiveIntegerAttachments());
1182 }
1183
1184 // Test ValidateAndAdjustDrawBuffers().
1185
1186 // gl_FragColor situation.
1187 EXPECT_CALL(*gl_, DrawBuffersARB(kMaxDrawBuffers, _))
1188 .Times(1)
1189 .RetiresOnSaturation();
1190 EXPECT_TRUE(framebuffer_->ValidateAndAdjustDrawBuffers(0x3u, 0x3u));
1191 // gl_FragData situation.
1192 EXPECT_CALL(*gl_, DrawBuffersARB(kMaxDrawBuffers, _))
1193 .Times(0);
1194 EXPECT_FALSE(
1195 framebuffer_->ValidateAndAdjustDrawBuffers(0xFFFFFFFFu, 0xFFFFFFFFu));
1196 // User defined output variables, fully match.
1197 EXPECT_CALL(*gl_, DrawBuffersARB(kMaxDrawBuffers, _))
1198 .Times(0);
1199 EXPECT_TRUE(
1200 framebuffer_->ValidateAndAdjustDrawBuffers(0x31Bu, 0x33Fu));
1201 // User defined output variables, fully on, one type mismatch.
1202 EXPECT_CALL(*gl_, DrawBuffersARB(kMaxDrawBuffers, _))
1203 .Times(0);
1204 EXPECT_FALSE(
1205 framebuffer_->ValidateAndAdjustDrawBuffers(0x32Bu, 0x33Fu));
1206 // Empty output.
1207 EXPECT_CALL(*gl_, DrawBuffersARB(kMaxDrawBuffers, _))
1208 .Times(1)
1209 .RetiresOnSaturation();
1210 EXPECT_TRUE(
1211 framebuffer_->ValidateAndAdjustDrawBuffers(0u, 0u));
1212 // User defined output variables, some active buffers have no corresponding
1213 // output variables, but if they do, types match.
1214 EXPECT_CALL(*gl_, DrawBuffersARB(kMaxDrawBuffers, _))
1215 .Times(1)
1216 .RetiresOnSaturation();
1217 EXPECT_TRUE(
1218 framebuffer_->ValidateAndAdjustDrawBuffers(0x310u, 0x330u));
1092 } 1219 }
1093 1220
1094 class FramebufferInfoFloatTest : public FramebufferInfoTest { 1221 class FramebufferInfoFloatTest : public FramebufferInfoTest {
1095 public: 1222 public:
1096 FramebufferInfoFloatTest() 1223 FramebufferInfoFloatTest()
1097 : FramebufferInfoTest() { 1224 : FramebufferInfoTest() {
1098 } 1225 }
1099 ~FramebufferInfoFloatTest() override {} 1226 ~FramebufferInfoFloatTest() override {}
1100 1227
1101 protected: 1228 protected:
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClientId); 1545 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClientId);
1419 ASSERT_TRUE(renderbuffer != NULL); 1546 ASSERT_TRUE(renderbuffer != NULL);
1420 framebuffer_->AttachRenderbuffer(GL_COLOR_ATTACHMENT1, renderbuffer); 1547 framebuffer_->AttachRenderbuffer(GL_COLOR_ATTACHMENT1, renderbuffer);
1421 EXPECT_TRUE(framebuffer_->GetReadBufferAttachment()); 1548 EXPECT_TRUE(framebuffer_->GetReadBufferAttachment());
1422 } 1549 }
1423 1550
1424 } // namespace gles2 1551 } // namespace gles2
1425 } // namespace gpu 1552 } // namespace gpu
1426 1553
1427 1554
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698