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

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

Issue 2389363002: Move special DEPTH_STENCIL attachment logic from command buffers to WebGL1 (Closed)
Patch Set: Created 4 years, 2 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 5846 matching lines...) Expand 10 before | Expand all | Expand 10 after
5857 break; 5857 break;
5858 } 5858 }
5859 5859
5860 if (!dirty) 5860 if (!dirty)
5861 return; 5861 return;
5862 5862
5863 // Marks each one of them as not cleared. 5863 // Marks each one of them as not cleared.
5864 for (GLsizei i = 0; i < validated_count; ++i) { 5864 for (GLsizei i = 0; i < validated_count; ++i) {
5865 if (framebuffer) { 5865 if (framebuffer) {
5866 if (validated_attachments[i] == GL_DEPTH_STENCIL_ATTACHMENT) { 5866 if (validated_attachments[i] == GL_DEPTH_STENCIL_ATTACHMENT) {
5867 // TODO(qiankun.miao@intel.com): We should only mark DEPTH and STENCIL
5868 // attachments as cleared when command buffer handles DEPTH_STENCIL
5869 // well. http://crbug.com/630568
5870 framebuffer->MarkAttachmentAsCleared(renderbuffer_manager(), 5867 framebuffer->MarkAttachmentAsCleared(renderbuffer_manager(),
5871 texture_manager(), 5868 texture_manager(),
5872 GL_DEPTH_ATTACHMENT, 5869 GL_DEPTH_ATTACHMENT,
5873 false); 5870 false);
5874 framebuffer->MarkAttachmentAsCleared(renderbuffer_manager(), 5871 framebuffer->MarkAttachmentAsCleared(renderbuffer_manager(),
5875 texture_manager(), 5872 texture_manager(),
5876 GL_STENCIL_ATTACHMENT, 5873 GL_STENCIL_ATTACHMENT,
5877 false); 5874 false);
5878 framebuffer->MarkAttachmentAsCleared(renderbuffer_manager(),
5879 texture_manager(),
5880 GL_DEPTH_STENCIL_ATTACHMENT,
5881 false);
5882 } else { 5875 } else {
5883 framebuffer->MarkAttachmentAsCleared(renderbuffer_manager(), 5876 framebuffer->MarkAttachmentAsCleared(renderbuffer_manager(),
5884 texture_manager(), 5877 texture_manager(),
5885 validated_attachments[i], 5878 validated_attachments[i],
5886 false); 5879 false);
5887 } 5880 }
5888 } else { 5881 } else {
5889 switch (validated_attachments[i]) { 5882 switch (validated_attachments[i]) {
5890 case GL_COLOR_EXT: 5883 case GL_COLOR_EXT:
5891 backbuffer_needs_clear_bits_ |= GL_COLOR_BUFFER_BIT; 5884 backbuffer_needs_clear_bits_ |= GL_COLOR_BUFFER_BIT;
(...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after
7120 if (client_renderbuffer_id) { 7113 if (client_renderbuffer_id) {
7121 renderbuffer = GetRenderbuffer(client_renderbuffer_id); 7114 renderbuffer = GetRenderbuffer(client_renderbuffer_id);
7122 if (!renderbuffer) { 7115 if (!renderbuffer) {
7123 LOCAL_SET_GL_ERROR( 7116 LOCAL_SET_GL_ERROR(
7124 GL_INVALID_OPERATION, 7117 GL_INVALID_OPERATION,
7125 "glFramebufferRenderbuffer", "unknown renderbuffer"); 7118 "glFramebufferRenderbuffer", "unknown renderbuffer");
7126 return; 7119 return;
7127 } 7120 }
7128 service_id = renderbuffer->service_id(); 7121 service_id = renderbuffer->service_id();
7129 } 7122 }
7123 std::vector<GLenum> attachments;
7124 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
7125 attachments.push_back(GL_DEPTH_ATTACHMENT);
7126 attachments.push_back(GL_STENCIL_ATTACHMENT);
7127 } else {
7128 attachments.push_back(attachment);
7129 }
7130 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glFramebufferRenderbuffer"); 7130 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glFramebufferRenderbuffer");
7131 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { 7131 for (GLenum attachment_point : attachments) {
7132 glFramebufferRenderbufferEXT( 7132 glFramebufferRenderbufferEXT(
7133 target, GL_DEPTH_ATTACHMENT, renderbuffertarget, service_id); 7133 target, attachment_point, renderbuffertarget, service_id);
7134 glFramebufferRenderbufferEXT( 7134 GLenum error = LOCAL_PEEK_GL_ERROR("glFramebufferRenderbuffer");
7135 target, GL_STENCIL_ATTACHMENT, renderbuffertarget, service_id); 7135 if (error == GL_NO_ERROR) {
7136 } else { 7136 framebuffer->AttachRenderbuffer(attachment_point, renderbuffer);
7137 glFramebufferRenderbufferEXT( 7137 }
7138 target, attachment, renderbuffertarget, service_id);
7139 }
7140 GLenum error = LOCAL_PEEK_GL_ERROR("glFramebufferRenderbuffer");
7141 if (error == GL_NO_ERROR) {
7142 framebuffer->AttachRenderbuffer(attachment, renderbuffer);
7143 } 7138 }
7144 if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { 7139 if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) {
7145 framebuffer_state_.clear_state_dirty = true; 7140 framebuffer_state_.clear_state_dirty = true;
7146 } 7141 }
7147 OnFboChanged(); 7142 OnFboChanged();
7148 } 7143 }
7149 7144
7150 void GLES2DecoderImpl::DoDisable(GLenum cap) { 7145 void GLES2DecoderImpl::DoDisable(GLenum cap) {
7151 if (SetCapabilityState(cap, false)) { 7146 if (SetCapabilityState(cap, false)) {
7152 if (cap == GL_PRIMITIVE_RESTART_FIXED_INDEX && 7147 if (cap == GL_PRIMITIVE_RESTART_FIXED_INDEX &&
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
7220 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 7215 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
7221 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 7216 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
7222 clear_bits |= GL_COLOR_BUFFER_BIT; 7217 clear_bits |= GL_COLOR_BUFFER_BIT;
7223 7218
7224 if (SupportsDrawBuffers()) { 7219 if (SupportsDrawBuffers()) {
7225 reset_draw_buffers = 7220 reset_draw_buffers =
7226 framebuffer->PrepareDrawBuffersForClearingUninitializedAttachments(); 7221 framebuffer->PrepareDrawBuffersForClearingUninitializedAttachments();
7227 } 7222 }
7228 } 7223 }
7229 7224
7230 if (framebuffer->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT) || 7225 if (framebuffer->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)) {
7231 framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) {
7232 glClearStencil(0); 7226 glClearStencil(0);
7233 state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); 7227 state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask);
7234 state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); 7228 state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask);
7235 clear_bits |= GL_STENCIL_BUFFER_BIT; 7229 clear_bits |= GL_STENCIL_BUFFER_BIT;
7236 } 7230 }
7237 7231
7238 if (framebuffer->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT) || 7232 if (framebuffer->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)) {
7239 framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) {
7240 glClearDepth(1.0f); 7233 glClearDepth(1.0f);
7241 state_.SetDeviceDepthMask(GL_TRUE); 7234 state_.SetDeviceDepthMask(GL_TRUE);
7242 clear_bits |= GL_DEPTH_BUFFER_BIT; 7235 clear_bits |= GL_DEPTH_BUFFER_BIT;
7243 } 7236 }
7244 7237
7245 if (clear_bits) { 7238 if (clear_bits) {
7246 if (!cleared_int_renderbuffers && 7239 if (!cleared_int_renderbuffers &&
7247 target == GL_READ_FRAMEBUFFER && draw_framebuffer != framebuffer) { 7240 target == GL_READ_FRAMEBUFFER && draw_framebuffer != framebuffer) {
7248 // TODO(zmo): There is no guarantee that an FBO that is complete on the 7241 // TODO(zmo): There is no guarantee that an FBO that is complete on the
7249 // READ attachment will be complete as a DRAW attachment. 7242 // READ attachment will be complete as a DRAW attachment.
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
7375 target, attachments[ii], textarget, service_id, level); 7368 target, attachments[ii], textarget, service_id, level);
7376 } else { 7369 } else {
7377 if (features().use_img_for_multisampled_render_to_texture) { 7370 if (features().use_img_for_multisampled_render_to_texture) {
7378 glFramebufferTexture2DMultisampleIMG( 7371 glFramebufferTexture2DMultisampleIMG(
7379 target, attachments[ii], textarget, service_id, level, samples); 7372 target, attachments[ii], textarget, service_id, level, samples);
7380 } else { 7373 } else {
7381 glFramebufferTexture2DMultisampleEXT( 7374 glFramebufferTexture2DMultisampleEXT(
7382 target, attachments[ii], textarget, service_id, level, samples); 7375 target, attachments[ii], textarget, service_id, level, samples);
7383 } 7376 }
7384 } 7377 }
7385 } 7378 GLenum error = LOCAL_PEEK_GL_ERROR(name);
7386 GLenum error = LOCAL_PEEK_GL_ERROR(name); 7379 if (error == GL_NO_ERROR) {
7387 if (error == GL_NO_ERROR) { 7380 framebuffer->AttachTexture(attachments[ii], texture_ref, textarget, level,
7388 framebuffer->AttachTexture(attachment, texture_ref, textarget, level, 7381 samples);
7389 samples); 7382 }
7390 } 7383 }
7391 if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { 7384 if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) {
7392 framebuffer_state_.clear_state_dirty = true; 7385 framebuffer_state_.clear_state_dirty = true;
7393 } 7386 }
7394 7387
7395 OnFboChanged(); 7388 OnFboChanged();
7396 } 7389 }
7397 7390
7398 void GLES2DecoderImpl::DoFramebufferTextureLayer( 7391 void GLES2DecoderImpl::DoFramebufferTextureLayer(
7399 GLenum target, GLenum attachment, GLuint client_texture_id, 7392 GLenum target, GLenum attachment, GLuint client_texture_id,
(...skipping 29 matching lines...) Expand all
7429 return; 7422 return;
7430 } 7423 }
7431 if (!texture_manager()->ValidForTarget(texture_target, level, 7424 if (!texture_manager()->ValidForTarget(texture_target, level,
7432 0, 0, layer)) { 7425 0, 0, layer)) {
7433 LOCAL_SET_GL_ERROR( 7426 LOCAL_SET_GL_ERROR(
7434 GL_INVALID_VALUE, function_name, "invalid level or layer"); 7427 GL_INVALID_VALUE, function_name, "invalid level or layer");
7435 return; 7428 return;
7436 } 7429 }
7437 } 7430 }
7438 glFramebufferTextureLayer(target, attachment, service_id, level, layer); 7431 glFramebufferTextureLayer(target, attachment, service_id, level, layer);
7439 framebuffer->AttachTextureLayer( 7432 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
7440 attachment, texture_ref, texture_target, level, layer); 7433 framebuffer->AttachTextureLayer(
7434 GL_DEPTH_ATTACHMENT, texture_ref, texture_target, level, layer);
7435 framebuffer->AttachTextureLayer(
7436 GL_STENCIL_ATTACHMENT, texture_ref, texture_target, level, layer);
7437 } else {
7438 framebuffer->AttachTextureLayer(
7439 attachment, texture_ref, texture_target, level, layer);
7440 }
7441 if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { 7441 if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) {
7442 framebuffer_state_.clear_state_dirty = true; 7442 framebuffer_state_.clear_state_dirty = true;
7443 } 7443 }
7444 } 7444 }
7445 7445
7446 void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv( 7446 void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv(
7447 GLenum target, GLenum attachment, GLenum pname, GLint* params) { 7447 GLenum target, GLenum attachment, GLenum pname, GLint* params) {
7448 const char kFunctionName[] = "glGetFramebufferAttachmentParameteriv"; 7448 const char kFunctionName[] = "glGetFramebufferAttachmentParameteriv";
7449 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); 7449 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target);
7450 if (!framebuffer) { 7450 if (!framebuffer) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
7486 attachment = GL_DEPTH_ATTACHMENT; 7486 attachment = GL_DEPTH_ATTACHMENT;
7487 break; 7487 break;
7488 case GL_STENCIL: 7488 case GL_STENCIL:
7489 attachment = GL_STENCIL_ATTACHMENT; 7489 attachment = GL_STENCIL_ATTACHMENT;
7490 break; 7490 break;
7491 default: 7491 default:
7492 NOTREACHED(); 7492 NOTREACHED();
7493 break; 7493 break;
7494 } 7494 }
7495 } 7495 }
7496 } else {
7497 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
7498 const Framebuffer::Attachment* depth =
7499 framebuffer->GetAttachment(GL_DEPTH_ATTACHMENT);
7500 const Framebuffer::Attachment* stencil =
7501 framebuffer->GetAttachment(GL_STENCIL_ATTACHMENT);
7502 if ((!depth && !stencil) ||
7503 (depth && stencil && depth->IsSameAttachment(stencil))) {
7504 attachment = GL_DEPTH_ATTACHMENT;
7505 } else {
7506 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, kFunctionName,
7507 "depth and stencil attachment mismatch");
7508 return;
7509 }
7510 }
7496 } 7511 }
7497 if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT && 7512 if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT &&
7498 features().use_img_for_multisampled_render_to_texture) { 7513 features().use_img_for_multisampled_render_to_texture) {
7499 pname = GL_TEXTURE_SAMPLES_IMG; 7514 pname = GL_TEXTURE_SAMPLES_IMG;
7500 } 7515 }
7501 if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) { 7516 if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) {
7502 DCHECK(framebuffer); 7517 DCHECK(framebuffer);
7503 // If we query from the driver, it will be service ID; however, we need to 7518 // If we query from the driver, it will be service ID; however, we need to
7504 // return the client ID here. 7519 // return the client ID here.
7505 const Framebuffer::Attachment* attachment_object = 7520 const Framebuffer::Attachment* attachment_object =
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
7595 // and draw framebuffe is default framebuffer, but the other is fbo, they 7610 // and draw framebuffe is default framebuffer, but the other is fbo, they
7596 // always have no identical image. 7611 // always have no identical image.
7597 if (!read_framebuffer && !draw_framebuffer) { 7612 if (!read_framebuffer && !draw_framebuffer) {
7598 is_feedback_loop = FeedbackLoopTrue; 7613 is_feedback_loop = FeedbackLoopTrue;
7599 } else if (!read_framebuffer || !draw_framebuffer) { 7614 } else if (!read_framebuffer || !draw_framebuffer) {
7600 is_feedback_loop = FeedbackLoopFalse; 7615 is_feedback_loop = FeedbackLoopFalse;
7601 } else { 7616 } else {
7602 DCHECK(read_framebuffer && draw_framebuffer); 7617 DCHECK(read_framebuffer && draw_framebuffer);
7603 if ((mask & GL_DEPTH_BUFFER_BIT) != 0) { 7618 if ((mask & GL_DEPTH_BUFFER_BIT) != 0) {
7604 const Framebuffer::Attachment* depth_buffer_read = 7619 const Framebuffer::Attachment* depth_buffer_read =
7605 read_framebuffer->GetDepthAttachment(); 7620 read_framebuffer->GetAttachment(GL_DEPTH_ATTACHMENT);
7606 const Framebuffer::Attachment* depth_buffer_draw = 7621 const Framebuffer::Attachment* depth_buffer_draw =
7607 draw_framebuffer->GetDepthAttachment(); 7622 draw_framebuffer->GetAttachment(GL_DEPTH_ATTACHMENT);
7608 if (!depth_buffer_draw || !depth_buffer_read) { 7623 if (!depth_buffer_draw || !depth_buffer_read) {
7609 mask &= ~GL_DEPTH_BUFFER_BIT; 7624 mask &= ~GL_DEPTH_BUFFER_BIT;
7610 } else if (depth_buffer_draw->IsSameAttachment(depth_buffer_read)) { 7625 } else if (depth_buffer_draw->IsSameAttachment(depth_buffer_read)) {
7611 is_feedback_loop = FeedbackLoopTrue; 7626 is_feedback_loop = FeedbackLoopTrue;
7612 } 7627 }
7613 } 7628 }
7614 if ((mask & GL_STENCIL_BUFFER_BIT) != 0) { 7629 if ((mask & GL_STENCIL_BUFFER_BIT) != 0) {
7615 const Framebuffer::Attachment* stencil_buffer_read = 7630 const Framebuffer::Attachment* stencil_buffer_read =
7616 read_framebuffer->GetStencilAttachment(); 7631 read_framebuffer->GetAttachment(GL_STENCIL_ATTACHMENT);
7617 const Framebuffer::Attachment* stencil_buffer_draw = 7632 const Framebuffer::Attachment* stencil_buffer_draw =
7618 draw_framebuffer->GetStencilAttachment(); 7633 draw_framebuffer->GetAttachment(GL_STENCIL_ATTACHMENT);
7619 if (!stencil_buffer_draw || !stencil_buffer_read) { 7634 if (!stencil_buffer_draw || !stencil_buffer_read) {
7620 mask &= ~GL_STENCIL_BUFFER_BIT; 7635 mask &= ~GL_STENCIL_BUFFER_BIT;
7621 } else if (stencil_buffer_draw->IsSameAttachment(stencil_buffer_read)) { 7636 } else if (stencil_buffer_draw->IsSameAttachment(stencil_buffer_read)) {
7622 is_feedback_loop = FeedbackLoopTrue; 7637 is_feedback_loop = FeedbackLoopTrue;
7623 } 7638 }
7624 } 7639 }
7625 if (!mask) 7640 if (!mask)
7626 return; 7641 return;
7627 } 7642 }
7628 7643
(...skipping 10515 matching lines...) Expand 10 before | Expand all | Expand 10 after
18144 } 18159 }
18145 18160
18146 // Include the auto-generated part of this file. We split this because it means 18161 // Include the auto-generated part of this file. We split this because it means
18147 // we can easily edit the non-auto generated parts right here in this file 18162 // we can easily edit the non-auto generated parts right here in this file
18148 // instead of having to edit some template or the code generator. 18163 // instead of having to edit some template or the code generator.
18149 #include "base/macros.h" 18164 #include "base/macros.h"
18150 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 18165 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
18151 18166
18152 } // namespace gles2 18167 } // namespace gles2
18153 } // namespace gpu 18168 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698