OLD | NEW |
---|---|
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 5659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5670 "glDisableVertexAttribArray", "index out of range"); | 5670 "glDisableVertexAttribArray", "index out of range"); |
5671 } | 5671 } |
5672 } | 5672 } |
5673 | 5673 |
5674 void GLES2DecoderImpl::InvalidateFramebufferImpl( | 5674 void GLES2DecoderImpl::InvalidateFramebufferImpl( |
5675 GLenum target, GLsizei count, const GLenum* attachments, | 5675 GLenum target, GLsizei count, const GLenum* attachments, |
5676 GLint x, GLint y, GLsizei width, GLsizei height, | 5676 GLint x, GLint y, GLsizei width, GLsizei height, |
5677 const char* function_name, FramebufferOperation op) { | 5677 const char* function_name, FramebufferOperation op) { |
5678 Framebuffer* framebuffer = GetFramebufferInfoForTarget(GL_FRAMEBUFFER); | 5678 Framebuffer* framebuffer = GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
5679 | 5679 |
5680 // Because of performance issues, no-op if the format of the attachment is | |
5681 // DEPTH_STENCIL and only one part is intended to be invalidated. | |
5682 bool has_depth_stencil_format = framebuffer && | |
5683 framebuffer->HasDepthStencilFormatAttachment(GL_DEPTH_ATTACHMENT) && | |
5684 framebuffer->HasDepthStencilFormatAttachment(GL_STENCIL_ATTACHMENT); | |
5685 bool invalidate_depth = false; | |
5686 bool invalidate_stencil = false; | |
5687 std::unique_ptr<GLenum[]> validated_attachments(new GLenum[count]); | |
5688 GLsizei validated_count = 0; | |
5689 | |
5680 // Validates the attachments. If one of them fails, the whole command fails. | 5690 // Validates the attachments. If one of them fails, the whole command fails. |
5681 GLenum thresh0 = GL_COLOR_ATTACHMENT0 + group_->max_color_attachments(); | 5691 GLenum thresh0 = GL_COLOR_ATTACHMENT0 + group_->max_color_attachments(); |
5682 GLenum thresh1 = GL_COLOR_ATTACHMENT15; | 5692 GLenum thresh1 = GL_COLOR_ATTACHMENT15; |
5683 for (GLsizei i = 0; i < count; ++i) { | 5693 for (GLsizei i = 0; i < count; ++i) { |
5684 if (framebuffer) { | 5694 if (framebuffer) { |
5685 if (attachments[i] >= thresh0 && attachments[i] <= thresh1) { | 5695 if (attachments[i] >= thresh0 && attachments[i] <= thresh1) { |
5686 LOCAL_SET_GL_ERROR( | 5696 LOCAL_SET_GL_ERROR( |
5687 GL_INVALID_OPERATION, function_name, "invalid attachment"); | 5697 GL_INVALID_OPERATION, function_name, "invalid attachment"); |
5688 return; | 5698 return; |
5689 } | 5699 } |
5690 if (!validators_->attachment.IsValid(attachments[i])) { | 5700 if (!validators_->attachment.IsValid(attachments[i])) { |
5691 LOCAL_SET_GL_ERROR_INVALID_ENUM( | 5701 LOCAL_SET_GL_ERROR_INVALID_ENUM( |
5692 function_name, attachments[i], "attachments"); | 5702 function_name, attachments[i], "attachments"); |
5693 return; | 5703 return; |
5694 } | 5704 } |
5705 if (has_depth_stencil_format) { | |
5706 switch(attachments[i]) { | |
5707 case GL_DEPTH_ATTACHMENT: | |
5708 invalidate_depth = true; | |
5709 continue; | |
5710 case GL_STENCIL_ATTACHMENT: | |
5711 invalidate_stencil = true; | |
5712 continue; | |
5713 } | |
5714 } | |
5695 } else { | 5715 } else { |
5696 if (!validators_->backbuffer_attachment.IsValid(attachments[i])) { | 5716 if (!validators_->backbuffer_attachment.IsValid(attachments[i])) { |
5697 LOCAL_SET_GL_ERROR_INVALID_ENUM( | 5717 LOCAL_SET_GL_ERROR_INVALID_ENUM( |
5698 function_name, attachments[i], "attachments"); | 5718 function_name, attachments[i], "attachments"); |
5699 return; | 5719 return; |
5700 } | 5720 } |
5701 } | 5721 } |
5722 validated_attachments[validated_count++] = attachments[i]; | |
5723 } | |
5724 if (invalidate_depth && invalidate_stencil) { | |
5725 validated_attachments[validated_count++] = GL_DEPTH_STENCIL_ATTACHMENT; | |
5702 } | 5726 } |
5703 | 5727 |
5704 // If the default framebuffer is bound but we are still rendering to an | 5728 // If the default framebuffer is bound but we are still rendering to an |
5705 // FBO, translate attachment names that refer to default framebuffer | 5729 // FBO, translate attachment names that refer to default framebuffer |
5706 // channels to corresponding framebuffer attachments. | 5730 // channels to corresponding framebuffer attachments. |
5707 std::unique_ptr<GLenum[]> translated_attachments(new GLenum[count]); | 5731 std::unique_ptr<GLenum[]> translated_attachments(new GLenum[validated_count]); |
5708 for (GLsizei i = 0; i < count; ++i) { | 5732 for (GLsizei i = 0; i < validated_count; ++i) { |
5709 GLenum attachment = attachments[i]; | 5733 GLenum attachment = validated_attachments[i]; |
5710 if (!framebuffer && GetBackbufferServiceId()) { | 5734 if (!framebuffer && GetBackbufferServiceId()) { |
5711 switch (attachment) { | 5735 switch (attachment) { |
5712 case GL_COLOR_EXT: | 5736 case GL_COLOR_EXT: |
5713 attachment = GL_COLOR_ATTACHMENT0; | 5737 attachment = GL_COLOR_ATTACHMENT0; |
5714 break; | 5738 break; |
5715 case GL_DEPTH_EXT: | 5739 case GL_DEPTH_EXT: |
5716 attachment = GL_DEPTH_ATTACHMENT; | 5740 attachment = GL_DEPTH_ATTACHMENT; |
5717 break; | 5741 break; |
5718 case GL_STENCIL_EXT: | 5742 case GL_STENCIL_EXT: |
5719 attachment = GL_STENCIL_ATTACHMENT; | 5743 attachment = GL_STENCIL_ATTACHMENT; |
5720 break; | 5744 break; |
5721 default: | 5745 default: |
5722 NOTREACHED(); | 5746 NOTREACHED(); |
5723 return; | 5747 return; |
5724 } | 5748 } |
5725 } | 5749 } |
5726 translated_attachments[i] = attachment; | 5750 translated_attachments[i] = attachment; |
5727 } | 5751 } |
5728 | 5752 |
5729 bool dirty = false; | 5753 bool dirty = false; |
5730 switch (op) { | 5754 switch (op) { |
5731 case kFramebufferDiscard: | 5755 case kFramebufferDiscard: |
5732 if (feature_info_->gl_version_info().is_es3) { | 5756 if (feature_info_->gl_version_info().is_es3) { |
5733 glInvalidateFramebuffer( | 5757 glInvalidateFramebuffer( |
5734 target, count, translated_attachments.get()); | 5758 target, validated_count, translated_attachments.get()); |
5735 } else { | 5759 } else { |
5736 glDiscardFramebufferEXT( | 5760 glDiscardFramebufferEXT( |
5737 target, count, translated_attachments.get()); | 5761 target, validated_count, translated_attachments.get()); |
5738 } | 5762 } |
5739 dirty = true; | 5763 dirty = true; |
5740 break; | 5764 break; |
5741 case kFramebufferInvalidate: | 5765 case kFramebufferInvalidate: |
5742 if (feature_info_->gl_version_info().IsLowerThanGL(4, 3)) { | 5766 if (feature_info_->gl_version_info().IsLowerThanGL(4, 3)) { |
5743 // no-op since the function isn't supported. | 5767 // no-op since the function isn't supported. |
5744 } else { | 5768 } else { |
5745 glInvalidateFramebuffer( | 5769 glInvalidateFramebuffer( |
5746 target, count, translated_attachments.get()); | 5770 target, validated_count, translated_attachments.get()); |
5747 dirty = true; | 5771 dirty = true; |
5748 } | 5772 } |
5749 break; | 5773 break; |
5750 case kFramebufferInvalidateSub: | 5774 case kFramebufferInvalidateSub: |
5751 // Make it an no-op because we don't have a mechanism to mark partial | 5775 // Make it an no-op because we don't have a mechanism to mark partial |
5752 // pixels uncleared yet. | 5776 // pixels uncleared yet. |
5753 // TODO(zmo): Revisit this. | 5777 // TODO(zmo): Revisit this. |
5754 break; | 5778 break; |
5755 } | 5779 } |
5756 | 5780 |
5757 if (!dirty) | 5781 if (!dirty) |
5758 return; | 5782 return; |
5759 | 5783 |
5760 // Marks each one of them as not cleared. | 5784 // Marks each one of them as not cleared. |
5761 for (GLsizei i = 0; i < count; ++i) { | 5785 for (GLsizei i = 0; i < validated_count; ++i) { |
5762 if (framebuffer) { | 5786 if (framebuffer) { |
5763 framebuffer->MarkAttachmentAsCleared(renderbuffer_manager(), | 5787 if (validated_attachments[i] == GL_DEPTH_STENCIL_ATTACHMENT) { |
5764 texture_manager(), | 5788 framebuffer->MarkAttachmentAsCleared(renderbuffer_manager(), |
5765 attachments[i], | 5789 texture_manager(), |
5766 false); | 5790 GL_DEPTH_ATTACHMENT, |
5791 false); | |
5792 framebuffer->MarkAttachmentAsCleared(renderbuffer_manager(), | |
5793 texture_manager(), | |
5794 GL_STENCIL_ATTACHMENT, | |
5795 false); | |
5796 } else { | |
5797 framebuffer->MarkAttachmentAsCleared(renderbuffer_manager(), | |
5798 texture_manager(), | |
5799 validated_attachments[i], | |
5800 false); | |
5801 } | |
5767 } else { | 5802 } else { |
5768 switch (attachments[i]) { | 5803 switch (validated_attachments[i]) { |
5769 case GL_COLOR_EXT: | 5804 case GL_COLOR_EXT: |
5770 backbuffer_needs_clear_bits_ |= GL_COLOR_BUFFER_BIT; | 5805 backbuffer_needs_clear_bits_ |= GL_COLOR_BUFFER_BIT; |
5771 break; | 5806 break; |
5772 case GL_DEPTH_EXT: | 5807 case GL_DEPTH_EXT: |
5773 backbuffer_needs_clear_bits_ |= GL_DEPTH_BUFFER_BIT; | 5808 backbuffer_needs_clear_bits_ |= GL_DEPTH_BUFFER_BIT; |
5774 break; | 5809 break; |
5775 case GL_STENCIL_EXT: | 5810 case GL_STENCIL_EXT: |
5776 backbuffer_needs_clear_bits_ |= GL_STENCIL_BUFFER_BIT; | 5811 backbuffer_needs_clear_bits_ |= GL_STENCIL_BUFFER_BIT; |
5777 break; | 5812 break; |
5778 default: | 5813 default: |
(...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6995 glFramebufferRenderbufferEXT( | 7030 glFramebufferRenderbufferEXT( |
6996 target, GL_DEPTH_ATTACHMENT, renderbuffertarget, service_id); | 7031 target, GL_DEPTH_ATTACHMENT, renderbuffertarget, service_id); |
6997 glFramebufferRenderbufferEXT( | 7032 glFramebufferRenderbufferEXT( |
6998 target, GL_STENCIL_ATTACHMENT, renderbuffertarget, service_id); | 7033 target, GL_STENCIL_ATTACHMENT, renderbuffertarget, service_id); |
6999 } else { | 7034 } else { |
7000 glFramebufferRenderbufferEXT( | 7035 glFramebufferRenderbufferEXT( |
7001 target, attachment, renderbuffertarget, service_id); | 7036 target, attachment, renderbuffertarget, service_id); |
7002 } | 7037 } |
7003 GLenum error = LOCAL_PEEK_GL_ERROR("glFramebufferRenderbuffer"); | 7038 GLenum error = LOCAL_PEEK_GL_ERROR("glFramebufferRenderbuffer"); |
7004 if (error == GL_NO_ERROR) { | 7039 if (error == GL_NO_ERROR) { |
7005 framebuffer->AttachRenderbuffer(attachment, renderbuffer); | 7040 framebuffer->AttachRenderbuffer(attachment, renderbuffer); |
qiankun
2016/07/20 18:54:57
If attachment is GL_DEPTH_STENCIL_ATTACHMENT, fram
Zhenyao Mo
2016/07/20 19:08:20
Actually I think somewhere before reaching here, w
Zhenyao Mo
2016/07/20 19:09:51
Yeah, see GLES2DecoderImpl::DoFramebufferRenderbuf
Zhenyao Mo
2016/07/20 19:23:54
You are correct. On blink side, we only split DEP
| |
7006 } | 7041 } |
7007 if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { | 7042 if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
7008 framebuffer_state_.clear_state_dirty = true; | 7043 framebuffer_state_.clear_state_dirty = true; |
7009 } | 7044 } |
7010 OnFboChanged(); | 7045 OnFboChanged(); |
7011 } | 7046 } |
7012 | 7047 |
7013 void GLES2DecoderImpl::DoDisable(GLenum cap) { | 7048 void GLES2DecoderImpl::DoDisable(GLenum cap) { |
7014 if (SetCapabilityState(cap, false)) { | 7049 if (SetCapabilityState(cap, false)) { |
7015 if (cap == GL_PRIMITIVE_RESTART_FIXED_INDEX && | 7050 if (cap == GL_PRIMITIVE_RESTART_FIXED_INDEX && |
(...skipping 10439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17455 } | 17490 } |
17456 | 17491 |
17457 // Include the auto-generated part of this file. We split this because it means | 17492 // Include the auto-generated part of this file. We split this because it means |
17458 // we can easily edit the non-auto generated parts right here in this file | 17493 // we can easily edit the non-auto generated parts right here in this file |
17459 // instead of having to edit some template or the code generator. | 17494 // instead of having to edit some template or the code generator. |
17460 #include "base/macros.h" | 17495 #include "base/macros.h" |
17461 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 17496 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
17462 | 17497 |
17463 } // namespace gles2 | 17498 } // namespace gles2 |
17464 } // namespace gpu | 17499 } // namespace gpu |
OLD | NEW |