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

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

Issue 2190543005: Command buffer: feedback loop detection for CopyTexSubImage3D (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Command buffer: feedback loop detection for CopyTexSubImage3D Created 4 years, 4 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 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 void RestoreClearState(); 1346 void RestoreClearState();
1347 1347
1348 // Remembers the state of some capabilities. 1348 // Remembers the state of some capabilities.
1349 // Returns: true if glEnable/glDisable should actually be called. 1349 // Returns: true if glEnable/glDisable should actually be called.
1350 bool SetCapabilityState(GLenum cap, bool enabled); 1350 bool SetCapabilityState(GLenum cap, bool enabled);
1351 1351
1352 // Infer color encoding from internalformat 1352 // Infer color encoding from internalformat
1353 static GLint GetColorEncodingFromInternalFormat(GLenum internalformat); 1353 static GLint GetColorEncodingFromInternalFormat(GLenum internalformat);
1354 1354
1355 // Check that the currently bound read framebuffer's color image 1355 // Check that the currently bound read framebuffer's color image
1356 // isn't the target texture of the glCopyTex{Sub}Image2D. 1356 // isn't the target texture of the glCopyTex{Sub}Image{2D|3D}.
1357 bool FormsTextureCopyingFeedbackLoop(TextureRef* texture, GLint level); 1357 bool FormsTextureCopyingFeedbackLoop(
1358 TextureRef* texture,
1359 GLint level,
1360 GLint layer);
1358 1361
1359 // Check if a framebuffer meets our requirements. 1362 // Check if a framebuffer meets our requirements.
1360 // Generates |gl_error| if the framebuffer is incomplete. 1363 // Generates |gl_error| if the framebuffer is incomplete.
1361 bool CheckFramebufferValid( 1364 bool CheckFramebufferValid(
1362 Framebuffer* framebuffer, 1365 Framebuffer* framebuffer,
1363 GLenum target, 1366 GLenum target,
1364 GLenum gl_error, 1367 GLenum gl_error,
1365 const char* func_name); 1368 const char* func_name);
1366 1369
1367 bool CheckBoundDrawFramebufferValid(const char* func_name); 1370 bool CheckBoundDrawFramebufferValid(const char* func_name);
(...skipping 2867 matching lines...) Expand 10 before | Expand all | Expand 10 after
4235 // behave correctly. 4238 // behave correctly.
4236 bool enable_framebuffer_srgb = 4239 bool enable_framebuffer_srgb =
4237 framebuffer && framebuffer->HasSRGBAttachments(); 4240 framebuffer && framebuffer->HasSRGBAttachments();
4238 state_.EnableDisableFramebufferSRGB(enable_framebuffer_srgb); 4241 state_.EnableDisableFramebufferSRGB(enable_framebuffer_srgb);
4239 } 4242 }
4240 return valid; 4243 return valid;
4241 } 4244 }
4242 4245
4243 bool GLES2DecoderImpl::CheckBoundReadFramebufferValid( 4246 bool GLES2DecoderImpl::CheckBoundReadFramebufferValid(
4244 const char* func_name, GLenum gl_error) { 4247 const char* func_name, GLenum gl_error) {
4245 GLenum target = features().chromium_framebuffer_multisample ? 4248 GLenum target = GL_FRAMEBUFFER;
4246 GL_READ_FRAMEBUFFER : GL_FRAMEBUFFER; 4249 if (feature_info_->IsWebGL2OrES3Context() ||
qiankun 2016/07/28 13:59:31 Can you explain why webgl2 or es3 are different he
Zhenyao Mo 2016/07/28 14:51:37 I don't think this is necessary. chromium_framebu
yunchao 2016/07/28 15:53:05 Got it.
yunchao 2016/07/28 15:53:06 For read buffer, we should get info from GL_READ_F
4250 features().chromium_framebuffer_multisample) {
4251 target = GL_READ_FRAMEBUFFER;
4252 }
4247 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); 4253 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target);
4248 bool valid = CheckFramebufferValid( 4254 bool valid = CheckFramebufferValid(
4249 framebuffer, target, gl_error, func_name); 4255 framebuffer, target, gl_error, func_name);
4250 return valid; 4256 return valid;
4251 } 4257 }
4252 4258
4253 bool GLES2DecoderImpl::CheckBoundFramebufferValid(const char* func_name) { 4259 bool GLES2DecoderImpl::CheckBoundFramebufferValid(const char* func_name) {
4254 GLenum target = features().chromium_framebuffer_multisample ? 4260 GLenum target = features().chromium_framebuffer_multisample ?
4255 GL_DRAW_FRAMEBUFFER : GL_FRAMEBUFFER; 4261 GL_DRAW_FRAMEBUFFER : GL_FRAMEBUFFER;
4256 Framebuffer* draw_framebuffer = GetFramebufferInfoForTarget(target); 4262 Framebuffer* draw_framebuffer = GetFramebufferInfoForTarget(target);
(...skipping 23 matching lines...) Expand all
4280 case GL_SRGB_ALPHA_EXT: 4286 case GL_SRGB_ALPHA_EXT:
4281 case GL_SRGB8: 4287 case GL_SRGB8:
4282 case GL_SRGB8_ALPHA8: 4288 case GL_SRGB8_ALPHA8:
4283 return GL_SRGB; 4289 return GL_SRGB;
4284 default: 4290 default:
4285 return GL_LINEAR; 4291 return GL_LINEAR;
4286 } 4292 }
4287 } 4293 }
4288 4294
4289 bool GLES2DecoderImpl::FormsTextureCopyingFeedbackLoop( 4295 bool GLES2DecoderImpl::FormsTextureCopyingFeedbackLoop(
4290 TextureRef* texture, GLint level) { 4296 TextureRef* texture, GLint level, GLint layer) {
4291 Framebuffer* framebuffer = features().chromium_framebuffer_multisample ? 4297 bool is_webgl2_or_es3 = feature_info_->IsWebGL2OrES3Context();
4292 framebuffer_state_.bound_read_framebuffer.get() : 4298 Framebuffer* framebuffer = NULL;
qiankun 2016/07/28 13:59:31 Use nullptr.
4293 framebuffer_state_.bound_draw_framebuffer.get(); 4299 if (is_webgl2_or_es3) {
4300 framebuffer = GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT);
Zhenyao Mo 2016/07/28 14:51:37 I don't think it's necessary. is_webgl2_or_es3 is
yunchao 2016/07/28 15:53:06 Done.
4301 } else {
4302 framebuffer = features().chromium_framebuffer_multisample ?
4303 framebuffer_state_.bound_read_framebuffer.get() :
4304 framebuffer_state_.bound_draw_framebuffer.get();
4305 }
4294 if (!framebuffer) 4306 if (!framebuffer)
4295 return false; 4307 return false;
4296 const Framebuffer::Attachment* attachment = framebuffer->GetAttachment( 4308 const Framebuffer::Attachment* attachment = is_webgl2_or_es3 ?
Zhenyao Mo 2016/07/28 14:51:37 This is unnecessary. In ES2 READ_BUFFER is just C
yunchao 2016/07/28 15:04:04 Why here is not necessary, Zhenyao? I don't unders
yunchao 2016/07/28 15:06:05 Sorry, I got what you mean. We can only use frameb
Zhenyao Mo 2016/07/28 15:06:38 What I mean is you can always call framebuffer->Ge
yunchao 2016/07/28 15:53:06 Yeah.
yunchao 2016/07/28 15:53:06 Yeah.
4297 GL_COLOR_ATTACHMENT0); 4309 framebuffer->GetReadBufferAttachment() :
4310 framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0);
4298 if (!attachment) 4311 if (!attachment)
4299 return false; 4312 return false;
4300 return attachment->FormsFeedbackLoop(texture, level); 4313 return attachment->FormsFeedbackLoop(texture, level, layer);
4301 } 4314 }
4302 4315
4303 gfx::Size GLES2DecoderImpl::GetBoundReadFrameBufferSize() { 4316 gfx::Size GLES2DecoderImpl::GetBoundReadFrameBufferSize() {
4304 Framebuffer* framebuffer = 4317 Framebuffer* framebuffer =
4305 GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); 4318 GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT);
4306 if (framebuffer != NULL) { 4319 if (framebuffer != NULL) {
4307 const Framebuffer::Attachment* attachment = 4320 const Framebuffer::Attachment* attachment =
4308 framebuffer->GetReadBufferAttachment(); 4321 framebuffer->GetReadBufferAttachment();
4309 if (attachment) { 4322 if (attachment) {
4310 return gfx::Size(attachment->width(), attachment->height()); 4323 return gfx::Size(attachment->width(), attachment->height());
(...skipping 8694 matching lines...) Expand 10 before | Expand all | Expand 10 after
13005 state_.unpack_alignment, &pixels_size, NULL, NULL)) { 13018 state_.unpack_alignment, &pixels_size, NULL, NULL)) {
13006 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, func_name, "dimensions too large"); 13019 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, func_name, "dimensions too large");
13007 return; 13020 return;
13008 } 13021 }
13009 13022
13010 if (!EnsureGPUMemoryAvailable(pixels_size)) { 13023 if (!EnsureGPUMemoryAvailable(pixels_size)) {
13011 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, func_name, "out of memory"); 13024 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, func_name, "out of memory");
13012 return; 13025 return;
13013 } 13026 }
13014 13027
13015 if (FormsTextureCopyingFeedbackLoop(texture_ref, level)) { 13028 if (FormsTextureCopyingFeedbackLoop(texture_ref, level, 0)) {
13016 LOCAL_SET_GL_ERROR( 13029 LOCAL_SET_GL_ERROR(
13017 GL_INVALID_OPERATION, 13030 GL_INVALID_OPERATION,
13018 func_name, "source and destination textures are the same"); 13031 func_name, "source and destination textures are the same");
13019 return; 13032 return;
13020 } 13033 }
13021 13034
13022 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(func_name); 13035 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(func_name);
13023 ScopedResolvedFrameBufferBinder binder(this, false, true); 13036 ScopedResolvedFrameBufferBinder binder(this, false, true);
13024 gfx::Size size = GetBoundReadFrameBufferSize(); 13037 gfx::Size size = GetBoundReadFrameBufferSize();
13025 13038
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
13179 return; 13192 return;
13180 } 13193 }
13181 13194
13182 GLenum read_format = GetBoundReadFrameBufferInternalFormat(); 13195 GLenum read_format = GetBoundReadFrameBufferInternalFormat();
13183 GLenum read_type = GetBoundReadFrameBufferTextureType(); 13196 GLenum read_type = GetBoundReadFrameBufferTextureType();
13184 if (!ValidateCopyTexFormat(func_name, internal_format, 13197 if (!ValidateCopyTexFormat(func_name, internal_format,
13185 read_format, read_type)) { 13198 read_format, read_type)) {
13186 return; 13199 return;
13187 } 13200 }
13188 13201
13189 if (FormsTextureCopyingFeedbackLoop(texture_ref, level)) { 13202 if (FormsTextureCopyingFeedbackLoop(texture_ref, level, 0)) {
13190 LOCAL_SET_GL_ERROR( 13203 LOCAL_SET_GL_ERROR(
13191 GL_INVALID_OPERATION, 13204 GL_INVALID_OPERATION,
13192 func_name, "source and destination textures are the same"); 13205 func_name, "source and destination textures are the same");
13193 return; 13206 return;
13194 } 13207 }
13195 13208
13196 ScopedResolvedFrameBufferBinder binder(this, false, true); 13209 ScopedResolvedFrameBufferBinder binder(this, false, true);
13197 gfx::Size size = GetBoundReadFrameBufferSize(); 13210 gfx::Size size = GetBoundReadFrameBufferSize();
13198 GLint copyX = 0; 13211 GLint copyX = 0;
13199 GLint copyY = 0; 13212 GLint copyY = 0;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
13286 return; 13299 return;
13287 } 13300 }
13288 13301
13289 GLenum read_format = GetBoundReadFrameBufferInternalFormat(); 13302 GLenum read_format = GetBoundReadFrameBufferInternalFormat();
13290 GLenum read_type = GetBoundReadFrameBufferTextureType(); 13303 GLenum read_type = GetBoundReadFrameBufferTextureType();
13291 if (!ValidateCopyTexFormat(func_name, internal_format, 13304 if (!ValidateCopyTexFormat(func_name, internal_format,
13292 read_format, read_type)) { 13305 read_format, read_type)) {
13293 return; 13306 return;
13294 } 13307 }
13295 13308
13296 // TODO(yunchao): Follow-up CLs are necessary. For instance, feedback loop 13309 if (FormsTextureCopyingFeedbackLoop(texture_ref, level, zoffset)) {
13297 // detection, emulation of unsized formats in core profile, clear the 3d 13310 LOCAL_SET_GL_ERROR(
13298 // textures if it is uncleared, out-of-bounds reading, etc. 13311 GL_INVALID_OPERATION,
13312 func_name, "source and destination textures are the same");
13313 return;
13314 }
13315
13316 // TODO(yunchao): Follow-up CLs are necessary. For instance:
13317 // 1. emulation of unsized formats in core profile
13318 // 2. clear the 3d textures if it is uncleared.
13319 // 3. out-of-bounds reading, etc.
13299 13320
13300 glCopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, 13321 glCopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width,
13301 height); 13322 height);
13302 13323
13303 // This may be a slow command. Exit command processing to allow for 13324 // This may be a slow command. Exit command processing to allow for
13304 // context preemption and GPU watchdog checks. 13325 // context preemption and GPU watchdog checks.
13305 ExitCommandProcessingEarly(); 13326 ExitCommandProcessingEarly();
13306 } 13327 }
13307 13328
13308 error::Error GLES2DecoderImpl::HandleTexSubImage2D(uint32_t immediate_data_size, 13329 error::Error GLES2DecoderImpl::HandleTexSubImage2D(uint32_t immediate_data_size,
(...skipping 4444 matching lines...) Expand 10 before | Expand all | Expand 10 after
17753 } 17774 }
17754 17775
17755 // Include the auto-generated part of this file. We split this because it means 17776 // Include the auto-generated part of this file. We split this because it means
17756 // we can easily edit the non-auto generated parts right here in this file 17777 // we can easily edit the non-auto generated parts right here in this file
17757 // instead of having to edit some template or the code generator. 17778 // instead of having to edit some template or the code generator.
17758 #include "base/macros.h" 17779 #include "base/macros.h"
17759 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 17780 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
17760 17781
17761 } // namespace gles2 17782 } // namespace gles2
17762 } // namespace gpu 17783 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698