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

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

Issue 2125803002: gpu, cmaa: optimize COMBINE_EDGES path to reduce fragment shader tasks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove g_Depth uniform because frag shader controls depth by itself Created 4 years, 5 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 | « no previous file | 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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // Inputs 341 // Inputs
342 // g_screenTexture source_texture tex0 342 // g_screenTexture source_texture tex0
343 // Outputs 343 // Outputs
344 // gl_FragDepth mini4_edge_depth_texture_ fbo.depth 344 // gl_FragDepth mini4_edge_depth_texture_ fbo.depth
345 // out uvec4 outEdges mini4_edge_texture_ fbo.col 345 // out uvec4 outEdges mini4_edge_texture_ fbo.col
346 // image2D g_resultTextureFlt4Slot1 working_color_texture_ image1 346 // image2D g_resultTextureFlt4Slot1 working_color_texture_ image1
347 GLenum edge_format = supports_r8_image_ ? GL_R8 : GL_R32F; 347 GLenum edge_format = supports_r8_image_ ? GL_R8 : GL_R32F;
348 348
349 { 349 {
350 glUseProgram(edges0_shader_); 350 glUseProgram(edges0_shader_);
351 glUniform1f(0, 1.0f); 351 glUniform2f(0, 1.0f / width_, 1.0f / height_);
352 glUniform2f(1, 1.0f / width_, 1.0f / height_);
353 glDepthMask(GL_TRUE); 352 glDepthMask(GL_TRUE);
354 glDepthFunc(GL_ALWAYS); 353 glDepthFunc(GL_ALWAYS);
355 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 354 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
356 355
357 if (!is_gles31_compatible_) { 356 if (!is_gles31_compatible_) {
358 glUniform1i(edges1_shader_result_texture_float4_slot1_, 1); 357 glUniform1i(edges1_shader_result_texture_float4_slot1_, 1);
359 } 358 }
360 glBindImageTextureEXT(1, working_color_texture_, 0, GL_FALSE, 0, 359 glBindImageTextureEXT(1, working_color_texture_, 0, GL_FALSE, 0,
361 GL_WRITE_ONLY, GL_RGBA8); 360 GL_WRITE_ONLY, GL_RGBA8);
362 361
363 glActiveTexture(GL_TEXTURE0); 362 glActiveTexture(GL_TEXTURE0);
364 glBindTexture(GL_TEXTURE_2D, source_texture); 363 glBindTexture(GL_TEXTURE_2D, source_texture);
365 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 364 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
366 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 365 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
367 366
368 glDrawArrays(GL_TRIANGLES, 0, 3); 367 glDrawArrays(GL_TRIANGLES, 0, 3);
369 } 368 }
370 369
371 // Detect edges Pass 1 (finish the previous pass edge processing). 370 // Detect edges Pass 1 (finish the previous pass edge processing).
372 // Do the culling of non-dominant local edges (leave mainly locally dominant 371 // Do the culling of non-dominant local edges (leave mainly locally dominant
373 // edges) and merge Right and Bottom edges into TopRightBottomLeft 372 // edges) and merge Right and Bottom edges into TopRightBottomLeft
374 373
375 // Inputs 374 // Inputs
376 // g_src0Texture4Uint mini4_edge_texture_ tex1 375 // g_src0Texture4Uint mini4_edge_texture_ tex1
377 // Outputs 376 // Outputs
378 // image2D g_resultTexture edge_texture_b image0 377 // image2D g_resultTexture edge_texture_b image0
379 { 378 {
380 glUseProgram(edges1_shader_); 379 glUseProgram(edges1_shader_);
381 glUniform1f(0, 0.0f); 380 glUniform2f(0, 1.0f / width_, 1.0f / height_);
382 glUniform2f(1, 1.0f / width_, 1.0f / height_);
383 glDepthMask(GL_FALSE); 381 glDepthMask(GL_FALSE);
384 glDepthFunc(GL_LESS); 382 glDepthFunc(GL_LESS);
385 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 383 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
386 384
387 if (!is_gles31_compatible_) { 385 if (!is_gles31_compatible_) {
388 glUniform1i(edges1_shader_result_texture_, 0); 386 glUniform1i(edges1_shader_result_texture_, 0);
389 } 387 }
390 glBindImageTextureEXT(0, edge_texture_b, 0, GL_FALSE, 0, GL_WRITE_ONLY, 388 glBindImageTextureEXT(0, edge_texture_b, 0, GL_FALSE, 0, GL_WRITE_ONLY,
391 edge_format); 389 edge_format);
392 390
393 glActiveTexture(GL_TEXTURE1); 391 glActiveTexture(GL_TEXTURE1);
394 glBindTexture(GL_TEXTURE_2D, mini4_edge_texture_); 392 glBindTexture(GL_TEXTURE_2D, mini4_edge_texture_);
395 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 393 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
396 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 394 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
397 395
398 glDrawArrays(GL_TRIANGLES, 0, 3); 396 glDrawArrays(GL_TRIANGLES, 0, 3);
399 } 397 }
400 398
401 // - Combine RightBottom (.xy) edges from previous pass into 399 // - Combine RightBottom (.xy) edges from previous pass into
402 // RightBottomLeftTop (.xyzw) edges and output it into the mask (have to 400 // RightBottomLeftTop (.xyzw) edges and output it into the mask.
403 // fill in the whole buffer including empty ones for the line length
404 // detection to work correctly).
405 // - On all pixels with any edge, input buffer into a temporary color buffer 401 // - On all pixels with any edge, input buffer into a temporary color buffer
406 // needed for correct blending in the next pass (other pixels not needed 402 // needed for correct blending in the next pass (other pixels not needed
407 // so not copied to avoid bandwidth use). 403 // so not copied to avoid bandwidth use).
408 // - On all pixels with 2 or more edges output positive depth mask for the 404 // - On all pixels with 2 or more edges output positive depth mask for the
409 // next pass. 405 // next pass.
410 406
411 // Inputs 407 // Inputs
412 // g_src0TextureFlt edge_texture_b tex1 //ps 408 // g_src0TextureFlt edge_texture_b tex1 //ps
413 // Outputs 409 // Outputs
414 // image2D g_resultTextureSlot2 edge_texture_a image2 410 // image2D g_resultTextureSlot2 edge_texture_a image2
415 // gl_FragDepth mini4_edge_texture_ fbo.depth 411 // gl_FragDepth mini4_edge_texture_ fbo.depth
416 { 412 {
417 // Combine edges: each pixel will now contain info on all (top, right, 413 // Combine edges: each pixel will now contain info on all (top, right,
418 // bottom, left) edges; also create depth mask as above depth and mark 414 // bottom, left) edges; also mark depth 1 value on all pixels with any edge
419 // potential Z sAND also copy source color data but only on edge pixels 415 // and also copy source color data but only on edge pixels
420 glUseProgram(edges_combine_shader_); 416 glUseProgram(edges_combine_shader_);
421 glUniform1f(0, 1.0f); 417 glUniform2f(0, 1.0f / width_, 1.0f / height_);
422 glUniform2f(1, 1.0f / width_, 1.0f / height_);
423 glDepthMask(GL_TRUE); 418 glDepthMask(GL_TRUE);
424 glDepthFunc(GL_ALWAYS); 419 glDepthFunc(GL_LESS);
425 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 420 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
426 421
427 if (!is_gles31_compatible_) { 422 if (!is_gles31_compatible_) {
428 glUniform1i(edges_combine_shader_result_texture_slot2_, 2); 423 glUniform1i(edges_combine_shader_result_texture_slot2_, 2);
429 } 424 }
430 glBindImageTextureEXT(2, edge_texture_a, 0, GL_FALSE, 0, GL_WRITE_ONLY, 425 glBindImageTextureEXT(2, edge_texture_a, 0, GL_FALSE, 0, GL_WRITE_ONLY,
431 edge_format); 426 edge_format);
432 427
433 glActiveTexture(GL_TEXTURE1); 428 glActiveTexture(GL_TEXTURE1);
434 glBindTexture(GL_TEXTURE_2D, edge_texture_b); 429 glBindTexture(GL_TEXTURE_2D, edge_texture_b);
(...skipping 13 matching lines...) Expand all
448 443
449 // Inputs 444 // Inputs
450 // g_screenTexture working_color_texture_ tex0 445 // g_screenTexture working_color_texture_ tex0
451 // g_src0TextureFlt edge_texture_a tex1 //ps 446 // g_src0TextureFlt edge_texture_a tex1 //ps
452 // sampled 447 // sampled
453 // Outputs 448 // Outputs
454 // g_resultTextureFlt4Slot1 dest_texture image1 449 // g_resultTextureFlt4Slot1 dest_texture image1
455 // gl_FragDepth mini4_edge_texture_ fbo.depth 450 // gl_FragDepth mini4_edge_texture_ fbo.depth
456 { 451 {
457 glUseProgram(process_and_apply_shader_); 452 glUseProgram(process_and_apply_shader_);
458 glUniform1f(0, 0.0f); 453 glUniform2f(0, 1.0f / width_, 1.0f / height_);
459 glUniform2f(1, 1.0f / width_, 1.0f / height_);
460 glDepthMask(GL_FALSE); 454 glDepthMask(GL_FALSE);
461 glDepthFunc(GL_LESS); 455 glDepthFunc(GL_LESS);
462 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 456 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
463 457
464 if (!is_gles31_compatible_) { 458 if (!is_gles31_compatible_) {
465 glUniform1i(process_and_apply_shader_result_texture_float4_slot1_, 1); 459 glUniform1i(process_and_apply_shader_result_texture_float4_slot1_, 1);
466 } 460 }
467 glBindImageTextureEXT(1, dest_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, 461 glBindImageTextureEXT(1, dest_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY,
468 GL_RGBA8); 462 GL_RGBA8);
469 463
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 } 677 }
684 678
685 return shader; 679 return shader;
686 } 680 }
687 681
688 /* clang-format off */ 682 /* clang-format off */
689 // Shaders used in the CMAA algorithm. 683 // Shaders used in the CMAA algorithm.
690 const char ApplyFramebufferAttachmentCMAAINTELResourceManager::vert_str_[] = 684 const char ApplyFramebufferAttachmentCMAAINTELResourceManager::vert_str_[] =
691 SHADER( 685 SHADER(
692 precision highp float; 686 precision highp float;
693 layout(location = 0) uniform float g_Depth;
694 // No input data. 687 // No input data.
695 // Verts are autogenerated. 688 // Verts are autogenerated.
696 // 689 //
697 // vertexID 0,1,2 should generate 690 // vertexID 0,1,2 should generate
698 // POS: (-1,-1), (+3,-1), (-1,+3) 691 // POS: (-1,-1), (+3,-1), (-1,+3)
699 // 692 //
700 // This generates a triangle that completely covers the -1->1 viewport 693 // This generates a triangle that completely covers the -1->1 viewport
701 // 694 //
702 void main() 695 void main()
703 { 696 {
704 float x = -1.0 + float((gl_VertexID & 1) << 2); 697 float x = -1.0 + float((gl_VertexID & 1) << 2);
705 float y = -1.0 + float((gl_VertexID & 2) << 1); 698 float y = -1.0 + float((gl_VertexID & 2) << 1);
706 gl_Position = vec4(x, y, g_Depth, 1.0); 699 gl_Position = vec4(x, y, 0.0, 1.0);
707 } 700 }
708 ); 701 );
709 702
710 const char ApplyFramebufferAttachmentCMAAINTELResourceManager::cmaa_frag_s1_[] = 703 const char ApplyFramebufferAttachmentCMAAINTELResourceManager::cmaa_frag_s1_[] =
711 SHADER( 704 SHADER(
712 precision highp float; 705 precision highp float;
713 precision highp int; 706 precision highp int;
714 707
715 \n#define SETTINGS_ALLOW_SHORT_Zs 1\n 708 \n#define SETTINGS_ALLOW_SHORT_Zs 1\n
716 \n#define EDGE_DETECT_THRESHOLD 13.0f\n 709 \n#define EDGE_DETECT_THRESHOLD 13.0f\n
717 \n#define saturate(x) clamp((x), 0.0, 1.0)\n 710 \n#define saturate(x) clamp((x), 0.0, 1.0)\n
718 711
719 // bind to location 0
720 layout(location = 0) uniform float g_Depth;
721 // bind to a uniform buffer bind point 0 712 // bind to a uniform buffer bind point 0
722 layout(location = 1) uniform vec2 g_OneOverScreenSize; 713 layout(location = 0) uniform vec2 g_OneOverScreenSize;
723 \n#ifndef EDGE_DETECT_THRESHOLD\n 714 \n#ifndef EDGE_DETECT_THRESHOLD\n
724 layout(location = 2) uniform float g_ColorThreshold; 715 layout(location = 1) uniform float g_ColorThreshold;
725 \n#endif\n 716 \n#endif\n
726 717
727 \n#ifdef SUPPORTS_USAMPLER2D\n 718 \n#ifdef SUPPORTS_USAMPLER2D\n
728 \n#define USAMPLER usampler2D\n 719 \n#define USAMPLER usampler2D\n
729 \n#define UVEC4 uvec4\n 720 \n#define UVEC4 uvec4\n
730 \n#define LOAD_UINT(arg) arg\n 721 \n#define LOAD_UINT(arg) arg\n
731 \n#define STORE_UVEC4(arg) arg\n 722 \n#define STORE_UVEC4(arg) arg\n
732 \n#else\n 723 \n#else\n
733 \n#define USAMPLER sampler2D\n 724 \n#define USAMPLER sampler2D\n
734 \n#define UVEC4 vec4\n 725 \n#define UVEC4 vec4\n
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 et = saturate(et - threshold); 1147 et = saturate(et - threshold);
1157 ivec2 eti = ivec2(et * 15.0 + 0.99); 1148 ivec2 eti = ivec2(et * 15.0 + 0.99);
1158 outputEdges.w = uint(eti.x | (eti.y << 4)); 1149 outputEdges.w = uint(eti.x | (eti.y << 4));
1159 1150
1160 storeFlagPixel11 += et.x; 1151 storeFlagPixel11 += et.x;
1161 storeFlagPixel11 += et.y; 1152 storeFlagPixel11 += et.y;
1162 storeFlagPixel21 += et.x; 1153 storeFlagPixel21 += et.x;
1163 storeFlagPixel12 += et.y; 1154 storeFlagPixel12 += et.y;
1164 } 1155 }
1165 1156
1166 gl_FragDepth = any(bvec4(outputEdges)) ? 1.0 : 0.0; 1157 gl_FragDepth = any(bvec4(outputEdges)) ? 1.0 : 0.0;
dshwang 2016/07/06 10:41:20 gl_Depth is redudant.
1167 1158
1168 if (gl_FragDepth != 0.0) { 1159 if (gl_FragDepth != 0.0) {
1169 if (storeFlagPixel00 != 0.0) 1160 if (storeFlagPixel00 != 0.0)
1170 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(0, 0), 1161 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(0, 0),
1171 pixel00); 1162 pixel00);
1172 if (storeFlagPixel10 != 0.0) 1163 if (storeFlagPixel10 != 0.0)
1173 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(1, 0), 1164 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(1, 0),
1174 pixel10); 1165 pixel10);
1175 if (storeFlagPixel20 != 0.0) 1166 if (storeFlagPixel20 != 0.0)
1176 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(2, 0), 1167 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(2, 0),
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1424 imageStore(g_resultTextureSlot2, screenPosIBase.xy + ivec2(0, 1), 1415 imageStore(g_resultTextureSlot2, screenPosIBase.xy + ivec2(0, 1),
1425 outEdge4Flt.zzzz); 1416 outEdge4Flt.zzzz);
1426 imageStore(g_resultTextureSlot2, screenPosIBase.xy + ivec2(1, 1), 1417 imageStore(g_resultTextureSlot2, screenPosIBase.xy + ivec2(1, 1),
1427 outEdge4Flt.wwww); 1418 outEdge4Flt.wwww);
1428 1419
1429 // uvec4 numberOfEdges4 = uvec4(bitCount(outEdge4)); 1420 // uvec4 numberOfEdges4 = uvec4(bitCount(outEdge4));
1430 // gl_FragDepth = 1421 // gl_FragDepth =
1431 // any(greaterThan(numberOfEdges4, uvec4(1))) ? 1.0 : 0.0; 1422 // any(greaterThan(numberOfEdges4, uvec4(1))) ? 1.0 : 0.0;
1432 1423
1433 gl_FragDepth = 1424 gl_FragDepth =
1434 any(greaterThan(outEdge4, uvec4(1))) ? 1.0 : 0.0; 1425 any(greaterThan(outEdge4, uvec4(1))) ? 1.0 : 0.0;
dshwang 2016/07/06 10:41:20 gl_Depth is redudant.
1435 } 1426 }
1436 \n#endif\n // COMBINE_EDGES 1427 \n#endif\n // COMBINE_EDGES
1437 1428
1438 \n#ifdef BLUR_EDGES\n 1429 \n#ifdef BLUR_EDGES\n
1439 layout(early_fragment_tests) in; 1430 layout(early_fragment_tests) in;
1440 void BlurEdges() { 1431 void BlurEdges() {
1441 // Each |gl_FragCoord| updates 4 texels of the original texture, which are 1432 // Each |gl_FragCoord| updates 4 texels of the original texture, which are
1442 // 2x|gl_FragCoord| + (-1 or 0, -1 or 0) in the unnormalized texture 1433 // 2x|gl_FragCoord| + (-1 or 0, -1 or 0) in the unnormalized texture
1443 // coordinate, which is the coordinate used by texelFetch(). 1434 // coordinate, which is the coordinate used by texelFetch().
1444 // e.g. when gl_FragCoord == (3.5, 3.5), this fragment shader covers 1435 // e.g. when gl_FragCoord == (3.5, 3.5), this fragment shader covers
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 \n#ifdef OUT_FBO\n 1874 \n#ifdef OUT_FBO\n
1884 outColor = pixel; 1875 outColor = pixel;
1885 \n#else\n 1876 \n#else\n
1886 imageStore(outTexture, screenPosI, pixel); 1877 imageStore(outTexture, screenPosI, pixel);
1887 \n#endif\n 1878 \n#endif\n
1888 } 1879 }
1889 ); 1880 );
1890 /* clang-format on */ 1881 /* clang-format on */
1891 1882
1892 } // namespace gpu 1883 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698