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

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

Issue 1684343002: Upgrade TexSubImage3D and TexStorage3D. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 "gpu/command_buffer/service/gles2_cmd_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 void DoCopyTexSubImage2D( 910 void DoCopyTexSubImage2D(
911 GLenum target, 911 GLenum target,
912 GLint level, 912 GLint level,
913 GLint xoffset, 913 GLint xoffset,
914 GLint yoffset, 914 GLint yoffset,
915 GLint x, 915 GLint x,
916 GLint y, 916 GLint y,
917 GLsizei width, 917 GLsizei width,
918 GLsizei height); 918 GLsizei height);
919 919
920 // Wrapper for TexSubImage3D.
921 error::Error DoTexSubImage3D(
922 GLenum target,
923 GLint level,
924 GLint xoffset,
925 GLint yoffset,
926 GLint zoffset,
927 GLsizei width,
928 GLsizei height,
929 GLsizei depth,
930 GLenum format,
931 GLenum type,
932 const void * data);
933
934 // Wrapper for TexImageIOSurface2DCHROMIUM. 920 // Wrapper for TexImageIOSurface2DCHROMIUM.
935 void DoTexImageIOSurface2DCHROMIUM( 921 void DoTexImageIOSurface2DCHROMIUM(
936 GLenum target, 922 GLenum target,
937 GLsizei width, 923 GLsizei width,
938 GLsizei height, 924 GLsizei height,
939 GLuint io_surface_id, 925 GLuint io_surface_id,
940 GLuint plane); 926 GLuint plane);
941 927
942 void DoCopyTextureCHROMIUM(GLuint source_id, 928 void DoCopyTextureCHROMIUM(GLuint source_id,
943 GLuint dest_id, 929 GLuint dest_id,
(...skipping 18 matching lines...) Expand all
962 void DoCompressedCopyTextureCHROMIUM(GLuint source_id, GLuint dest_id); 948 void DoCompressedCopyTextureCHROMIUM(GLuint source_id, GLuint dest_id);
963 949
964 // Wrapper for TexStorage2DEXT. 950 // Wrapper for TexStorage2DEXT.
965 void DoTexStorage2DEXT( 951 void DoTexStorage2DEXT(
966 GLenum target, 952 GLenum target,
967 GLint levels, 953 GLint levels,
968 GLenum internal_format, 954 GLenum internal_format,
969 GLsizei width, 955 GLsizei width,
970 GLsizei height); 956 GLsizei height);
971 957
958 // Wrapper for TexStorage3D.
959 void DoTexStorage3D(
960 GLenum target,
961 GLint levels,
962 GLenum internal_format,
963 GLsizei width,
964 GLsizei height,
965 GLsizei depth);
966
972 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); 967 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key);
973 void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, 968 void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target,
974 const GLbyte* key); 969 const GLbyte* key);
975 void ProduceTextureRef(const char* func_name, 970 void ProduceTextureRef(const char* func_name,
976 TextureRef* texture_ref, 971 TextureRef* texture_ref,
977 GLenum target, 972 GLenum target,
978 const GLbyte* data); 973 const GLbyte* data);
979 974
980 void EnsureTextureForClientId(GLenum target, GLuint client_id); 975 void EnsureTextureForClientId(GLenum target, GLuint client_id);
981 void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key); 976 void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key);
(...skipping 9099 matching lines...) Expand 10 before | Expand all | Expand 10 after
10081 10076
10082 bool GLES2DecoderImpl::ClearLevel(Texture* texture, 10077 bool GLES2DecoderImpl::ClearLevel(Texture* texture,
10083 unsigned target, 10078 unsigned target,
10084 int level, 10079 int level,
10085 unsigned format, 10080 unsigned format,
10086 unsigned type, 10081 unsigned type,
10087 int xoffset, 10082 int xoffset,
10088 int yoffset, 10083 int yoffset,
10089 int width, 10084 int width,
10090 int height) { 10085 int height) {
10086 // TODO(zmo): Implement clearing of 3D textures. crbug.com/597201.
10087 DCHECK(target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY);
10091 uint32_t channels = GLES2Util::GetChannelsForFormat(format); 10088 uint32_t channels = GLES2Util::GetChannelsForFormat(format);
10092 if ((feature_info_->feature_flags().angle_depth_texture || 10089 if ((feature_info_->feature_flags().angle_depth_texture ||
10093 feature_info_->IsES3Enabled()) 10090 feature_info_->IsES3Enabled())
10094 && (channels & GLES2Util::kDepth) != 0) { 10091 && (channels & GLES2Util::kDepth) != 0) {
10095 // It's a depth format and ANGLE doesn't allow texImage2D or texSubImage2D 10092 // It's a depth format and ANGLE doesn't allow texImage2D or texSubImage2D
10096 // on depth formats. 10093 // on depth formats.
10097 GLuint fb = 0; 10094 GLuint fb = 0;
10098 glGenFramebuffersEXT(1, &fb); 10095 glGenFramebuffersEXT(1, &fb);
10099 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb); 10096 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb);
10100 10097
(...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after
11490 NULL, NULL)) { 11487 NULL, NULL)) {
11491 return error::kOutOfBounds; 11488 return error::kOutOfBounds;
11492 } 11489 }
11493 11490
11494 const void* pixels = GetSharedMemoryAs<const void*>( 11491 const void* pixels = GetSharedMemoryAs<const void*>(
11495 c.pixels_shm_id, c.pixels_shm_offset, data_size); 11492 c.pixels_shm_id, c.pixels_shm_offset, data_size);
11496 if (!pixels) 11493 if (!pixels)
11497 return error::kOutOfBounds; 11494 return error::kOutOfBounds;
11498 11495
11499 TextureManager::DoTexSubImageArguments args = { 11496 TextureManager::DoTexSubImageArguments args = {
11500 target, level, xoffset, yoffset, width, 11497 target, level, xoffset, yoffset, 0, width, height, 1,
11501 height, format, type, pixels, data_size}; 11498 format, type, pixels, data_size,
11499 TextureManager::DoTexSubImageArguments::kTexSubImage2D};
11502 texture_manager()->ValidateAndDoTexSubImage(this, &texture_state_, &state_, 11500 texture_manager()->ValidateAndDoTexSubImage(this, &texture_state_, &state_,
11503 &framebuffer_state_, 11501 &framebuffer_state_,
11504 "glTexSubImage2D", args); 11502 "glTexSubImage2D", args);
11505 11503
11506 // This may be a slow command. Exit command processing to allow for 11504 // This may be a slow command. Exit command processing to allow for
11507 // context preemption and GPU watchdog checks. 11505 // context preemption and GPU watchdog checks.
11508 ExitCommandProcessingEarly(); 11506 ExitCommandProcessingEarly();
11509 return error::kNoError; 11507 return error::kNoError;
11510 } 11508 }
11511 11509
11512 error::Error GLES2DecoderImpl::DoTexSubImage3D(
11513 GLenum target,
11514 GLint level,
11515 GLint xoffset,
11516 GLint yoffset,
11517 GLint zoffset,
11518 GLsizei width,
11519 GLsizei height,
11520 GLsizei depth,
11521 GLenum format,
11522 GLenum type,
11523 const void * data) {
11524 TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget(
11525 &state_, target);
11526 if (!texture_ref) {
11527 LOCAL_SET_GL_ERROR(
11528 GL_INVALID_ENUM, "glTexSubImage3D", "invalid target");
11529 }
11530
11531 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexSubImage3D");
11532 ScopedTextureUploadTimer timer(&texture_state_);
11533 glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height,
11534 depth, format, type, data);
11535 GLenum error = LOCAL_PEEK_GL_ERROR("glTexSubImage3D");
11536 if (error == GL_NO_ERROR) {
11537 // TODO(zmo): This is not 100% correct because only part of the level
11538 // image is cleared.
11539 texture_manager()->SetLevelCleared(texture_ref, target, level, true);
11540 }
11541
11542 // This may be a slow command. Exit command processing to allow for
11543 // context preemption and GPU watchdog checks.
11544 ExitCommandProcessingEarly();
11545 return error::kNoError;
11546 }
11547
11548 error::Error GLES2DecoderImpl::HandleTexSubImage3D(uint32_t immediate_data_size, 11510 error::Error GLES2DecoderImpl::HandleTexSubImage3D(uint32_t immediate_data_size,
11549 const void* cmd_data) { 11511 const void* cmd_data) {
11550 if (!unsafe_es3_apis_enabled()) 11512 if (!unsafe_es3_apis_enabled())
11551 return error::kUnknownCommand; 11513 return error::kUnknownCommand;
11552 11514
11553 const gles2::cmds::TexSubImage3D& c = 11515 const gles2::cmds::TexSubImage3D& c =
11554 *static_cast<const gles2::cmds::TexSubImage3D*>(cmd_data); 11516 *static_cast<const gles2::cmds::TexSubImage3D*>(cmd_data);
11555 TRACE_EVENT2("gpu", "GLES2DecoderImpl::HandleTexSubImage3D", 11517 TRACE_EVENT2("gpu", "GLES2DecoderImpl::HandleTexSubImage3D",
11556 "widthXheight", c.width * c.height, "depth", c.depth); 11518 "widthXheight", c.width * c.height, "depth", c.depth);
11557 GLboolean internal = static_cast<GLboolean>(c.internal); 11519 GLboolean internal = static_cast<GLboolean>(c.internal);
11558 if (internal == GL_TRUE && texture_state_.tex_image_failed) 11520 if (internal == GL_TRUE && texture_state_.tex_image_failed)
11559 return error::kNoError; 11521 return error::kNoError;
11560 11522
11561 GLenum target = static_cast<GLenum>(c.target); 11523 GLenum target = static_cast<GLenum>(c.target);
11562 GLint level = static_cast<GLint>(c.level); 11524 GLint level = static_cast<GLint>(c.level);
11563 GLint xoffset = static_cast<GLint>(c.xoffset); 11525 GLint xoffset = static_cast<GLint>(c.xoffset);
11564 GLint yoffset = static_cast<GLint>(c.yoffset); 11526 GLint yoffset = static_cast<GLint>(c.yoffset);
11565 GLint zoffset = static_cast<GLint>(c.zoffset); 11527 GLint zoffset = static_cast<GLint>(c.zoffset);
11566 GLsizei width = static_cast<GLsizei>(c.width); 11528 GLsizei width = static_cast<GLsizei>(c.width);
11567 GLsizei height = static_cast<GLsizei>(c.height); 11529 GLsizei height = static_cast<GLsizei>(c.height);
11568 GLsizei depth = static_cast<GLsizei>(c.depth); 11530 GLsizei depth = static_cast<GLsizei>(c.depth);
11569 GLenum format = static_cast<GLenum>(c.format); 11531 GLenum format = static_cast<GLenum>(c.format);
11570 GLenum type = static_cast<GLenum>(c.type); 11532 GLenum type = static_cast<GLenum>(c.type);
11571 uint32_t data_size; 11533 uint32_t data_size;
11572 if (!GLES2Util::ComputeImageDataSizes( 11534 if (!GLES2Util::ComputeImageDataSizes(
11573 width, height, depth, format, type, state_.unpack_alignment, &data_size, 11535 width, height, depth, format, type, state_.unpack_alignment, &data_size,
11574 NULL, NULL)) { 11536 NULL, NULL)) {
11575 return error::kOutOfBounds; 11537 return error::kOutOfBounds;
11576 } 11538 }
11539
11577 const void* pixels = GetSharedMemoryAs<const void*>( 11540 const void* pixels = GetSharedMemoryAs<const void*>(
11578 c.pixels_shm_id, c.pixels_shm_offset, data_size); 11541 c.pixels_shm_id, c.pixels_shm_offset, data_size);
11579 return DoTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, 11542 if (!pixels)
11580 height, depth, format, type, pixels); 11543 return error::kOutOfBounds;
11544
11545 TextureManager::DoTexSubImageArguments args = {
11546 target, level, xoffset, yoffset, zoffset, width, height, depth,
11547 format, type, pixels, data_size,
11548 TextureManager::DoTexSubImageArguments::kTexSubImage3D};
11549 texture_manager()->ValidateAndDoTexSubImage(this, &texture_state_, &state_,
11550 &framebuffer_state_,
11551 "glTexSubImage3D", args);
11552
11553 // This may be a slow command. Exit command processing to allow for
11554 // context preemption and GPU watchdog checks.
11555 ExitCommandProcessingEarly();
11556 return error::kNoError;
11581 } 11557 }
11582 11558
11583 error::Error GLES2DecoderImpl::HandleGetVertexAttribPointerv( 11559 error::Error GLES2DecoderImpl::HandleGetVertexAttribPointerv(
11584 uint32_t immediate_data_size, 11560 uint32_t immediate_data_size,
11585 const void* cmd_data) { 11561 const void* cmd_data) {
11586 const gles2::cmds::GetVertexAttribPointerv& c = 11562 const gles2::cmds::GetVertexAttribPointerv& c =
11587 *static_cast<const gles2::cmds::GetVertexAttribPointerv*>(cmd_data); 11563 *static_cast<const gles2::cmds::GetVertexAttribPointerv*>(cmd_data);
11588 GLuint index = static_cast<GLuint>(c.index); 11564 GLuint index = static_cast<GLuint>(c.index);
11589 GLenum pname = static_cast<GLenum>(c.pname); 11565 GLenum pname = static_cast<GLenum>(c.pname);
11590 typedef cmds::GetVertexAttribPointerv::Result Result; 11566 typedef cmds::GetVertexAttribPointerv::Result Result;
(...skipping 2252 matching lines...) Expand 10 before | Expand all | Expand 10 after
13843 level_width, level_height, 1, 0, 13819 level_width, level_height, 1, 0,
13844 format, type, gfx::Rect()); 13820 format, type, gfx::Rect());
13845 } 13821 }
13846 level_width = std::max(1, level_width >> 1); 13822 level_width = std::max(1, level_width >> 1);
13847 level_height = std::max(1, level_height >> 1); 13823 level_height = std::max(1, level_height >> 1);
13848 } 13824 }
13849 texture->SetImmutable(true); 13825 texture->SetImmutable(true);
13850 } 13826 }
13851 } 13827 }
13852 13828
13829 void GLES2DecoderImpl::DoTexStorage3D(
13830 GLenum target,
13831 GLint levels,
13832 GLenum internal_format,
13833 GLsizei width,
13834 GLsizei height,
13835 GLsizei depth) {
13836 TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoTexStorage3D",
13837 "widthXheight", width * height, "depth", depth);
13838 if (!validators_->texture_3_d_target.IsValid(target)) {
13839 LOCAL_SET_GL_ERROR_INVALID_ENUM("glTexStorage3D", target, "target");
13840 return;
13841 }
13842 if (levels <= 0) {
13843 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexStorage3D", "levels <= 0");
13844 return;
13845 }
13846 if (!validators_->texture_internal_format_storage.IsValid(internal_format)) {
13847 LOCAL_SET_GL_ERROR_INVALID_ENUM("glTexStorage3D", internal_format,
13848 "internal_format");
13849 return;
13850 }
13851 if (width <= 0) {
13852 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexStorage3D", "width <= 0");
13853 return;
13854 }
13855 if (height <= 0) {
13856 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexStorage3D", "height <= 0");
13857 return;
13858 }
13859 if (depth <= 0) {
13860 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexStorage3D", "depth <= 0");
13861 return;
13862 }
13863 if (!texture_manager()->ValidForTarget(target, 0, width, height, depth) ||
13864 TextureManager::ComputeMipMapCount(
13865 target, width, height, depth) < levels) {
13866 LOCAL_SET_GL_ERROR(
13867 GL_INVALID_VALUE, "glTexStorage3D", "dimensions out of range");
13868 return;
13869 }
13870 TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget(
13871 &state_, target);
13872 if (!texture_ref) {
13873 LOCAL_SET_GL_ERROR(
13874 GL_INVALID_OPERATION,
13875 "glTexStorage3D", "unknown texture for target");
13876 return;
13877 }
13878 Texture* texture = texture_ref->texture();
13879 if (texture->IsAttachedToFramebuffer()) {
13880 framebuffer_state_.clear_state_dirty = true;
13881 }
13882 if (texture->IsImmutable()) {
13883 LOCAL_SET_GL_ERROR(
13884 GL_INVALID_OPERATION, "glTexStorage3D", "texture is immutable");
13885 return;
13886 }
13887
13888 GLenum format = TextureManager::ExtractFormatFromStorageFormat(
13889 internal_format);
13890 GLenum type = TextureManager::ExtractTypeFromStorageFormat(internal_format);
13891
13892 {
13893 GLsizei level_width = width;
13894 GLsizei level_height = height;
13895 GLsizei level_depth = depth;
13896 uint32_t estimated_size = 0;
13897 for (int ii = 0; ii < levels; ++ii) {
13898 uint32_t level_size = 0;
13899 if (!GLES2Util::ComputeImageDataSizes(
13900 level_width, level_height, level_depth, format, type,
13901 state_.unpack_alignment,
13902 &estimated_size, NULL, NULL) ||
13903 !SafeAddUint32(estimated_size, level_size, &estimated_size)) {
13904 LOCAL_SET_GL_ERROR(
13905 GL_OUT_OF_MEMORY, "glTexStorage3D", "dimensions too large");
13906 return;
13907 }
13908 level_width = std::max(1, level_width >> 1);
13909 level_height = std::max(1, level_height >> 1);
13910 if (target == GL_TEXTURE_3D)
13911 level_depth = std::max(1, level_depth >> 1);
13912 }
13913 if (!EnsureGPUMemoryAvailable(estimated_size)) {
13914 LOCAL_SET_GL_ERROR(
13915 GL_OUT_OF_MEMORY, "glTexStorage3D", "out of memory");
13916 return;
13917 }
13918 }
13919
13920 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexStorage3D");
13921 glTexStorage3D(target, levels, internal_format, width, height, depth);
13922 GLenum error = LOCAL_PEEK_GL_ERROR("glTexStorage3D");
13923 if (error == GL_NO_ERROR) {
13924 GLsizei level_width = width;
13925 GLsizei level_height = height;
13926 GLsizei level_depth = depth;
13927
13928 GLenum cur_format = feature_info_->IsES3Enabled() ?
13929 internal_format : format;
13930 for (int ii = 0; ii < levels; ++ii) {
13931 // TODO(zmo): Implement clearing of 3D textures. crbug.com/597201.
13932 texture_manager()->SetLevelInfo(texture_ref, target, ii, cur_format,
13933 level_width, level_height, level_depth, 0,
13934 format, type,
13935 gfx::Rect(level_width, level_height));
13936 level_width = std::max(1, level_width >> 1);
13937 level_height = std::max(1, level_height >> 1);
13938 if (target == GL_TEXTURE_3D)
13939 level_depth = std::max(1, level_depth >> 1);
13940 }
13941 texture->SetImmutable(true);
13942 }
13943 }
13944
13853 error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM( 13945 error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM(
13854 uint32_t immediate_data_size, 13946 uint32_t immediate_data_size,
13855 const void* cmd_data) { 13947 const void* cmd_data) {
13856 return error::kUnknownCommand; 13948 return error::kUnknownCommand;
13857 } 13949 }
13858 13950
13859 void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target, 13951 void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target,
13860 const GLbyte* data) { 13952 const GLbyte* data) {
13861 TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoProduceTextureCHROMIUM", 13953 TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoProduceTextureCHROMIUM",
13862 "context", logger_.GetLogPrefix(), 13954 "context", logger_.GetLogPrefix(),
(...skipping 1792 matching lines...) Expand 10 before | Expand all | Expand 10 after
15655 } 15747 }
15656 15748
15657 // Include the auto-generated part of this file. We split this because it means 15749 // Include the auto-generated part of this file. We split this because it means
15658 // we can easily edit the non-auto generated parts right here in this file 15750 // we can easily edit the non-auto generated parts right here in this file
15659 // instead of having to edit some template or the code generator. 15751 // instead of having to edit some template or the code generator.
15660 #include "base/macros.h" 15752 #include "base/macros.h"
15661 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 15753 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
15662 15754
15663 } // namespace gles2 15755 } // namespace gles2
15664 } // namespace gpu 15756 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/build_gles2_cmd_buffer.py ('k') | gpu/command_buffer/service/gles2_cmd_decoder_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698