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

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

Issue 2298613010: gpu, cmaa: copy RGBA8 texture via glCopyTexSubImage2D() instead of imageStore(). (Closed)
Patch Set: remove imageStore() path Created 4 years, 3 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
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_apply_framebuffer_attachment_cmaa_intel.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_decoder.h" 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
10 #include "ui/gl/gl_context.h" 10 #include "ui/gl/gl_context.h"
(...skipping 11 matching lines...) Expand all
22 textures_initialized_(false), 22 textures_initialized_(false),
23 is_in_gamma_correct_mode_(false), 23 is_in_gamma_correct_mode_(false),
24 supports_usampler_(true), 24 supports_usampler_(true),
25 supports_r8_image_(true), 25 supports_r8_image_(true),
26 supports_r8_read_format_(true), 26 supports_r8_read_format_(true),
27 is_gles31_compatible_(false), 27 is_gles31_compatible_(false),
28 frame_id_(0), 28 frame_id_(0),
29 width_(0), 29 width_(0),
30 height_(0), 30 height_(0),
31 copy_to_framebuffer_shader_(0), 31 copy_to_framebuffer_shader_(0),
32 copy_to_image_shader_(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),
39 copy_framebuffer_(0), 38 copy_framebuffer_(0),
40 rgba8_texture_(0), 39 rgba8_texture_(0),
41 working_color_texture_(0), 40 working_color_texture_(0),
42 edges0_texture_(0), 41 edges0_texture_(0),
43 edges1_texture_(0), 42 edges1_texture_(0),
44 mini4_edge_texture_(0), 43 mini4_edge_texture_(0),
45 mini4_edge_depth_texture_(0), 44 mini4_edge_depth_texture_(0),
46 edges1_shader_result_texture_float4_slot1_(0), 45 edges1_shader_result_texture_float4_slot1_(0),
47 edges1_shader_result_texture_(0), 46 edges1_shader_result_texture_(0),
48 edges_combine_shader_result_texture_float4_slot1_(0), 47 edges_combine_shader_result_texture_float4_slot1_(0),
49 process_and_apply_shader_result_texture_float4_slot1_(0), 48 process_and_apply_shader_result_texture_float4_slot1_(0),
50 edges_combine_shader_result_texture_slot2_(0), 49 edges_combine_shader_result_texture_slot2_(0) {}
51 copy_to_image_shader_outTexture_(0) {}
52 50
53 ApplyFramebufferAttachmentCMAAINTELResourceManager:: 51 ApplyFramebufferAttachmentCMAAINTELResourceManager::
54 ~ApplyFramebufferAttachmentCMAAINTELResourceManager() { 52 ~ApplyFramebufferAttachmentCMAAINTELResourceManager() {
55 Destroy(); 53 Destroy();
56 } 54 }
57 55
58 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Initialize( 56 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Initialize(
59 gles2::GLES2Decoder* decoder) { 57 gles2::GLES2Decoder* decoder) {
60 DCHECK(decoder); 58 DCHECK(decoder);
61 is_gles31_compatible_ = 59 is_gles31_compatible_ =
62 decoder->GetGLContext()->GetVersionInfo()->IsAtLeastGLES(3, 1); 60 decoder->GetGLContext()->GetVersionInfo()->IsAtLeastGLES(3, 1);
63 61
64 copy_to_image_shader_ = CreateProgram("", vert_str_, copy_frag_str_); 62 copy_to_framebuffer_shader_ = CreateProgram("", vert_str_, copy_frag_str_);
65 copy_to_framebuffer_shader_ =
66 CreateProgram("#define OUT_FBO 1\n", vert_str_, copy_frag_str_);
67 63
68 // Check if RGBA8UI is supported as an FBO colour target with depth. 64 // Check if RGBA8UI is supported as an FBO colour target with depth.
69 // If not supported, GLSL needs to convert the data to/from float so there is 65 // If not supported, GLSL needs to convert the data to/from float so there is
70 // a small extra cost. 66 // a small extra cost.
71 { 67 {
72 GLuint rgba8ui_texture = 0, depth_texture = 0; 68 GLuint rgba8ui_texture = 0, depth_texture = 0;
73 glGenTextures(1, &rgba8ui_texture); 69 glGenTextures(1, &rgba8ui_texture);
74 glBindTexture(GL_TEXTURE_2D, rgba8ui_texture); 70 glBindTexture(GL_TEXTURE_2D, rgba8ui_texture);
75 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8UI, 4, 4); 71 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8UI, 4, 4);
76 72
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 edges1_shader_result_texture_float4_slot1_ = 179 edges1_shader_result_texture_float4_slot1_ =
184 glGetUniformLocation(edges0_shader_, "g_resultTextureFlt4Slot1"); 180 glGetUniformLocation(edges0_shader_, "g_resultTextureFlt4Slot1");
185 edges1_shader_result_texture_ = 181 edges1_shader_result_texture_ =
186 glGetUniformLocation(edges1_shader_, "g_resultTexture"); 182 glGetUniformLocation(edges1_shader_, "g_resultTexture");
187 edges_combine_shader_result_texture_float4_slot1_ = 183 edges_combine_shader_result_texture_float4_slot1_ =
188 glGetUniformLocation(edges_combine_shader_, "g_resultTextureFlt4Slot1"); 184 glGetUniformLocation(edges_combine_shader_, "g_resultTextureFlt4Slot1");
189 edges_combine_shader_result_texture_slot2_ = 185 edges_combine_shader_result_texture_slot2_ =
190 glGetUniformLocation(edges_combine_shader_, "g_resultTextureSlot2"); 186 glGetUniformLocation(edges_combine_shader_, "g_resultTextureSlot2");
191 process_and_apply_shader_result_texture_float4_slot1_ = glGetUniformLocation( 187 process_and_apply_shader_result_texture_float4_slot1_ = glGetUniformLocation(
192 process_and_apply_shader_, "g_resultTextureFlt4Slot1"); 188 process_and_apply_shader_, "g_resultTextureFlt4Slot1");
193 copy_to_image_shader_outTexture_ =
194 glGetUniformLocation(copy_to_image_shader_, "outTexture");
195 189
196 initialized_ = true; 190 initialized_ = true;
197 } 191 }
198 192
199 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Destroy() { 193 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Destroy() {
200 if (!initialized_) 194 if (!initialized_)
201 return; 195 return;
202 196
203 ReleaseTextures(); 197 ReleaseTextures();
204 198
205 glDeleteProgram(copy_to_image_shader_);
206 glDeleteProgram(copy_to_framebuffer_shader_); 199 glDeleteProgram(copy_to_framebuffer_shader_);
207 glDeleteProgram(process_and_apply_shader_); 200 glDeleteProgram(process_and_apply_shader_);
208 glDeleteProgram(edges_combine_shader_); 201 glDeleteProgram(edges_combine_shader_);
209 glDeleteProgram(edges1_shader_); 202 glDeleteProgram(edges1_shader_);
210 glDeleteProgram(edges0_shader_); 203 glDeleteProgram(edges0_shader_);
211 glDeleteProgram(debug_display_edges_shader_); 204 glDeleteProgram(debug_display_edges_shader_);
212 205
213 initialized_ = false; 206 initialized_ = false;
214 } 207 }
215 208
216 // Apply CMAA(Conservative Morphological Anti-Aliasing) algorithm to the 209 // Apply CMAA(Conservative Morphological Anti-Aliasing) algorithm to the
217 // color attachments of currently bound draw framebuffer. 210 // color attachments of currently bound draw framebuffer.
218 // Reference GL_INTEL_framebuffer_CMAA for details. 211 // Reference GL_INTEL_framebuffer_CMAA for details.
219 void ApplyFramebufferAttachmentCMAAINTELResourceManager:: 212 void ApplyFramebufferAttachmentCMAAINTELResourceManager::
220 ApplyFramebufferAttachmentCMAAINTEL(gles2::GLES2Decoder* decoder, 213 ApplyFramebufferAttachmentCMAAINTEL(gles2::GLES2Decoder* decoder,
221 gles2::Framebuffer* framebuffer) { 214 gles2::Framebuffer* framebuffer) {
222 DCHECK(decoder); 215 DCHECK(decoder);
223 DCHECK(initialized_); 216 DCHECK(initialized_);
224 if (!framebuffer) 217 if (!framebuffer)
225 return; 218 return;
226 219
220 glDisable(GL_SCISSOR_TEST);
221 glDisable(GL_STENCIL_TEST);
222 glDisable(GL_CULL_FACE);
223 glDisable(GL_BLEND);
dshwang 2016/09/02 15:00:21 These was in CopyTexture(), but ApplyCMAAEffectTex
224
227 GLuint last_framebuffer = framebuffer->service_id(); 225 GLuint last_framebuffer = framebuffer->service_id();
228 226
229 // Process each color attachment of the current draw framebuffer. 227 // Process each color attachment of the current draw framebuffer.
230 uint32_t max_draw_buffers = decoder->GetContextGroup()->max_draw_buffers(); 228 uint32_t max_draw_buffers = decoder->GetContextGroup()->max_draw_buffers();
231 for (uint32_t i = 0; i < max_draw_buffers; i++) { 229 for (uint32_t i = 0; i < max_draw_buffers; i++) {
232 const gles2::Framebuffer::Attachment* attachment = 230 const gles2::Framebuffer::Attachment* attachment =
233 framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0 + i); 231 framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0 + i);
234 if (attachment && attachment->IsTextureAttachment()) { 232 if (attachment && attachment->IsTextureAttachment()) {
235 // Get the texture info. 233 // Get the texture info.
236 GLuint source_texture_client_id = attachment->object_name(); 234 GLuint source_texture_client_id = attachment->object_name();
237 GLuint source_texture = 0; 235 GLuint source_texture = 0;
238 if (!decoder->GetServiceTextureId(source_texture_client_id, 236 if (!decoder->GetServiceTextureId(source_texture_client_id,
239 &source_texture)) 237 &source_texture))
240 continue; 238 continue;
241 GLsizei width = attachment->width(); 239 GLsizei width = attachment->width();
242 GLsizei height = attachment->height(); 240 GLsizei height = attachment->height();
243 GLenum internal_format = attachment->internal_format(); 241 GLenum internal_format = attachment->internal_format();
244 242
245 // Resize internal structures - only if needed. 243 // Resize internal structures - only if needed.
246 OnSize(width, height); 244 OnSize(width, height);
247 245
248 // CMAA internally expects GL_RGBA8 textures. 246 // CMAA internally expects GL_RGBA8 textures.
249 // Process using a GL_RGBA8 copy if this is not the case. 247 // Process using a GL_RGBA8 copy if this is not the case.
250 bool do_copy = internal_format != GL_RGBA8; 248 bool do_copy = internal_format != GL_RGBA8;
251 249
252 // Copy source_texture to rgba8_texture_ 250 // Copy source_texture to rgba8_texture_
253 if (do_copy) { 251 if (do_copy) {
254 CopyTexture(source_texture, rgba8_texture_, false); 252 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_);
253 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
254 GL_TEXTURE_2D, rgba8_texture_, 0);
255 CopyTexture(source_texture);
255 } 256 }
256 257
257 // CMAA Effect 258 // CMAA Effect
258 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, last_framebuffer);
259 if (do_copy) { 259 if (do_copy) {
260 ApplyCMAAEffectTexture(rgba8_texture_, rgba8_texture_); 260 ApplyCMAAEffectTexture(rgba8_texture_, rgba8_texture_);
261 } else { 261 } else {
262 ApplyCMAAEffectTexture(source_texture, source_texture); 262 ApplyCMAAEffectTexture(source_texture, source_texture);
263 } 263 }
264 264
265 // Copy rgba8_texture_ to source_texture 265 // Copy rgba8_texture_ to source_texture
266 if (do_copy) { 266 if (do_copy) {
267 // Move source_texture to the first color attachment of the copy fbo. 267 // Move source_texture to the first color attachment of the copy fbo.
268 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, last_framebuffer); 268 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, last_framebuffer);
269 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, 269 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
270 GL_TEXTURE_2D, 0, 0); 270 GL_TEXTURE_2D, 0, 0);
271 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_); 271 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_);
272 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 272 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
273 GL_TEXTURE_2D, source_texture, 0); 273 GL_TEXTURE_2D, source_texture, 0);
274 274
275 CopyTexture(rgba8_texture_, source_texture, true); 275 CopyTexture(rgba8_texture_);
276 276
277 // Restore color attachments 277 // Restore color attachments
278 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_); 278 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_);
279 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 279 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
280 GL_TEXTURE_2D, rgba8_texture_, 0); 280 GL_TEXTURE_2D, rgba8_texture_, 0);
281 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, last_framebuffer); 281 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, last_framebuffer);
282 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, 282 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
283 GL_TEXTURE_2D, source_texture, 0); 283 GL_TEXTURE_2D, source_texture, 0);
284 } 284 }
285 } 285 }
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 glDeleteTextures(1, &edges0_texture_); 558 glDeleteTextures(1, &edges0_texture_);
559 glDeleteTextures(1, &edges1_texture_); 559 glDeleteTextures(1, &edges1_texture_);
560 glDeleteTextures(1, &mini4_edge_texture_); 560 glDeleteTextures(1, &mini4_edge_texture_);
561 glDeleteTextures(1, &mini4_edge_depth_texture_); 561 glDeleteTextures(1, &mini4_edge_depth_texture_);
562 glDeleteTextures(1, &working_color_texture_); 562 glDeleteTextures(1, &working_color_texture_);
563 } 563 }
564 textures_initialized_ = false; 564 textures_initialized_ = false;
565 } 565 }
566 566
567 void ApplyFramebufferAttachmentCMAAINTELResourceManager::CopyTexture( 567 void ApplyFramebufferAttachmentCMAAINTELResourceManager::CopyTexture(
568 GLint source, 568 GLint source) {
569 GLint dest,
570 bool via_fbo) {
571 glViewport(0, 0, width_, height_); 569 glViewport(0, 0, width_, height_);
572 glActiveTexture(GL_TEXTURE0); 570 glActiveTexture(GL_TEXTURE0);
573 glBindTexture(GL_TEXTURE_2D, source); 571 glBindTexture(GL_TEXTURE_2D, source);
574 572
575 if (!via_fbo) { 573 glDisable(GL_DEPTH_TEST);
576 glUseProgram(copy_to_image_shader_); 574 glDepthMask(GL_FALSE);
577 if (!is_gles31_compatible_) { 575 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
578 glUniform1i(copy_to_image_shader_outTexture_, 0); 576 glUseProgram(copy_to_framebuffer_shader_);
579 }
580 glBindImageTextureEXT(0, dest, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
581 } else {
582 glDisable(GL_DEPTH_TEST);
583 glDisable(GL_STENCIL_TEST);
584 glDisable(GL_CULL_FACE);
585 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
586 glDepthMask(GL_FALSE);
587 glDisable(GL_BLEND);
588 glUseProgram(copy_to_framebuffer_shader_);
589 }
590 577
591 glDrawArrays(GL_TRIANGLES, 0, 3); 578 glDrawArrays(GL_TRIANGLES, 0, 3);
592 glUseProgram(0); 579 glUseProgram(0);
593 glBindTexture(GL_TEXTURE_2D, 0); 580 glBindTexture(GL_TEXTURE_2D, 0);
594 } 581 }
595 582
596 GLuint ApplyFramebufferAttachmentCMAAINTELResourceManager::CreateProgram( 583 GLuint ApplyFramebufferAttachmentCMAAINTELResourceManager::CreateProgram(
597 const char* defines, 584 const char* defines,
598 const char* vs_source, 585 const char* vs_source,
599 const char* fs_source) { 586 const char* fs_source) {
(...skipping 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1882 \n#endif\n 1869 \n#endif\n
1883 } 1870 }
1884 ); 1871 );
1885 1872
1886 const char 1873 const char
1887 ApplyFramebufferAttachmentCMAAINTELResourceManager::copy_frag_str_[] = 1874 ApplyFramebufferAttachmentCMAAINTELResourceManager::copy_frag_str_[] =
1888 SHADER( 1875 SHADER(
1889 precision highp float; 1876 precision highp float;
1890 layout(binding = 0) uniform highp sampler2D inTexture; 1877 layout(binding = 0) uniform highp sampler2D inTexture;
1891 layout(location = 0) out vec4 outColor; 1878 layout(location = 0) out vec4 outColor;
1892 \n#ifdef GL_ES\n
1893 layout(binding = 0, rgba8) restrict writeonly uniform highp
1894 image2D outTexture;
1895 \n#else\n
1896 layout(rgba8) restrict writeonly uniform highp image2D outTexture;
1897 \n#endif\n
1898 1879
1899 void main() { 1880 void main() {
1900 ivec2 screenPosI = ivec2( gl_FragCoord.xy ); 1881 ivec2 screenPosI = ivec2( gl_FragCoord.xy );
1901 vec4 pixel = texelFetch(inTexture, screenPosI, 0); 1882 vec4 pixel = texelFetch(inTexture, screenPosI, 0);
1902 \n#ifdef OUT_FBO\n
1903 outColor = pixel; 1883 outColor = pixel;
1904 \n#else\n
1905 imageStore(outTexture, screenPosI, pixel);
dshwang 2016/09/02 15:00:21 simple fix is adding following line here. outCol
1906 \n#endif\n
1907 } 1884 }
1908 ); 1885 );
1909 /* clang-format on */ 1886 /* clang-format on */
1910 1887
1911 } // namespace gles2 1888 } // namespace gles2
1912 } // namespace gpu 1889 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_apply_framebuffer_attachment_cmaa_intel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698