Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_apply_framebuffer_attachment_cmaa _intel.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_apply_framebuffer_attachment_cmaa _intel.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "gpu/command_buffer/service/framebuffer_manager.h" | 8 #include "gpu/command_buffer/service/framebuffer_manager.h" |
| 9 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" | 9 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
| 10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 11 #include "gpu/command_buffer/service/texture_manager.h" | 11 #include "gpu/command_buffer/service/texture_manager.h" |
| 12 #include "ui/gl/gl_context.h" | 12 #include "ui/gl/gl_context.h" |
| 13 #include "ui/gl/gl_gl_api_implementation.h" | 13 #include "ui/gl/gl_gl_api_implementation.h" |
| 14 #include "ui/gl/gl_version_info.h" | 14 #include "ui/gl/gl_version_info.h" |
| 15 | 15 |
| 16 #define SHADER(Src) #Src | 16 #define SHADER(Src) #Src |
| 17 | 17 |
| 18 namespace gpu { | 18 namespace gpu { |
| 19 namespace gles2 { | 19 namespace gles2 { |
| 20 | 20 |
| 21 ApplyFramebufferAttachmentCMAAINTELResourceManager:: | 21 ApplyFramebufferAttachmentCMAAINTELResourceManager:: |
| 22 ApplyFramebufferAttachmentCMAAINTELResourceManager() | 22 ApplyFramebufferAttachmentCMAAINTELResourceManager() |
| 23 : initialized_(false), | 23 : initialized_(false), |
| 24 textures_initialized_(false), | 24 textures_initialized_(false), |
| 25 is_in_gamma_correct_mode_(false), | 25 is_in_gamma_correct_mode_(false), |
| 26 supports_usampler_(true), | 26 supports_usampler_(true), |
| 27 supports_r8_image_(true), | 27 supports_r8_image_(true), |
| 28 supports_r8_read_format_(true), | |
| 29 is_gles31_compatible_(false), | 28 is_gles31_compatible_(false), |
| 30 frame_id_(0), | 29 frame_id_(0), |
| 31 width_(0), | 30 width_(0), |
| 32 height_(0), | 31 height_(0), |
| 33 edges0_shader_(0), | 32 edges0_shader_(0), |
| 34 edges1_shader_(0), | 33 edges1_shader_(0), |
| 35 edges_combine_shader_(0), | 34 edges_combine_shader_(0), |
| 36 process_and_apply_shader_(0), | 35 process_and_apply_shader_(0), |
| 37 debug_display_edges_shader_(0), | 36 debug_display_edges_shader_(0), |
| 38 cmaa_framebuffer_(0), | 37 cmaa_framebuffer_(0), |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 52 ~ApplyFramebufferAttachmentCMAAINTELResourceManager() { | 51 ~ApplyFramebufferAttachmentCMAAINTELResourceManager() { |
| 53 Destroy(); | 52 Destroy(); |
| 54 } | 53 } |
| 55 | 54 |
| 56 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Initialize( | 55 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Initialize( |
| 57 gles2::GLES2Decoder* decoder) { | 56 gles2::GLES2Decoder* decoder) { |
| 58 DCHECK(decoder); | 57 DCHECK(decoder); |
| 59 is_gles31_compatible_ = | 58 is_gles31_compatible_ = |
| 60 decoder->GetGLContext()->GetVersionInfo()->IsAtLeastGLES(3, 1); | 59 decoder->GetGLContext()->GetVersionInfo()->IsAtLeastGLES(3, 1); |
| 61 | 60 |
| 62 // Check if RGBA8UI is supported as an FBO colour target with depth. | 61 if (is_gles31_compatible_) { |
| 63 // If not supported, GLSL needs to convert the data to/from float so there is | 62 supports_r8_image_ = |
| 64 // a small extra cost. | 63 decoder->GetGLContext()->HasExtension("GL_NV_image_formats"); |
| 65 { | |
| 66 GLuint rgba8ui_texture = 0, depth_texture = 0; | |
| 67 glGenTextures(1, &rgba8ui_texture); | |
| 68 glBindTexture(GL_TEXTURE_2D, rgba8ui_texture); | |
| 69 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8UI, 4, 4); | |
| 70 | 64 |
| 71 glGenTextures(1, &depth_texture); | 65 // ES 3.0 requires GL_RGBA8UI is color renderable. |
| 72 glBindTexture(GL_TEXTURE_2D, depth_texture); | 66 supports_usampler_ = true; |
| 73 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT16, 4, 4); | 67 } else { |
| 68 // CMAA requires GL_ARB_shader_image_load_store for GL, and it requires r8 | |
| 69 // image texture. | |
| 70 DCHECK(decoder->GetGLContext()->HasExtension( | |
|
Zhenyao Mo
2017/03/01 23:52:33
Is it validated somewhere before this that it's ei
dshwang
2017/03/02 20:27:03
yes, here https://cs.chromium.org/chromium/src/gpu
| |
| 71 "GL_ARB_shader_image_load_store")); | |
| 72 supports_r8_image_ = true; | |
| 74 | 73 |
| 75 // Create the FBO | 74 // Check if RGBA8UI is supported as an FBO colour target with depth. |
| 76 GLuint rgba8ui_framebuffer = 0; | 75 // If not supported, GLSL needs to convert the data to/from float so there |
| 77 glGenFramebuffersEXT(1, &rgba8ui_framebuffer); | 76 // is a small extra cost. |
| 78 glBindFramebufferEXT(GL_FRAMEBUFFER, rgba8ui_framebuffer); | 77 { |
| 78 GLuint rgba8ui_texture = 0, depth_texture = 0; | |
| 79 glGenTextures(1, &rgba8ui_texture); | |
| 80 glBindTexture(GL_TEXTURE_2D, rgba8ui_texture); | |
|
Zhenyao Mo
2017/03/01 23:52:33
A question: although not new to this CL, but here
dshwang
2017/03/02 20:27:03
below code anyway bind texture/fbo, so not necessa
Zhenyao Mo
2017/03/06 03:36:54
What I mean is the bindings before entering this c
dshwang
2017/03/07 02:44:09
Before leaving CMAA code, CMAA always restore text
| |
| 81 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8UI, 4, 4); | |
|
Zhenyao Mo
2017/03/01 23:52:33
tex storage isn't part of core 4.1 or lower. I th
dshwang
2017/03/02 20:27:03
Good point! The implementation uses glTexStorage2D
| |
| 79 | 82 |
| 80 // Bind to the FBO to test support | 83 glGenTextures(1, &depth_texture); |
| 81 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 84 glBindTexture(GL_TEXTURE_2D, depth_texture); |
| 82 GL_TEXTURE_2D, rgba8ui_texture, 0); | 85 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT16, 4, 4); |
| 83 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, | |
| 84 GL_TEXTURE_2D, depth_texture, 0); | |
| 85 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); | |
| 86 | 86 |
| 87 supports_usampler_ = (status == GL_FRAMEBUFFER_COMPLETE); | 87 // Create the FBO |
| 88 GLuint rgba8ui_framebuffer = 0; | |
| 89 glGenFramebuffersEXT(1, &rgba8ui_framebuffer); | |
| 90 glBindFramebufferEXT(GL_FRAMEBUFFER, rgba8ui_framebuffer); | |
| 88 | 91 |
| 89 glDeleteFramebuffersEXT(1, &rgba8ui_framebuffer); | 92 // Bind to the FBO to test support |
| 90 glDeleteTextures(1, &rgba8ui_texture); | 93 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 91 glDeleteTextures(1, &depth_texture); | 94 GL_TEXTURE_2D, rgba8ui_texture, 0); |
| 92 } | 95 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, |
| 96 GL_TEXTURE_2D, depth_texture, 0); | |
| 97 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); | |
| 93 | 98 |
| 94 // Check to see if R8 images are supported | 99 supports_usampler_ = (status == GL_FRAMEBUFFER_COMPLETE); |
| 95 // If not supported, images are bound as R32F for write targets, not R8. | |
| 96 { | |
| 97 GLuint r8_texture = 0; | |
| 98 glGenTextures(1, &r8_texture); | |
| 99 glBindTexture(GL_TEXTURE_2D, r8_texture); | |
| 100 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_R8, 4, 4); | |
| 101 | 100 |
| 102 glGetError(); // reset all previous errors | 101 glDeleteFramebuffersEXT(1, &rgba8ui_framebuffer); |
| 103 glBindImageTextureEXT(0, r8_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R8); | 102 glDeleteTextures(1, &rgba8ui_texture); |
| 104 if (glGetError() != GL_NO_ERROR) | 103 glDeleteTextures(1, &depth_texture); |
| 105 supports_r8_image_ = false; | |
| 106 | |
| 107 glDeleteTextures(1, &r8_texture); | |
| 108 } | |
| 109 | |
| 110 // Check if R8 GLSL read formats are supported. | |
| 111 // If not supported, r32f is used instead. | |
| 112 { | |
| 113 const char shader_source[] = | |
| 114 SHADER(layout(r8) restrict writeonly uniform highp image2D g_r8Image; | |
| 115 void main() { | |
| 116 imageStore(g_r8Image, ivec2(0, 0), vec4(1.0, 0.0, 0.0, 0.0)); | |
| 117 }); | |
| 118 | |
| 119 GLuint shader = CreateShader(GL_FRAGMENT_SHADER, "", shader_source); | |
| 120 supports_r8_read_format_ = (shader != 0); | |
| 121 if (shader != 0) { | |
| 122 glDeleteShader(shader); | |
| 123 } | 104 } |
| 124 } | 105 } |
| 125 | 106 |
| 126 VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: " | 107 VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: " |
| 127 << "Supports USampler is " << (supports_usampler_ ? "true" : "false"); | 108 << "Supports USampler is " << (supports_usampler_ ? "true" : "false"); |
| 128 VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: " | 109 VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: " |
| 129 << "Supports R8 Images is " | 110 << "Supports R8 Images is " |
| 130 << (supports_r8_image_ ? "true" : "false"); | 111 << (supports_r8_image_ ? "true" : "false"); |
| 131 VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: " | |
| 132 << "Supports R8 Read Format is " | |
| 133 << (supports_r8_read_format_ ? "true" : "false"); | |
| 134 | 112 |
| 135 // Create the shaders | 113 // Create the shaders |
| 136 std::ostringstream defines, edge1, edge2, combineEdges, blur, displayEdges, | 114 std::ostringstream defines, edge1, edge2, combineEdges, blur, displayEdges, |
| 137 cmaa_frag; | 115 cmaa_frag; |
| 138 | 116 |
| 139 cmaa_frag << cmaa_frag_s1_ << cmaa_frag_s2_; | 117 cmaa_frag << cmaa_frag_s1_ << cmaa_frag_s2_; |
| 140 std::string cmaa_frag_string = cmaa_frag.str(); | 118 std::string cmaa_frag_string = cmaa_frag.str(); |
| 141 const char* cmaa_frag_c_str = cmaa_frag_string.c_str(); | 119 const char* cmaa_frag_c_str = cmaa_frag_string.c_str(); |
| 142 | 120 |
| 143 if (supports_usampler_) { | 121 if (supports_usampler_) { |
| 144 defines << "#define SUPPORTS_USAMPLER2D\n"; | 122 defines << "#define SUPPORTS_USAMPLER2D\n"; |
| 145 } | 123 } |
| 146 | 124 |
| 147 if (is_in_gamma_correct_mode_) { | 125 if (is_in_gamma_correct_mode_) { |
| 148 defines << "#define IN_GAMMA_CORRECT_MODE\n"; | 126 defines << "#define IN_GAMMA_CORRECT_MODE\n"; |
| 149 } | 127 } |
| 150 | 128 |
| 151 if (supports_r8_read_format_) { | 129 if (supports_r8_image_) { |
| 152 defines << "#define EDGE_READ_FORMAT r8\n"; | 130 defines << "#define EDGE_READ_FORMAT r8\n"; |
| 153 } else { | 131 } else { |
| 154 defines << "#define EDGE_READ_FORMAT r32f\n"; | 132 defines << "#define EDGE_READ_FORMAT r32f\n"; |
| 155 } | 133 } |
| 156 | 134 |
| 157 displayEdges << defines.str() << "#define DISPLAY_EDGES\n"; | 135 displayEdges << defines.str() << "#define DISPLAY_EDGES\n"; |
| 158 debug_display_edges_shader_ = | 136 debug_display_edges_shader_ = |
| 159 CreateProgram(displayEdges.str().c_str(), vert_str_, cmaa_frag_c_str); | 137 CreateProgram(displayEdges.str().c_str(), vert_str_, cmaa_frag_c_str); |
| 160 | 138 |
| 161 edge1 << defines.str() << "#define DETECT_EDGES1\n"; | 139 edge1 << defines.str() << "#define DETECT_EDGES1\n"; |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 } | 568 } |
| 591 | 569 |
| 592 GLuint ApplyFramebufferAttachmentCMAAINTELResourceManager::CreateShader( | 570 GLuint ApplyFramebufferAttachmentCMAAINTELResourceManager::CreateShader( |
| 593 GLenum type, | 571 GLenum type, |
| 594 const char* defines, | 572 const char* defines, |
| 595 const char* source) { | 573 const char* source) { |
| 596 GLuint shader = glCreateShader(type); | 574 GLuint shader = glCreateShader(type); |
| 597 | 575 |
| 598 const char header_es31[] = | 576 const char header_es31[] = |
| 599 "#version 310 es \n"; | 577 "#version 310 es \n"; |
| 600 const char header_gl30[] = | 578 const char header_gl30[] = |
|
Zhenyao Mo
2017/03/01 23:52:33
shouldn't this name be gl130 instead?
dshwang
2017/03/02 20:27:03
Done.
| |
| 601 "#version 130 \n" | 579 "#version 130 \n" |
| 602 "#extension GL_ARB_shading_language_420pack : require \n" | 580 "#extension GL_ARB_shading_language_420pack : require \n" |
| 603 "#extension GL_ARB_texture_gather : require \n" | 581 "#extension GL_ARB_texture_gather : require \n" |
| 604 "#extension GL_ARB_explicit_uniform_location : require \n" | 582 "#extension GL_ARB_explicit_uniform_location : require \n" |
| 605 "#extension GL_ARB_explicit_attrib_location : require \n" | 583 "#extension GL_ARB_explicit_attrib_location : require \n" |
| 606 "#extension GL_ARB_shader_image_load_store : require \n"; | 584 "#extension GL_ARB_shader_image_load_store : require \n"; |
| 607 | 585 |
| 608 const char* header = NULL; | 586 std::ostringstream header; |
| 609 if (is_gles31_compatible_) { | 587 if (is_gles31_compatible_) { |
| 610 header = header_es31; | 588 header << header_es31; |
| 589 if (supports_r8_image_) | |
| 590 header << "#extension GL_NV_image_formats : require\n"; | |
| 611 } else { | 591 } else { |
| 612 header = header_gl30; | 592 header << header_gl30; |
| 613 } | 593 } |
| 614 | 594 |
| 615 const char* source_array[4] = {header, defines, "\n", source}; | 595 const char* source_array[4] = {header.str().c_str(), defines, "\n", source}; |
| 616 glShaderSource(shader, 4, source_array, NULL); | 596 glShaderSource(shader, 4, source_array, NULL); |
| 617 | 597 |
| 618 glCompileShader(shader); | 598 glCompileShader(shader); |
| 619 | 599 |
| 620 GLint compile_result; | 600 GLint compile_result; |
| 621 glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_result); | 601 glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_result); |
| 622 if (compile_result == 0) { | 602 if (compile_result == 0) { |
| 623 #if DCHECK_IS_ON() | 603 #if DCHECK_IS_ON() |
| 624 GLint info_log_length; | 604 GLint info_log_length; |
| 625 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_length); | 605 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_length); |
| (...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1850 \n#endif\n | 1830 \n#endif\n |
| 1851 \n#if defined DISPLAY_EDGES\n | 1831 \n#if defined DISPLAY_EDGES\n |
| 1852 DisplayEdges(); | 1832 DisplayEdges(); |
| 1853 \n#endif\n | 1833 \n#endif\n |
| 1854 } | 1834 } |
| 1855 ); | 1835 ); |
| 1856 /* clang-format on */ | 1836 /* clang-format on */ |
| 1857 | 1837 |
| 1858 } // namespace gles2 | 1838 } // namespace gles2 |
| 1859 } // namespace gpu | 1839 } // namespace gpu |
| OLD | NEW |