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

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

Issue 954053002: gpu: Avoid detaching images with glTexSubImage2D (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "gpu/command_buffer/service/gles2_cmd_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "gpu/command_buffer/common/gles2_cmd_format.h" 9 #include "gpu/command_buffer/common/gles2_cmd_format.h"
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 10 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
(...skipping 2156 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); 2167 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2168 EXPECT_EQ(3, width); 2168 EXPECT_EQ(3, width);
2169 EXPECT_EQ(1, height); 2169 EXPECT_EQ(1, height);
2170 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format)); 2170 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2171 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format); 2171 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2172 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type); 2172 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2173 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); 2173 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2174 2174
2175 // Bind image to texture. 2175 // Bind image to texture.
2176 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. 2176 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2177 EXPECT_CALL(*gl_, GetError()) 2177 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1);
2178 .WillOnce(Return(GL_NO_ERROR))
2179 .WillOnce(Return(GL_NO_ERROR))
2180 .RetiresOnSaturation();
2181 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
2182 bind_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1);
2183 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2184 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); 2178 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2185 // Image should now be set. 2179 // Image should now be set.
2186 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); 2180 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2187 2181
2188 // Define new texture image. 2182 // Define new texture image.
2189 DoTexImage2D( 2183 DoTexImage2D(
2190 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 2184 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2191 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); 2185 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2192 // Image should no longer be set. 2186 // Image should no longer be set.
2193 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); 2187 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2194 } 2188 }
2195 2189
2196 TEST_P(GLES2DecoderTest, BindTexImage2DCHROMIUMCubeMapNotAllowed) { 2190 TEST_P(GLES2DecoderTest, BindTexImage2DCHROMIUMCubeMapNotAllowed) {
2197 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub); 2191 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2198 GetImageManager()->AddImage(image.get(), 1); 2192 GetImageManager()->AddImage(image.get(), 1);
2199 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId); 2193 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId);
2200 2194
2201 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd; 2195 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
2202 bind_tex_image_2d_cmd.Init(GL_TEXTURE_CUBE_MAP, 1); 2196 bind_tex_image_2d_cmd.Init(GL_TEXTURE_CUBE_MAP, 1);
2203 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd)); 2197 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2204 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); 2198 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
2205 } 2199 }
2206 2200
2207 TEST_P(GLES2DecoderTest, OrphanGLImageWithTexImage2D) { 2201 TEST_P(GLES2DecoderTest, OrphanGLImageWithTexImage2D) {
2208 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub); 2202 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2209 GetImageManager()->AddImage(image.get(), 1); 2203 GetImageManager()->AddImage(image.get(), 1);
2210 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId); 2204 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2211 2205
2212 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd; 2206 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1);
2213 bind_tex_image_2d_cmd.Init(GL_TEXTURE_CUBE_MAP, 1);
2214 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2215 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
2216 2207
2217 DoTexImage2D(
2218 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2219 TextureRef* texture_ref = 2208 TextureRef* texture_ref =
2220 group().texture_manager()->GetTexture(client_texture_id_); 2209 group().texture_manager()->GetTexture(client_texture_id_);
2221 ASSERT_TRUE(texture_ref != NULL); 2210 ASSERT_TRUE(texture_ref != NULL);
2222 Texture* texture = texture_ref->texture(); 2211 Texture* texture = texture_ref->texture();
2212
2213 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == image.get());
2214 DoTexImage2D(
2215 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2223 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); 2216 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2224 } 2217 }
2225 2218
2219 TEST_P(GLES2DecoderTest, GLImageAttachedAfterSubTexImage2D) {
2220 // Specifically tests that TexSubImage2D is not optimized to TexImage2D
2221 // in the presence of image attachments.
2222 ASSERT_FALSE(
2223 feature_info()->workarounds().texsubimage2d_faster_than_teximage2d);
2224
2225 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2226 GetImageManager()->AddImage(image.get(), 1);
2227 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2228
2229 GLenum target = GL_TEXTURE_2D;
2230 GLint level = 0;
2231 GLint xoffset = 0;
2232 GLint yoffset = 0;
2233 GLsizei width = 1;
2234 GLsizei height = 1;
2235 GLint border = 0;
2236 GLenum format = GL_RGBA;
2237 GLenum type = GL_UNSIGNED_BYTE;
2238 uint32_t pixels_shm_id = kSharedMemoryId;
2239 uint32_t pixels_shm_offset = kSharedMemoryOffset;
2240 GLboolean internal = 0;
2241
2242 // Define texture first.
2243 DoTexImage2D(target, level, format, width, height, border, format, type,
2244 pixels_shm_id, pixels_shm_offset);
2245
2246 // Bind texture to GLImage.
2247 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1);
2248
2249 // Check binding.
2250 TextureRef* texture_ref =
2251 group().texture_manager()->GetTexture(client_texture_id_);
2252 ASSERT_TRUE(texture_ref != NULL);
2253 Texture* texture = texture_ref->texture();
2254 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == image.get());
2255
2256 // TexSubImage2D should not unbind GLImage.
2257 EXPECT_CALL(*gl_, TexSubImage2D(target, level, xoffset, yoffset, width,
2258 height, format, type, _))
2259 .Times(1)
2260 .RetiresOnSaturation();
2261 cmds::TexSubImage2D tex_sub_image_2d_cmd;
2262 tex_sub_image_2d_cmd.Init(target, level, xoffset, yoffset, width, height,
2263 format, type, pixels_shm_id, pixels_shm_offset,
2264 internal);
2265 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_sub_image_2d_cmd));
2266 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == image.get());
2267 }
2268
2269 TEST_P(GLES2DecoderTest, GLImageAttachedAfterClearLevel) {
2270 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2271 GetImageManager()->AddImage(image.get(), 1);
2272 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2273
2274 GLenum target = GL_TEXTURE_2D;
2275 GLint level = 0;
2276 GLint xoffset = 0;
2277 GLint yoffset = 0;
2278 GLsizei width = 1;
2279 GLsizei height = 1;
2280 GLint border = 0;
2281 GLenum format = GL_RGBA;
2282 GLenum type = GL_UNSIGNED_BYTE;
2283 uint32_t pixels_shm_id = kSharedMemoryId;
2284 uint32_t pixels_shm_offset = kSharedMemoryOffset;
2285
2286 // Define texture first.
2287 DoTexImage2D(target, level, format, width, height, border, format, type,
2288 pixels_shm_id, pixels_shm_offset);
2289
2290 // Bind texture to GLImage.
2291 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1);
2292
2293 // Check binding.
2294 TextureRef* texture_ref =
2295 group().texture_manager()->GetTexture(client_texture_id_);
2296 ASSERT_TRUE(texture_ref != NULL);
2297 Texture* texture = texture_ref->texture();
2298 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == image.get());
2299
2300 // ClearLevel should use glTexSubImage2D to avoid unbinding GLImage.
2301 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
2302 .Times(2)
2303 .RetiresOnSaturation();
2304 EXPECT_CALL(*gl_, TexSubImage2D(target, level, xoffset, yoffset, width,
2305 height, format, type, _))
2306 .Times(1)
2307 .RetiresOnSaturation();
2308 GetDecoder()->ClearLevel(texture, target, level, format, format, type, width,
2309 height, false);
2310 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == image.get());
2311 }
2312
2226 TEST_P(GLES2DecoderTest, ReleaseTexImage2DCHROMIUM) { 2313 TEST_P(GLES2DecoderTest, ReleaseTexImage2DCHROMIUM) {
2227 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); 2314 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2228 DoTexImage2D( 2315 DoTexImage2D(
2229 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0); 2316 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2230 TextureRef* texture_ref = 2317 TextureRef* texture_ref =
2231 group().texture_manager()->GetTexture(client_texture_id_); 2318 group().texture_manager()->GetTexture(client_texture_id_);
2232 ASSERT_TRUE(texture_ref != NULL); 2319 ASSERT_TRUE(texture_ref != NULL);
2233 Texture* texture = texture_ref->texture(); 2320 Texture* texture = texture_ref->texture();
2234 EXPECT_EQ(kServiceTextureId, texture->service_id()); 2321 EXPECT_EQ(kServiceTextureId, texture->service_id());
2235 2322
2236 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub); 2323 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2237 GetImageManager()->AddImage(image.get(), 1); 2324 GetImageManager()->AddImage(image.get(), 1);
2238 EXPECT_FALSE(GetImageManager()->LookupImage(1) == NULL); 2325 EXPECT_FALSE(GetImageManager()->LookupImage(1) == NULL);
2239 2326
2240 GLsizei width; 2327 GLsizei width;
2241 GLsizei height; 2328 GLsizei height;
2242 GLenum type; 2329 GLenum type;
2243 GLenum internal_format; 2330 GLenum internal_format;
2244 2331
2245 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); 2332 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2246 EXPECT_EQ(3, width); 2333 EXPECT_EQ(3, width);
2247 EXPECT_EQ(1, height); 2334 EXPECT_EQ(1, height);
2248 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format)); 2335 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2249 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format); 2336 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2250 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type); 2337 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2251 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); 2338 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2252 2339
2253 // Bind image to texture. 2340 // Bind image to texture.
2254 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. 2341 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2255 EXPECT_CALL(*gl_, GetError()) 2342 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1);
2256 .WillOnce(Return(GL_NO_ERROR))
2257 .WillOnce(Return(GL_NO_ERROR))
2258 .RetiresOnSaturation();
2259 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
2260 bind_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1);
2261 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2262 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height)); 2343 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2263 // Image should now be set. 2344 // Image should now be set.
2264 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); 2345 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2265 2346
2266 // Release image from texture. 2347 // Release image from texture.
2267 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. 2348 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2268 EXPECT_CALL(*gl_, GetError()) 2349 EXPECT_CALL(*gl_, GetError())
2269 .WillOnce(Return(GL_NO_ERROR)) 2350 .WillOnce(Return(GL_NO_ERROR))
2270 .WillOnce(Return(GL_NO_ERROR)) 2351 .WillOnce(Return(GL_NO_ERROR))
2271 .RetiresOnSaturation(); 2352 .RetiresOnSaturation();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2327 // Bind image to texture. 2408 // Bind image to texture.
2328 EXPECT_CALL(*image.get(), BindTexImage(GL_TEXTURE_2D)) 2409 EXPECT_CALL(*image.get(), BindTexImage(GL_TEXTURE_2D))
2329 .Times(1) 2410 .Times(1)
2330 .WillOnce(Return(true)) 2411 .WillOnce(Return(true))
2331 .RetiresOnSaturation(); 2412 .RetiresOnSaturation();
2332 EXPECT_CALL(*image.get(), GetSize()) 2413 EXPECT_CALL(*image.get(), GetSize())
2333 .Times(1) 2414 .Times(1)
2334 .WillOnce(Return(gfx::Size(1, 1))) 2415 .WillOnce(Return(gfx::Size(1, 1)))
2335 .RetiresOnSaturation(); 2416 .RetiresOnSaturation();
2336 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. 2417 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2337 EXPECT_CALL(*gl_, GetError()) 2418 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId);
2338 .WillOnce(Return(GL_NO_ERROR))
2339 .WillOnce(Return(GL_NO_ERROR))
2340 .RetiresOnSaturation();
2341 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
2342 bind_tex_image_2d_cmd.Init(GL_TEXTURE_2D, kImageId);
2343 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2344 2419
2345 AddExpectationsForSimulatedAttrib0(kNumVertices, 0); 2420 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2346 SetupExpectationsForApplyingDefaultDirtyState(); 2421 SetupExpectationsForApplyingDefaultDirtyState();
2347 2422
2348 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor. 2423 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2349 EXPECT_CALL(*gl_, GetError()) 2424 EXPECT_CALL(*gl_, GetError())
2350 .WillOnce(Return(GL_NO_ERROR)) 2425 .WillOnce(Return(GL_NO_ERROR))
2351 .WillOnce(Return(GL_NO_ERROR)) 2426 .WillOnce(Return(GL_NO_ERROR))
2352 .WillOnce(Return(GL_NO_ERROR)) 2427 .WillOnce(Return(GL_NO_ERROR))
2353 .WillOnce(Return(GL_NO_ERROR)) 2428 .WillOnce(Return(GL_NO_ERROR))
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
2837 // TODO(gman): CompressedTexSubImage2DImmediate 2912 // TODO(gman): CompressedTexSubImage2DImmediate
2838 2913
2839 // TODO(gman): TexImage2D 2914 // TODO(gman): TexImage2D
2840 2915
2841 // TODO(gman): TexImage2DImmediate 2916 // TODO(gman): TexImage2DImmediate
2842 2917
2843 // TODO(gman): TexSubImage2DImmediate 2918 // TODO(gman): TexSubImage2DImmediate
2844 2919
2845 } // namespace gles2 2920 } // namespace gles2
2846 } // namespace gpu 2921 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc ('k') | gpu/command_buffer/service/texture_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698