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

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

Issue 1838923002: Workaround UNPACK_ROW_LENGTH driver bugs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « gpu/command_buffer/service/texture_manager.h ('k') | gpu/config/gpu_driver_bug_list_json.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "gpu/command_buffer/service/texture_manager.h" 5 #include "gpu/command_buffer/service/texture_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 2314 matching lines...) Expand 10 before | Expand all | Expand 10 after
2325 memset(zero.get(), 0, args.pixels_size); 2325 memset(zero.get(), 0, args.pixels_size);
2326 for (GLenum face : undefined_faces) { 2326 for (GLenum face : undefined_faces) {
2327 new_args.target = face; 2327 new_args.target = face;
2328 new_args.pixels = zero.get(); 2328 new_args.pixels = zero.get();
2329 DoTexImage(texture_state, state, framebuffer_state, 2329 DoTexImage(texture_state, state, framebuffer_state,
2330 function_name, texture_ref, new_args); 2330 function_name, texture_ref, new_args);
2331 texture->MarkLevelAsInternalWorkaround(face, args.level); 2331 texture->MarkLevelAsInternalWorkaround(face, args.level);
2332 } 2332 }
2333 } 2333 }
2334 2334
2335 if (texture_state->unpack_alignment_workaround_with_unpack_buffer && buffer) { 2335 if (texture_state->unpack_parameters_workaround_with_unpack_buffer &&
2336 buffer) {
2336 uint32_t buffer_size = static_cast<uint32_t>(buffer->size()); 2337 uint32_t buffer_size = static_cast<uint32_t>(buffer->size());
2337 if (buffer_size - args.pixels_size - ToGLuint(args.pixels) < args.padding) { 2338 if (buffer_size - args.pixels_size - ToGLuint(args.pixels) < args.padding ||
2339 (state->unpack_row_length != 0 &&
2340 state->unpack_row_length != args.width)) {
2338 // In ValidateTexImage(), we already made sure buffer size is no less 2341 // In ValidateTexImage(), we already made sure buffer size is no less
2339 // than offset + pixels_size. 2342 // than offset + pixels_size.
2340 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); 2343 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
2341 state->SetBoundBuffer(GL_PIXEL_UNPACK_BUFFER, nullptr); 2344 state->SetBoundBuffer(GL_PIXEL_UNPACK_BUFFER, nullptr);
2342 DoTexImageArguments new_args = args; 2345 DoTexImageArguments new_args = args;
2343 new_args.pixels = nullptr; 2346 new_args.pixels = nullptr;
2344 // pixels_size might be incorrect, but it's not used in this case. 2347 // pixels_size might be incorrect, but it's not used in this case.
2345 DoTexImage(texture_state, state, framebuffer_state, function_name, 2348 DoTexImage(texture_state, state, framebuffer_state, function_name,
2346 texture_ref, new_args); 2349 texture_ref, new_args);
2347 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer->service_id()); 2350 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer->service_id());
2348 state->SetBoundBuffer(GL_PIXEL_UNPACK_BUFFER, buffer); 2351 state->SetBoundBuffer(GL_PIXEL_UNPACK_BUFFER, buffer);
2349 2352
2350 DoTexSubImageArguments sub_args = { 2353 DoTexSubImageArguments sub_args = {
2351 args.target, args.level, 0, 0, 0, args.width, args.height, args.depth, 2354 args.target, args.level, 0, 0, 0, args.width, args.height, args.depth,
2352 args.format, args.type, args.pixels, args.pixels_size, args.padding, 2355 args.format, args.type, args.pixels, args.pixels_size, args.padding,
2353 args.command_type == DoTexImageArguments::kTexImage3D ? 2356 args.command_type == DoTexImageArguments::kTexImage3D ?
2354 DoTexSubImageArguments::kTexSubImage3D : 2357 DoTexSubImageArguments::kTexSubImage3D :
2355 DoTexSubImageArguments::kTexSubImage2D}; 2358 DoTexSubImageArguments::kTexSubImage2D};
2356 DoTexSubImageWithAlignmentWorkaround(texture_state, state, sub_args); 2359 DoTexSubImageWithUnpackParamsWorkaround(texture_state, state, sub_args);
2357 2360
2358 SetLevelCleared(texture_ref, args.target, args.level, true); 2361 SetLevelCleared(texture_ref, args.target, args.level, true);
2359 return; 2362 return;
2360 } 2363 }
2361 } 2364 }
2362 DoTexImage(texture_state, state, framebuffer_state, 2365 DoTexImage(texture_state, state, framebuffer_state,
2363 function_name, texture_ref, args); 2366 function_name, texture_ref, args);
2364 } 2367 }
2365 2368
2366 bool TextureManager::ValidateTexSubImage(ContextState* state, 2369 bool TextureManager::ValidateTexSubImage(ContextState* state,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2501 return; 2504 return;
2502 } 2505 }
2503 } 2506 }
2504 full_image = false; 2507 full_image = false;
2505 } else { 2508 } else {
2506 SetLevelCleared(texture_ref, args.target, args.level, true); 2509 SetLevelCleared(texture_ref, args.target, args.level, true);
2507 full_image = true; 2510 full_image = true;
2508 } 2511 }
2509 2512
2510 Buffer* buffer = state->bound_pixel_unpack_buffer.get(); 2513 Buffer* buffer = state->bound_pixel_unpack_buffer.get();
2511 if (texture_state->unpack_alignment_workaround_with_unpack_buffer && buffer) { 2514 if (texture_state->unpack_parameters_workaround_with_unpack_buffer &&
2515 buffer) {
2512 uint32_t buffer_size = static_cast<uint32_t>(buffer->size()); 2516 uint32_t buffer_size = static_cast<uint32_t>(buffer->size());
2513 if (buffer_size - args.pixels_size - ToGLuint(args.pixels) < args.padding) { 2517 if (buffer_size - args.pixels_size - ToGLuint(args.pixels) < args.padding ||
2514 DoTexSubImageWithAlignmentWorkaround(texture_state, state, args); 2518 (state->unpack_row_length != 0 &&
2519 state->unpack_row_length != args.width)) {
2520 DoTexSubImageWithUnpackParamsWorkaround(texture_state, state, args);
2515 return; 2521 return;
2516 } 2522 }
2517 } 2523 }
2518 2524
2519 if (full_image && !texture_state->texsubimage_faster_than_teximage && 2525 if (full_image && !texture_state->texsubimage_faster_than_teximage &&
2520 !texture->IsImmutable() && !texture->HasImages()) { 2526 !texture->IsImmutable() && !texture->HasImages()) {
2521 ScopedTextureUploadTimer timer(texture_state); 2527 ScopedTextureUploadTimer timer(texture_state);
2522 GLenum internal_format; 2528 GLenum internal_format;
2523 GLenum tex_type; 2529 GLenum tex_type;
2524 texture->GetLevelType(args.target, args.level, &tex_type, &internal_format); 2530 texture->GetLevelType(args.target, args.level, &tex_type, &internal_format);
(...skipping 16 matching lines...) Expand all
2541 args.zoffset, args.width, args.height, args.depth, 2547 args.zoffset, args.width, args.height, args.depth,
2542 AdjustTexFormat(args.format), args.type, args.pixels); 2548 AdjustTexFormat(args.format), args.type, args.pixels);
2543 } else { 2549 } else {
2544 glTexSubImage2D(args.target, args.level, args.xoffset, args.yoffset, 2550 glTexSubImage2D(args.target, args.level, args.xoffset, args.yoffset,
2545 args.width, args.height, AdjustTexFormat(args.format), 2551 args.width, args.height, AdjustTexFormat(args.format),
2546 args.type, args.pixels); 2552 args.type, args.pixels);
2547 } 2553 }
2548 } 2554 }
2549 } 2555 }
2550 2556
2551 void TextureManager::DoTexSubImageWithAlignmentWorkaround( 2557 void TextureManager::DoTexSubImageWithUnpackParamsWorkaround(
2552 DecoderTextureState* texture_state, 2558 DecoderTextureState* texture_state,
2553 ContextState* state, 2559 ContextState* state,
2554 const DoTexSubImageArguments& args) { 2560 const DoTexSubImageArguments& args) {
2555 DCHECK(state->bound_pixel_unpack_buffer.get()); 2561 DCHECK(state->bound_pixel_unpack_buffer.get());
2556 DCHECK(args.width > 0 && args.height > 0 && args.depth > 0); 2562 DCHECK(args.width > 0 && args.height > 0 && args.depth > 0);
2557 2563
2558 ScopedTextureUploadTimer timer(texture_state); 2564 ScopedTextureUploadTimer timer(texture_state);
2559 uint32_t offset = ToGLuint(args.pixels); 2565 uint32_t offset = ToGLuint(args.pixels);
2560 if (args.command_type == DoTexSubImageArguments::kTexSubImage2D) { 2566 if (args.command_type == DoTexSubImageArguments::kTexSubImage2D) {
2561 PixelStoreParams params = state->GetUnpackParams(ContextState::k2D); 2567 PixelStoreParams params = state->GetUnpackParams(ContextState::k2D);
2562 if (args.height > 1) { 2568 if (args.height > 1) {
2563 glTexSubImage2D(args.target, args.level, args.xoffset, args.yoffset, 2569 glTexSubImage2D(args.target, args.level, args.xoffset, args.yoffset,
2564 args.width, args.height - 1, 2570 args.width, args.height - 1,
2565 AdjustTexFormat(args.format), args.type, args.pixels); 2571 AdjustTexFormat(args.format), args.type, args.pixels);
2566 GLint actual_width = state->unpack_row_length > 0 ? 2572 GLint actual_width = state->unpack_row_length > 0 ?
2567 state->unpack_row_length : args.width; 2573 state->unpack_row_length : args.width;
2568 uint32_t size; 2574 uint32_t size;
2569 uint32_t padding; 2575 uint32_t padding;
2570 // No need to worry about integer overflow here. 2576 // No need to worry about integer overflow here.
2571 GLES2Util::ComputeImageDataSizesES3(actual_width, args.height - 1, 1, 2577 GLES2Util::ComputeImageDataSizesES3(actual_width, args.height - 1, 1,
2572 args.format, args.type, 2578 args.format, args.type,
2573 params, 2579 params,
2574 &size, 2580 &size,
2575 nullptr, nullptr, nullptr, 2581 nullptr, nullptr, nullptr,
2576 &padding); 2582 &padding);
2577 DCHECK_EQ(args.padding, padding); 2583 DCHECK_EQ(args.padding, padding);
2578 // Last row should be padded, not unpadded. 2584 // Last row should be padded, not unpadded.
2579 offset += size + padding; 2585 offset += size + padding;
2580 } 2586 }
2581 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 2587 if (state->unpack_alignment != 1) {
2588 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
2589 }
2590 if (state->unpack_row_length != 0 &&
2591 state->unpack_row_length != args.width) {
2592 glPixelStorei(GL_UNPACK_ROW_LENGTH, args.width);
2593 }
2582 glTexSubImage2D(args.target, args.level, args.xoffset, 2594 glTexSubImage2D(args.target, args.level, args.xoffset,
2583 args.yoffset + args.height - 1, 2595 args.yoffset + args.height - 1,
2584 args.width, 1, AdjustTexFormat(args.format), args.type, 2596 args.width, 1, AdjustTexFormat(args.format), args.type,
2585 reinterpret_cast<const void *>(offset)); 2597 reinterpret_cast<const void *>(offset));
2586 glPixelStorei(GL_UNPACK_ALIGNMENT, state->unpack_alignment); 2598 if (state->unpack_alignment != 1) {
2599 glPixelStorei(GL_UNPACK_ALIGNMENT, state->unpack_alignment);
2600 }
2601 if (state->unpack_row_length != 0 &&
2602 state->unpack_row_length != args.width) {
2603 glPixelStorei(GL_UNPACK_ROW_LENGTH, state->unpack_row_length);
2604 }
2587 { 2605 {
2588 uint32_t size; 2606 uint32_t size;
2589 GLES2Util::ComputeImageDataSizesES3(args.width, 1, 1, 2607 GLES2Util::ComputeImageDataSizesES3(args.width, 1, 1,
2590 args.format, args.type, 2608 args.format, args.type,
2591 params, 2609 params,
2592 &size, 2610 &size,
2593 nullptr, nullptr, nullptr, nullptr); 2611 nullptr, nullptr, nullptr, nullptr);
2594 offset += size; 2612 offset += size;
2595 } 2613 }
2596 } else { // kTexSubImage3D 2614 } else { // kTexSubImage3D
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2628 GLES2Util::ComputeImageDataSizesES3(actual_width, args.height - 1, 1, 2646 GLES2Util::ComputeImageDataSizesES3(actual_width, args.height - 1, 1,
2629 args.format, args.type, 2647 args.format, args.type,
2630 params, 2648 params,
2631 &size, 2649 &size,
2632 nullptr, nullptr, nullptr, 2650 nullptr, nullptr, nullptr,
2633 &padding); 2651 &padding);
2634 DCHECK_EQ(args.padding, padding); 2652 DCHECK_EQ(args.padding, padding);
2635 // Last row should be padded, not unpadded. 2653 // Last row should be padded, not unpadded.
2636 offset += size + padding; 2654 offset += size + padding;
2637 } 2655 }
2638 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 2656 if (state->unpack_alignment != 1) {
2657 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
2658 }
2659 if (state->unpack_row_length != 0 &&
2660 state->unpack_row_length != args.width) {
2661 glPixelStorei(GL_UNPACK_ROW_LENGTH, args.width);
2662 }
2639 glTexSubImage3D(args.target, args.level, args.xoffset, 2663 glTexSubImage3D(args.target, args.level, args.xoffset,
2640 args.yoffset + args.height - 1, 2664 args.yoffset + args.height - 1,
2641 args.zoffset + args.depth - 1, 2665 args.zoffset + args.depth - 1,
2642 args.width, 1, 1, AdjustTexFormat(args.format), args.type, 2666 args.width, 1, 1, AdjustTexFormat(args.format), args.type,
2643 reinterpret_cast<const void *>(offset)); 2667 reinterpret_cast<const void *>(offset));
2644 glPixelStorei(GL_UNPACK_ALIGNMENT, state->unpack_alignment); 2668 if (state->unpack_alignment != 1) {
2669 glPixelStorei(GL_UNPACK_ALIGNMENT, state->unpack_alignment);
2670 }
2671 if (state->unpack_row_length != 0 &&
2672 state->unpack_row_length != args.width) {
2673 glPixelStorei(GL_UNPACK_ROW_LENGTH, state->unpack_row_length);
2674 }
2645 { 2675 {
2646 uint32_t size; 2676 uint32_t size;
2647 GLES2Util::ComputeImageDataSizesES3(args.width, 1, 1, 2677 GLES2Util::ComputeImageDataSizesES3(args.width, 1, 1,
2648 args.format, args.type, 2678 args.format, args.type,
2649 params, 2679 params,
2650 &size, 2680 &size,
2651 nullptr, nullptr, nullptr, nullptr); 2681 nullptr, nullptr, nullptr, nullptr);
2652 offset += size; 2682 offset += size;
2653 } 2683 }
2654 } 2684 }
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
3134 uint32_t TextureManager::GetServiceIdGeneration() const { 3164 uint32_t TextureManager::GetServiceIdGeneration() const {
3135 return current_service_id_generation_; 3165 return current_service_id_generation_;
3136 } 3166 }
3137 3167
3138 void TextureManager::IncrementServiceIdGeneration() { 3168 void TextureManager::IncrementServiceIdGeneration() {
3139 current_service_id_generation_++; 3169 current_service_id_generation_++;
3140 } 3170 }
3141 3171
3142 } // namespace gles2 3172 } // namespace gles2
3143 } // namespace gpu 3173 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/texture_manager.h ('k') | gpu/config/gpu_driver_bug_list_json.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698