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

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

Issue 2738213003: Revert of cmaa, gpu: use R8 image texture when GL_NV_image_formats is available. (Closed)
Patch Set: Created 3 years, 9 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 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),
28 is_gles31_compatible_(false), 29 is_gles31_compatible_(false),
29 frame_id_(0), 30 frame_id_(0),
30 width_(0), 31 width_(0),
31 height_(0), 32 height_(0),
32 edges0_shader_(0), 33 edges0_shader_(0),
33 edges1_shader_(0), 34 edges1_shader_(0),
34 edges_combine_shader_(0), 35 edges_combine_shader_(0),
35 process_and_apply_shader_(0), 36 process_and_apply_shader_(0),
36 debug_display_edges_shader_(0), 37 debug_display_edges_shader_(0),
37 cmaa_framebuffer_(0), 38 cmaa_framebuffer_(0),
(...skipping 13 matching lines...) Expand all
51 ~ApplyFramebufferAttachmentCMAAINTELResourceManager() { 52 ~ApplyFramebufferAttachmentCMAAINTELResourceManager() {
52 Destroy(); 53 Destroy();
53 } 54 }
54 55
55 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Initialize( 56 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Initialize(
56 gles2::GLES2Decoder* decoder) { 57 gles2::GLES2Decoder* decoder) {
57 DCHECK(decoder); 58 DCHECK(decoder);
58 is_gles31_compatible_ = 59 is_gles31_compatible_ =
59 decoder->GetGLContext()->GetVersionInfo()->IsAtLeastGLES(3, 1); 60 decoder->GetGLContext()->GetVersionInfo()->IsAtLeastGLES(3, 1);
60 61
61 if (is_gles31_compatible_) { 62 // Check if RGBA8UI is supported as an FBO colour target with depth.
62 supports_r8_image_ = 63 // If not supported, GLSL needs to convert the data to/from float so there is
63 decoder->GetGLContext()->HasExtension("GL_NV_image_formats"); 64 // a small extra cost.
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);
64 70
65 // ES 3.0 requires GL_RGBA8UI is color renderable. 71 glGenTextures(1, &depth_texture);
66 supports_usampler_ = true; 72 glBindTexture(GL_TEXTURE_2D, depth_texture);
67 } else { 73 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT16, 4, 4);
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;
73 74
74 // Check if RGBA8UI is supported as an FBO colour target with depth. 75 // Create the FBO
75 // If not supported, GLSL needs to convert the data to/from float so there 76 GLuint rgba8ui_framebuffer = 0;
76 // is a small extra cost. 77 glGenFramebuffersEXT(1, &rgba8ui_framebuffer);
77 { 78 glBindFramebufferEXT(GL_FRAMEBUFFER, rgba8ui_framebuffer);
78 glActiveTexture(GL_TEXTURE0);
79 79
80 GLuint rgba8ui_texture = 0, depth_texture = 0; 80 // Bind to the FBO to test support
81 glGenTextures(1, &rgba8ui_texture); 81 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
82 glBindTexture(GL_TEXTURE_2D, rgba8ui_texture); 82 GL_TEXTURE_2D, rgba8ui_texture, 0);
83 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8UI, 4, 4); 83 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
84 GL_TEXTURE_2D, depth_texture, 0);
85 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
84 86
85 glGenTextures(1, &depth_texture); 87 supports_usampler_ = (status == GL_FRAMEBUFFER_COMPLETE);
86 glBindTexture(GL_TEXTURE_2D, depth_texture);
87 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT16, 4, 4);
88 88
89 // Create the FBO 89 glDeleteFramebuffersEXT(1, &rgba8ui_framebuffer);
90 GLuint rgba8ui_framebuffer = 0; 90 glDeleteTextures(1, &rgba8ui_texture);
91 glGenFramebuffersEXT(1, &rgba8ui_framebuffer); 91 glDeleteTextures(1, &depth_texture);
92 glBindFramebufferEXT(GL_FRAMEBUFFER, rgba8ui_framebuffer); 92 }
93 93
94 // Bind to the FBO to test support 94 // Check to see if R8 images are supported
95 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 95 // If not supported, images are bound as R32F for write targets, not R8.
96 GL_TEXTURE_2D, rgba8ui_texture, 0); 96 {
97 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, 97 GLuint r8_texture = 0;
98 GL_TEXTURE_2D, depth_texture, 0); 98 glGenTextures(1, &r8_texture);
99 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); 99 glBindTexture(GL_TEXTURE_2D, r8_texture);
100 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_R8, 4, 4);
100 101
101 supports_usampler_ = (status == GL_FRAMEBUFFER_COMPLETE); 102 glGetError(); // reset all previous errors
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;
102 106
103 glDeleteFramebuffersEXT(1, &rgba8ui_framebuffer); 107 glDeleteTextures(1, &r8_texture);
104 glDeleteTextures(1, &rgba8ui_texture); 108 }
105 glDeleteTextures(1, &depth_texture);
106 109
107 decoder->RestoreTextureUnitBindings(0); 110 // Check if R8 GLSL read formats are supported.
108 decoder->RestoreActiveTexture(); 111 // If not supported, r32f is used instead.
109 decoder->RestoreFramebufferBindings(); 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);
110 } 123 }
111 } 124 }
112 125
113 VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: " 126 VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: "
114 << "Supports USampler is " << (supports_usampler_ ? "true" : "false"); 127 << "Supports USampler is " << (supports_usampler_ ? "true" : "false");
115 VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: " 128 VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: "
116 << "Supports R8 Images is " 129 << "Supports R8 Images is "
117 << (supports_r8_image_ ? "true" : "false"); 130 << (supports_r8_image_ ? "true" : "false");
131 VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: "
132 << "Supports R8 Read Format is "
133 << (supports_r8_read_format_ ? "true" : "false");
118 134
119 // Create the shaders 135 // Create the shaders
120 std::ostringstream defines, edge1, edge2, combineEdges, blur, displayEdges, 136 std::ostringstream defines, edge1, edge2, combineEdges, blur, displayEdges,
121 cmaa_frag; 137 cmaa_frag;
122 138
123 cmaa_frag << cmaa_frag_s1_ << cmaa_frag_s2_; 139 cmaa_frag << cmaa_frag_s1_ << cmaa_frag_s2_;
124 std::string cmaa_frag_string = cmaa_frag.str(); 140 std::string cmaa_frag_string = cmaa_frag.str();
125 const char* cmaa_frag_c_str = cmaa_frag_string.c_str(); 141 const char* cmaa_frag_c_str = cmaa_frag_string.c_str();
126 142
127 if (supports_usampler_) { 143 if (supports_usampler_) {
128 defines << "#define SUPPORTS_USAMPLER2D\n"; 144 defines << "#define SUPPORTS_USAMPLER2D\n";
129 } 145 }
130 146
131 if (is_in_gamma_correct_mode_) { 147 if (is_in_gamma_correct_mode_) {
132 defines << "#define IN_GAMMA_CORRECT_MODE\n"; 148 defines << "#define IN_GAMMA_CORRECT_MODE\n";
133 } 149 }
134 150
135 if (supports_r8_image_) { 151 if (supports_r8_read_format_) {
136 defines << "#define EDGE_READ_FORMAT r8\n"; 152 defines << "#define EDGE_READ_FORMAT r8\n";
137 } else { 153 } else {
138 defines << "#define EDGE_READ_FORMAT r32f\n"; 154 defines << "#define EDGE_READ_FORMAT r32f\n";
139 } 155 }
140 156
141 displayEdges << defines.str() << "#define DISPLAY_EDGES\n"; 157 displayEdges << defines.str() << "#define DISPLAY_EDGES\n";
142 debug_display_edges_shader_ = 158 debug_display_edges_shader_ =
143 CreateProgram(displayEdges.str().c_str(), vert_str_, cmaa_frag_c_str); 159 CreateProgram(displayEdges.str().c_str(), vert_str_, cmaa_frag_c_str);
144 160
145 edge1 << defines.str() << "#define DETECT_EDGES1\n"; 161 edge1 << defines.str() << "#define DETECT_EDGES1\n";
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 } 622 }
607 623
608 GLuint ApplyFramebufferAttachmentCMAAINTELResourceManager::CreateShader( 624 GLuint ApplyFramebufferAttachmentCMAAINTELResourceManager::CreateShader(
609 GLenum type, 625 GLenum type,
610 const char* defines, 626 const char* defines,
611 const char* source) { 627 const char* source) {
612 GLuint shader = glCreateShader(type); 628 GLuint shader = glCreateShader(type);
613 629
614 const char header_es31[] = 630 const char header_es31[] =
615 "#version 310 es \n"; 631 "#version 310 es \n";
616 const char header_gl130[] = 632 const char header_gl30[] =
617 "#version 130 \n" 633 "#version 130 \n"
618 "#extension GL_ARB_shading_language_420pack : require \n" 634 "#extension GL_ARB_shading_language_420pack : require \n"
619 "#extension GL_ARB_texture_gather : require \n" 635 "#extension GL_ARB_texture_gather : require \n"
620 "#extension GL_ARB_explicit_uniform_location : require \n" 636 "#extension GL_ARB_explicit_uniform_location : require \n"
621 "#extension GL_ARB_explicit_attrib_location : require \n" 637 "#extension GL_ARB_explicit_attrib_location : require \n"
622 "#extension GL_ARB_shader_image_load_store : require \n"; 638 "#extension GL_ARB_shader_image_load_store : require \n";
623 639
624 std::ostringstream header; 640 const char* header = NULL;
625 if (is_gles31_compatible_) { 641 if (is_gles31_compatible_) {
626 header << header_es31; 642 header = header_es31;
627 if (supports_r8_image_)
628 header << "#extension GL_NV_image_formats : require\n";
629 } else { 643 } else {
630 header << header_gl130; 644 header = header_gl30;
631 } 645 }
632 646
633 const char* source_array[4] = {header.str().c_str(), defines, "\n", source}; 647 const char* source_array[4] = {header, defines, "\n", source};
634 glShaderSource(shader, 4, source_array, NULL); 648 glShaderSource(shader, 4, source_array, NULL);
635 649
636 glCompileShader(shader); 650 glCompileShader(shader);
637 651
638 GLint compile_result; 652 GLint compile_result;
639 glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_result); 653 glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_result);
640 if (compile_result == 0) { 654 if (compile_result == 0) {
641 #if DCHECK_IS_ON() 655 #if DCHECK_IS_ON()
642 GLint info_log_length; 656 GLint info_log_length;
643 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_length); 657 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_length);
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 \n#endif\n 1882 \n#endif\n
1869 \n#if defined DISPLAY_EDGES\n 1883 \n#if defined DISPLAY_EDGES\n
1870 DisplayEdges(); 1884 DisplayEdges();
1871 \n#endif\n 1885 \n#endif\n
1872 } 1886 }
1873 ); 1887 );
1874 /* clang-format on */ 1888 /* clang-format on */
1875 1889
1876 } // namespace gles2 1890 } // namespace gles2
1877 } // namespace gpu 1891 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698