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( | |
| 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 glActiveTexture(GL_TEXTURE0); | |
| 79 | 79 |
| 80 // Bind to the FBO to test support | 80 GLuint rgba8ui_texture = 0, depth_texture = 0; |
| 81 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 81 glGenTextures(1, &rgba8ui_texture); |
| 82 GL_TEXTURE_2D, rgba8ui_texture, 0); | 82 glBindTexture(GL_TEXTURE_2D, rgba8ui_texture); |
| 83 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, | 83 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8UI, 4, 4); |
| 84 GL_TEXTURE_2D, depth_texture, 0); | |
| 85 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); | |
| 86 | 84 |
| 87 supports_usampler_ = (status == GL_FRAMEBUFFER_COMPLETE); | 85 glGenTextures(1, &depth_texture); |
| 86 glBindTexture(GL_TEXTURE_2D, depth_texture); | |
| 87 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT16, 4, 4); | |
| 88 | 88 |
| 89 glDeleteFramebuffersEXT(1, &rgba8ui_framebuffer); | 89 // Create the FBO |
| 90 glDeleteTextures(1, &rgba8ui_texture); | 90 GLuint rgba8ui_framebuffer = 0; |
| 91 glDeleteTextures(1, &depth_texture); | 91 glGenFramebuffersEXT(1, &rgba8ui_framebuffer); |
| 92 } | 92 glBindFramebufferEXT(GL_FRAMEBUFFER, rgba8ui_framebuffer); |
| 93 | 93 |
| 94 // Check to see if R8 images are supported | 94 // Bind to the FBO to test support |
| 95 // If not supported, images are bound as R32F for write targets, not R8. | 95 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 96 { | 96 GL_TEXTURE_2D, rgba8ui_texture, 0); |
| 97 GLuint r8_texture = 0; | 97 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, |
| 98 glGenTextures(1, &r8_texture); | 98 GL_TEXTURE_2D, depth_texture, 0); |
| 99 glBindTexture(GL_TEXTURE_2D, r8_texture); | 99 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
| 100 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_R8, 4, 4); | |
| 101 | 100 |
| 102 glGetError(); // reset all previous errors | 101 supports_usampler_ = (status == GL_FRAMEBUFFER_COMPLETE); |
| 103 glBindImageTextureEXT(0, r8_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R8); | |
| 104 if (glGetError() != GL_NO_ERROR) | |
| 105 supports_r8_image_ = false; | |
| 106 | 102 |
| 107 glDeleteTextures(1, &r8_texture); | 103 glDeleteFramebuffersEXT(1, &rgba8ui_framebuffer); |
| 108 } | 104 glDeleteTextures(1, &rgba8ui_texture); |
| 105 glDeleteTextures(1, &depth_texture); | |
| 109 | 106 |
| 110 // Check if R8 GLSL read formats are supported. | 107 decoder->RestoreTextureUnitBindings(0); |
| 111 // If not supported, r32f is used instead. | 108 decoder->RestoreActiveTexture(); |
| 112 { | 109 decoder->RestoreFramebufferBindings(); |
| 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 } | 110 } |
| 124 } | 111 } |
| 125 | 112 |
| 126 VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: " | 113 VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: " |
| 127 << "Supports USampler is " << (supports_usampler_ ? "true" : "false"); | 114 << "Supports USampler is " << (supports_usampler_ ? "true" : "false"); |
| 128 VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: " | 115 VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: " |
| 129 << "Supports R8 Images is " | 116 << "Supports R8 Images is " |
| 130 << (supports_r8_image_ ? "true" : "false"); | 117 << (supports_r8_image_ ? "true" : "false"); |
| 131 VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: " | |
| 132 << "Supports R8 Read Format is " | |
| 133 << (supports_r8_read_format_ ? "true" : "false"); | |
| 134 | 118 |
| 135 // Create the shaders | 119 // Create the shaders |
| 136 std::ostringstream defines, edge1, edge2, combineEdges, blur, displayEdges, | 120 std::ostringstream defines, edge1, edge2, combineEdges, blur, displayEdges, |
| 137 cmaa_frag; | 121 cmaa_frag; |
| 138 | 122 |
| 139 cmaa_frag << cmaa_frag_s1_ << cmaa_frag_s2_; | 123 cmaa_frag << cmaa_frag_s1_ << cmaa_frag_s2_; |
| 140 std::string cmaa_frag_string = cmaa_frag.str(); | 124 std::string cmaa_frag_string = cmaa_frag.str(); |
| 141 const char* cmaa_frag_c_str = cmaa_frag_string.c_str(); | 125 const char* cmaa_frag_c_str = cmaa_frag_string.c_str(); |
| 142 | 126 |
| 143 if (supports_usampler_) { | 127 if (supports_usampler_) { |
| 144 defines << "#define SUPPORTS_USAMPLER2D\n"; | 128 defines << "#define SUPPORTS_USAMPLER2D\n"; |
| 145 } | 129 } |
| 146 | 130 |
| 147 if (is_in_gamma_correct_mode_) { | 131 if (is_in_gamma_correct_mode_) { |
| 148 defines << "#define IN_GAMMA_CORRECT_MODE\n"; | 132 defines << "#define IN_GAMMA_CORRECT_MODE\n"; |
| 149 } | 133 } |
| 150 | 134 |
| 151 if (supports_r8_read_format_) { | 135 if (supports_r8_image_) { |
| 152 defines << "#define EDGE_READ_FORMAT r8\n"; | 136 defines << "#define EDGE_READ_FORMAT r8\n"; |
| 153 } else { | 137 } else { |
| 154 defines << "#define EDGE_READ_FORMAT r32f\n"; | 138 defines << "#define EDGE_READ_FORMAT r32f\n"; |
| 155 } | 139 } |
| 156 | 140 |
| 157 displayEdges << defines.str() << "#define DISPLAY_EDGES\n"; | 141 displayEdges << defines.str() << "#define DISPLAY_EDGES\n"; |
| 158 debug_display_edges_shader_ = | 142 debug_display_edges_shader_ = |
| 159 CreateProgram(displayEdges.str().c_str(), vert_str_, cmaa_frag_c_str); | 143 CreateProgram(displayEdges.str().c_str(), vert_str_, cmaa_frag_c_str); |
| 160 | 144 |
| 161 edge1 << defines.str() << "#define DETECT_EDGES1\n"; | 145 edge1 << defines.str() << "#define DETECT_EDGES1\n"; |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 } | 606 } |
| 623 | 607 |
| 624 GLuint ApplyFramebufferAttachmentCMAAINTELResourceManager::CreateShader( | 608 GLuint ApplyFramebufferAttachmentCMAAINTELResourceManager::CreateShader( |
| 625 GLenum type, | 609 GLenum type, |
| 626 const char* defines, | 610 const char* defines, |
| 627 const char* source) { | 611 const char* source) { |
| 628 GLuint shader = glCreateShader(type); | 612 GLuint shader = glCreateShader(type); |
| 629 | 613 |
| 630 const char header_es31[] = | 614 const char header_es31[] = |
| 631 "#version 310 es \n"; | 615 "#version 310 es \n"; |
| 632 const char header_gl30[] = | 616 const char header_gl130[] = |
| 633 "#version 130 \n" | 617 "#version 130 \n" |
| 634 "#extension GL_ARB_shading_language_420pack : require \n" | 618 "#extension GL_ARB_shading_language_420pack : require \n" |
| 635 "#extension GL_ARB_texture_gather : require \n" | 619 "#extension GL_ARB_texture_gather : require \n" |
| 636 "#extension GL_ARB_explicit_uniform_location : require \n" | 620 "#extension GL_ARB_explicit_uniform_location : require \n" |
| 637 "#extension GL_ARB_explicit_attrib_location : require \n" | 621 "#extension GL_ARB_explicit_attrib_location : require \n" |
| 638 "#extension GL_ARB_shader_image_load_store : require \n"; | 622 "#extension GL_ARB_shader_image_load_store : require \n"; |
| 639 | 623 |
| 640 const char* header = NULL; | 624 std::ostringstream header; |
| 641 if (is_gles31_compatible_) { | 625 if (is_gles31_compatible_) { |
| 642 header = header_es31; | 626 header << header_es31; |
| 627 if (supports_r8_image_) | |
| 628 header << "#extension GL_NV_image_formats : require\n"; | |
| 643 } else { | 629 } else { |
| 644 header = header_gl30; | 630 header << header_gl130; |
| 645 } | 631 } |
| 646 | 632 |
| 647 const char* source_array[4] = {header, defines, "\n", source}; | 633 const char* source_array[4] = {header.str().c_str(), defines, "\n", source}; |
|
dshwang
2017/03/15 22:05:38
It's my mistake. std::ostringstream doesn't have a
| |
| 648 glShaderSource(shader, 4, source_array, NULL); | 634 glShaderSource(shader, 4, source_array, NULL); |
| 649 | 635 |
| 650 glCompileShader(shader); | 636 glCompileShader(shader); |
| 651 | 637 |
| 652 GLint compile_result; | 638 GLint compile_result; |
| 653 glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_result); | 639 glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_result); |
| 654 if (compile_result == 0) { | 640 if (compile_result == 0) { |
| 655 #if DCHECK_IS_ON() | 641 #if DCHECK_IS_ON() |
| 656 GLint info_log_length; | 642 GLint info_log_length; |
| 657 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_length); | 643 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_length); |
| (...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1882 \n#endif\n | 1868 \n#endif\n |
| 1883 \n#if defined DISPLAY_EDGES\n | 1869 \n#if defined DISPLAY_EDGES\n |
| 1884 DisplayEdges(); | 1870 DisplayEdges(); |
| 1885 \n#endif\n | 1871 \n#endif\n |
| 1886 } | 1872 } |
| 1887 ); | 1873 ); |
| 1888 /* clang-format on */ | 1874 /* clang-format on */ |
| 1889 | 1875 |
| 1890 } // namespace gles2 | 1876 } // namespace gles2 |
| 1891 } // namespace gpu | 1877 } // namespace gpu |
| OLD | NEW |