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

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

Issue 2405893002: gpu, cmaa: reduce one-copy (Closed)
Patch Set: add helper comment Created 4 years, 2 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 23 matching lines...) Expand all
34 process_and_apply_shader_(0), 34 process_and_apply_shader_(0),
35 debug_display_edges_shader_(0), 35 debug_display_edges_shader_(0),
36 cmaa_framebuffer_(0), 36 cmaa_framebuffer_(0),
37 copy_framebuffer_(0), 37 copy_framebuffer_(0),
38 rgba8_texture_(0), 38 rgba8_texture_(0),
39 working_color_texture_(0), 39 working_color_texture_(0),
40 edges0_texture_(0), 40 edges0_texture_(0),
41 edges1_texture_(0), 41 edges1_texture_(0),
42 mini4_edge_texture_(0), 42 mini4_edge_texture_(0),
43 mini4_edge_depth_texture_(0), 43 mini4_edge_depth_texture_(0),
44 edges1_shader_result_texture_float4_slot1_(0), 44 edges0_shader_result_rgba_texture_slot1_(0),
45 edges1_shader_result_texture_(0), 45 edges0_shader_target_texture_slot2_(0),
46 edges_combine_shader_result_texture_float4_slot1_(0), 46 edges1_shader_result_edge_texture_(0),
47 process_and_apply_shader_result_texture_float4_slot1_(0), 47 process_and_apply_shader_result_rgba_texture_slot1_(0),
48 edges_combine_shader_result_texture_slot2_(0) {} 48 edges_combine_shader_result_edge_texture_(0) {}
49 49
50 ApplyFramebufferAttachmentCMAAINTELResourceManager:: 50 ApplyFramebufferAttachmentCMAAINTELResourceManager::
51 ~ApplyFramebufferAttachmentCMAAINTELResourceManager() { 51 ~ApplyFramebufferAttachmentCMAAINTELResourceManager() {
52 Destroy(); 52 Destroy();
53 } 53 }
54 54
55 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Initialize( 55 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Initialize(
56 gles2::GLES2Decoder* decoder) { 56 gles2::GLES2Decoder* decoder) {
57 DCHECK(decoder); 57 DCHECK(decoder);
58 is_gles31_compatible_ = 58 is_gles31_compatible_ =
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 CreateProgram(edge2.str().c_str(), vert_str_, cmaa_frag_c_str); 166 CreateProgram(edge2.str().c_str(), vert_str_, cmaa_frag_c_str);
167 167
168 combineEdges << defines.str() << "#define COMBINE_EDGES\n"; 168 combineEdges << defines.str() << "#define COMBINE_EDGES\n";
169 edges_combine_shader_ = 169 edges_combine_shader_ =
170 CreateProgram(combineEdges.str().c_str(), vert_str_, cmaa_frag_c_str); 170 CreateProgram(combineEdges.str().c_str(), vert_str_, cmaa_frag_c_str);
171 171
172 blur << defines.str() << "#define BLUR_EDGES\n"; 172 blur << defines.str() << "#define BLUR_EDGES\n";
173 process_and_apply_shader_ = 173 process_and_apply_shader_ =
174 CreateProgram(blur.str().c_str(), vert_str_, cmaa_frag_c_str); 174 CreateProgram(blur.str().c_str(), vert_str_, cmaa_frag_c_str);
175 175
176 edges1_shader_result_texture_float4_slot1_ = 176 edges0_shader_result_rgba_texture_slot1_ =
177 glGetUniformLocation(edges0_shader_, "g_resultTextureFlt4Slot1"); 177 glGetUniformLocation(edges0_shader_, "g_resultRGBATextureSlot1");
178 edges1_shader_result_texture_ = 178 edges0_shader_target_texture_slot2_ =
179 glGetUniformLocation(edges1_shader_, "g_resultTexture"); 179 glGetUniformLocation(edges0_shader_, "g_targetTextureSlot2");
180 edges_combine_shader_result_texture_float4_slot1_ = 180 edges1_shader_result_edge_texture_ =
181 glGetUniformLocation(edges_combine_shader_, "g_resultTextureFlt4Slot1"); 181 glGetUniformLocation(edges1_shader_, "g_resultEdgeTexture");
182 edges_combine_shader_result_texture_slot2_ = 182 edges_combine_shader_result_edge_texture_ =
183 glGetUniformLocation(edges_combine_shader_, "g_resultTextureSlot2"); 183 glGetUniformLocation(edges_combine_shader_, "g_resultEdgeTexture");
184 process_and_apply_shader_result_texture_float4_slot1_ = glGetUniformLocation( 184 process_and_apply_shader_result_rgba_texture_slot1_ = glGetUniformLocation(
185 process_and_apply_shader_, "g_resultTextureFlt4Slot1"); 185 process_and_apply_shader_, "g_resultRGBATextureSlot1");
186 186
187 initialized_ = true; 187 initialized_ = true;
188 } 188 }
189 189
190 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Destroy() { 190 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Destroy() {
191 if (!initialized_) 191 if (!initialized_)
192 return; 192 return;
193 193
194 ReleaseTextures(); 194 ReleaseTextures();
195 195
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 GLsizei height = attachment->height(); 234 GLsizei height = attachment->height();
235 GLenum internal_format = attachment->internal_format(); 235 GLenum internal_format = attachment->internal_format();
236 236
237 // Resize internal structures - only if needed. 237 // Resize internal structures - only if needed.
238 OnSize(width, height); 238 OnSize(width, height);
239 239
240 // CMAA internally expects GL_RGBA8 textures. 240 // CMAA internally expects GL_RGBA8 textures.
241 // Process using a GL_RGBA8 copy if this is not the case. 241 // Process using a GL_RGBA8 copy if this is not the case.
242 bool do_copy = internal_format != GL_RGBA8; 242 bool do_copy = internal_format != GL_RGBA8;
243 243
244 // Copy source_texture to rgba8_texture_
245 if (do_copy) {
246 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_);
247 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
248 GL_TEXTURE_2D, source_texture, 0);
249 CopyTexture(rgba8_texture_);
250 }
251
252 // CMAA Effect 244 // CMAA Effect
253 if (do_copy) { 245 if (do_copy) {
254 ApplyCMAAEffectTexture(rgba8_texture_, rgba8_texture_); 246 ApplyCMAAEffectTexture(source_texture, rgba8_texture_, do_copy);
255 } else { 247 } else {
256 ApplyCMAAEffectTexture(source_texture, source_texture); 248 ApplyCMAAEffectTexture(source_texture, source_texture, do_copy);
257 } 249 }
258 250
259 // Copy rgba8_texture_ to source_texture 251 // Copy rgba8_texture_ to source_texture
260 if (do_copy) { 252 if (do_copy) {
253 // copy_framebuffer_ always binds rgba8_texture_
261 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_); 254 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_);
262 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
263 GL_TEXTURE_2D, rgba8_texture_, 0);
264 CopyTexture(source_texture); 255 CopyTexture(source_texture);
265 } 256 }
266 decoder->RestoreTextureState(source_texture); 257 decoder->RestoreTextureState(source_texture);
267 } 258 }
268 } 259 }
269 260
270 // Restore state 261 // Restore state
271 decoder->RestoreAllAttributes(); 262 decoder->RestoreAllAttributes();
272 decoder->RestoreTextureUnitBindings(0); 263 decoder->RestoreTextureUnitBindings(0);
273 decoder->RestoreTextureUnitBindings(1); 264 decoder->RestoreTextureUnitBindings(1);
274 decoder->RestoreActiveTexture(); 265 decoder->RestoreActiveTexture();
275 decoder->RestoreProgramBindings(); 266 decoder->RestoreProgramBindings();
276 decoder->RestoreBufferBindings(); 267 decoder->RestoreBufferBindings();
277 decoder->RestoreFramebufferBindings(); 268 decoder->RestoreFramebufferBindings();
278 decoder->RestoreGlobalState(); 269 decoder->RestoreGlobalState();
279 } 270 }
280 271
281 void ApplyFramebufferAttachmentCMAAINTELResourceManager::ApplyCMAAEffectTexture( 272 void ApplyFramebufferAttachmentCMAAINTELResourceManager::ApplyCMAAEffectTexture(
282 GLuint source_texture, 273 GLuint source_texture,
283 GLuint dest_texture) { 274 GLuint dest_texture,
275 bool do_copy) {
284 frame_id_++; 276 frame_id_++;
285 277
286 GLuint edge_texture_a; 278 GLuint edge_texture_a;
287 GLuint edge_texture_b; 279 GLuint edge_texture_b;
288 280
289 // Flip flop - One pass clears the texture that needs clearing for the other 281 // Flip flop - One pass clears the texture that needs clearing for the other
290 // one (actually it's only important that it clears the highest bit) 282 // one (actually it's only important that it clears the highest bit)
291 if ((frame_id_ % 2) == 0) { 283 if ((frame_id_ % 2) == 0) {
292 edge_texture_a = edges0_texture_; 284 edge_texture_a = edges0_texture_;
293 edge_texture_b = edges1_texture_; 285 edge_texture_b = edges1_texture_;
(...skipping 25 matching lines...) Expand all
319 // Detect edges Pass 0 311 // Detect edges Pass 0
320 // - For every pixel detect edges to the right and down and output depth 312 // - For every pixel detect edges to the right and down and output depth
321 // mask where edges detected (1 - far, for detected, 0-near for empty 313 // mask where edges detected (1 - far, for detected, 0-near for empty
322 // pixels) 314 // pixels)
323 315
324 // Inputs 316 // Inputs
325 // g_screenTexture source_texture tex0 317 // g_screenTexture source_texture tex0
326 // Outputs 318 // Outputs
327 // gl_FragDepth mini4_edge_depth_texture_ fbo.depth 319 // gl_FragDepth mini4_edge_depth_texture_ fbo.depth
328 // out uvec4 outEdges mini4_edge_texture_ fbo.col 320 // out uvec4 outEdges mini4_edge_texture_ fbo.col
329 // image2D g_resultTextureFlt4Slot1 working_color_texture_ image1 321 // image2D g_resultRGBATextureSlot1 working_color_texture_ image1
330 GLenum edge_format = supports_r8_image_ ? GL_R8 : GL_R32F; 322 GLenum edge_format = supports_r8_image_ ? GL_R8 : GL_R32F;
331 323
332 { 324 {
333 glUseProgram(edges0_shader_); 325 glUseProgram(edges0_shader_);
334 glUniform2f(0, 1.0f / width_, 1.0f / height_); 326 glUniform2f(0, 1.0f / width_, 1.0f / height_);
335 glDepthMask(GL_TRUE); 327 glDepthMask(GL_TRUE);
336 glDepthFunc(GL_ALWAYS); 328 glDepthFunc(GL_ALWAYS);
337 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 329 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
338 330
339 if (!is_gles31_compatible_) { 331 if (!is_gles31_compatible_) {
340 glUniform1i(edges1_shader_result_texture_float4_slot1_, 1); 332 glUniform1i(edges0_shader_result_rgba_texture_slot1_, 1);
333 glUniform1i(edges0_shader_target_texture_slot2_, 2);
341 } 334 }
342 glBindImageTextureEXT(1, working_color_texture_, 0, GL_FALSE, 0, 335 glBindImageTextureEXT(1, working_color_texture_, 0, GL_FALSE, 0,
343 GL_WRITE_ONLY, GL_RGBA8); 336 GL_WRITE_ONLY, GL_RGBA8);
337 if (do_copy) {
338 glUniform1i(2, GL_TRUE);
339 glBindImageTextureEXT(2, dest_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY,
340 GL_RGBA8);
341 } else {
342 glUniform1i(2, GL_FALSE);
343 }
344 344
345 glActiveTexture(GL_TEXTURE0); 345 glActiveTexture(GL_TEXTURE0);
346 glBindTexture(GL_TEXTURE_2D, source_texture); 346 glBindTexture(GL_TEXTURE_2D, source_texture);
347 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 347 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
348 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 348 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
349 349
350 glDrawArrays(GL_TRIANGLES, 0, 3); 350 glDrawArrays(GL_TRIANGLES, 0, 3);
351 } 351 }
352 352
353 // Detect edges Pass 1 (finish the previous pass edge processing). 353 // Detect edges Pass 1 (finish the previous pass edge processing).
354 // Do the culling of non-dominant local edges (leave mainly locally dominant 354 // Do the culling of non-dominant local edges (leave mainly locally dominant
355 // edges) and merge Right and Bottom edges into TopRightBottomLeft 355 // edges) and merge Right and Bottom edges into TopRightBottomLeft
356 356
357 // Inputs 357 // Inputs
358 // g_src0Texture4Uint mini4_edge_texture_ tex1 358 // g_src0Texture4Uint mini4_edge_texture_ tex1
359 // Outputs 359 // Outputs
360 // image2D g_resultTexture edge_texture_b image0 360 // image2D g_resultEdgeTexture edge_texture_b image0
361 { 361 {
362 glUseProgram(edges1_shader_); 362 glUseProgram(edges1_shader_);
363 glUniform2f(0, 1.0f / width_, 1.0f / height_); 363 glUniform2f(0, 1.0f / width_, 1.0f / height_);
364 glDepthMask(GL_FALSE); 364 glDepthMask(GL_FALSE);
365 glDepthFunc(GL_LESS); 365 glDepthFunc(GL_LESS);
366 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 366 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
367 367
368 if (!is_gles31_compatible_) { 368 if (!is_gles31_compatible_) {
369 glUniform1i(edges1_shader_result_texture_, 0); 369 glUniform1i(edges1_shader_result_edge_texture_, 0);
370 } 370 }
371 glBindImageTextureEXT(0, edge_texture_b, 0, GL_FALSE, 0, GL_WRITE_ONLY, 371 glBindImageTextureEXT(0, edge_texture_b, 0, GL_FALSE, 0, GL_WRITE_ONLY,
372 edge_format); 372 edge_format);
373 373
374 glActiveTexture(GL_TEXTURE1); 374 glActiveTexture(GL_TEXTURE1);
375 glBindTexture(GL_TEXTURE_2D, mini4_edge_texture_); 375 glBindTexture(GL_TEXTURE_2D, mini4_edge_texture_);
376 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 376 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
377 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 377 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
378 378
379 glDrawArrays(GL_TRIANGLES, 0, 3); 379 glDrawArrays(GL_TRIANGLES, 0, 3);
380 } 380 }
381 381
382 // - Combine RightBottom (.xy) edges from previous pass into 382 // - Combine RightBottom (.xy) edges from previous pass into
383 // RightBottomLeftTop (.xyzw) edges and output it into the mask. 383 // RightBottomLeftTop (.xyzw) edges and output it into the mask.
384 // - On all pixels with any edge, input buffer into a temporary color buffer 384 // - On all pixels with any edge, input buffer into a temporary color buffer
385 // needed for correct blending in the next pass (other pixels not needed 385 // needed for correct blending in the next pass (other pixels not needed
386 // so not copied to avoid bandwidth use). 386 // so not copied to avoid bandwidth use).
387 // - On all pixels with 2 or more edges output positive depth mask for the 387 // - On all pixels with 2 or more edges output positive depth mask for the
388 // next pass. 388 // next pass.
389 389
390 // Inputs 390 // Inputs
391 // g_src0TextureFlt edge_texture_b tex1 //ps 391 // g_src0TextureFlt edge_texture_b tex1 //ps
392 // Outputs 392 // Outputs
393 // image2D g_resultTextureSlot2 edge_texture_a image2 393 // image2D g_resultEdgeTexture edge_texture_a image2
394 // gl_FragDepth mini4_edge_texture_ fbo.depth 394 // gl_FragDepth mini4_edge_texture_ fbo.depth
395 { 395 {
396 // Combine edges: each pixel will now contain info on all (top, right, 396 // Combine edges: each pixel will now contain info on all (top, right,
397 // bottom, left) edges; also mark depth 1 value on all pixels with any edge 397 // bottom, left) edges; also mark depth 1 value on all pixels with any edge
398 // and also copy source color data but only on edge pixels 398 // and also copy source color data but only on edge pixels
399 glUseProgram(edges_combine_shader_); 399 glUseProgram(edges_combine_shader_);
400 glUniform2f(0, 1.0f / width_, 1.0f / height_); 400 glUniform2f(0, 1.0f / width_, 1.0f / height_);
401 glDepthMask(GL_TRUE); 401 glDepthMask(GL_TRUE);
402 glDepthFunc(GL_LESS); 402 glDepthFunc(GL_LESS);
403 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 403 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
404 404
405 if (!is_gles31_compatible_) { 405 if (!is_gles31_compatible_) {
406 glUniform1i(edges_combine_shader_result_texture_slot2_, 2); 406 glUniform1i(edges_combine_shader_result_edge_texture_, 0);
407 } 407 }
408 glBindImageTextureEXT(2, edge_texture_a, 0, GL_FALSE, 0, GL_WRITE_ONLY, 408 glBindImageTextureEXT(0, edge_texture_a, 0, GL_FALSE, 0, GL_WRITE_ONLY,
409 edge_format); 409 edge_format);
410 410
411 glActiveTexture(GL_TEXTURE1); 411 glActiveTexture(GL_TEXTURE1);
412 glBindTexture(GL_TEXTURE_2D, edge_texture_b); 412 glBindTexture(GL_TEXTURE_2D, edge_texture_b);
413 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 413 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
414 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 414 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
415 415
416 glDrawArrays(GL_TRIANGLES, 0, 3); 416 glDrawArrays(GL_TRIANGLES, 0, 3);
417 } 417 }
418 418
419 // Using depth mask and [earlydepthstencil] to work on pixels with 2, 3, 4 419 // Using depth mask and [earlydepthstencil] to work on pixels with 2, 3, 4
420 // edges: 420 // edges:
421 // - First blend simple blur map for 2,3,4 edge pixels 421 // - First blend simple blur map for 2,3,4 edge pixels
422 // - Then do the lines (line length counter -should- guarantee no overlap 422 // - Then do the lines (line length counter -should- guarantee no overlap
423 // with other pixels - pixels with 1 edge are excluded in the previous 423 // with other pixels - pixels with 1 edge are excluded in the previous
424 // pass and the pixels with 2 parallel edges are excluded in the simple 424 // pass and the pixels with 2 parallel edges are excluded in the simple
425 // blur) 425 // blur)
426 426
427 // Inputs 427 // Inputs
428 // g_screenTexture working_color_texture_ tex0 428 // g_screenTexture working_color_texture_ tex0
429 // g_src0TextureFlt edge_texture_a tex1 //ps 429 // g_src0TextureFlt edge_texture_a tex1 //ps
430 // sampled 430 // sampled
431 // Outputs 431 // Outputs
432 // g_resultTextureFlt4Slot1 dest_texture image1 432 // g_resultRGBATextureSlot1 dest_texture image1
433 // gl_FragDepth mini4_edge_texture_ fbo.depth 433 // gl_FragDepth mini4_edge_texture_ fbo.depth
434 { 434 {
435 glUseProgram(process_and_apply_shader_); 435 glUseProgram(process_and_apply_shader_);
436 glUniform2f(0, 1.0f / width_, 1.0f / height_); 436 glUniform2f(0, 1.0f / width_, 1.0f / height_);
437 glDepthMask(GL_FALSE); 437 glDepthMask(GL_FALSE);
438 glDepthFunc(GL_LESS); 438 glDepthFunc(GL_LESS);
439 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 439 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
440 440
441 if (!is_gles31_compatible_) { 441 if (!is_gles31_compatible_) {
442 glUniform1i(process_and_apply_shader_result_texture_float4_slot1_, 1); 442 glUniform1i(process_and_apply_shader_result_rgba_texture_slot1_, 1);
443 } 443 }
444 glBindImageTextureEXT(1, dest_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, 444 glBindImageTextureEXT(1, dest_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY,
445 GL_RGBA8); 445 GL_RGBA8);
446 446
447 glActiveTexture(GL_TEXTURE0); 447 glActiveTexture(GL_TEXTURE0);
448 glBindTexture(GL_TEXTURE_2D, working_color_texture_); 448 glBindTexture(GL_TEXTURE_2D, working_color_texture_);
449 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 449 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
450 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 450 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
451 451
452 glActiveTexture(GL_TEXTURE1); 452 glActiveTexture(GL_TEXTURE1);
(...skipping 17 matching lines...) Expand all
470 470
471 ReleaseTextures(); 471 ReleaseTextures();
472 472
473 height_ = height; 473 height_ = height;
474 width_ = width; 474 width_ = width;
475 475
476 glGenFramebuffersEXT(1, &copy_framebuffer_); 476 glGenFramebuffersEXT(1, &copy_framebuffer_);
477 glGenTextures(1, &rgba8_texture_); 477 glGenTextures(1, &rgba8_texture_);
478 glBindTexture(GL_TEXTURE_2D, rgba8_texture_); 478 glBindTexture(GL_TEXTURE_2D, rgba8_texture_);
479 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, width, height); 479 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, width, height);
480 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_);
481 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
482 rgba8_texture_, 0);
480 483
481 // Edges texture - R8 484 // Edges texture - R8
482 // OpenGLES has no single component 8/16-bit image support, so needs to be R32 485 // OpenGLES has no single component 8/16-bit image support, so needs to be R32
483 // Although CHT does support R8. 486 // Although CHT does support R8.
484 GLenum edge_format = supports_r8_image_ ? GL_R8 : GL_R32F; 487 GLenum edge_format = supports_r8_image_ ? GL_R8 : GL_R32F;
485 glGenTextures(1, &edges0_texture_); 488 glGenTextures(1, &edges0_texture_);
486 glBindTexture(GL_TEXTURE_2D, edges0_texture_); 489 glBindTexture(GL_TEXTURE_2D, edges0_texture_);
487 glTexStorage2DEXT(GL_TEXTURE_2D, 1, edge_format, width, height); 490 glTexStorage2DEXT(GL_TEXTURE_2D, 1, edge_format, width, height);
488 491
489 glGenTextures(1, &edges1_texture_); 492 glGenTextures(1, &edges1_texture_);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 676
674 \n#define SETTINGS_ALLOW_SHORT_Zs 1\n 677 \n#define SETTINGS_ALLOW_SHORT_Zs 1\n
675 \n#define EDGE_DETECT_THRESHOLD 13.0f\n 678 \n#define EDGE_DETECT_THRESHOLD 13.0f\n
676 \n#define saturate(x) clamp((x), 0.0, 1.0)\n 679 \n#define saturate(x) clamp((x), 0.0, 1.0)\n
677 680
678 // bind to a uniform buffer bind point 0 681 // bind to a uniform buffer bind point 0
679 layout(location = 0) uniform vec2 g_OneOverScreenSize; 682 layout(location = 0) uniform vec2 g_OneOverScreenSize;
680 \n#ifndef EDGE_DETECT_THRESHOLD\n 683 \n#ifndef EDGE_DETECT_THRESHOLD\n
681 layout(location = 1) uniform float g_ColorThreshold; 684 layout(location = 1) uniform float g_ColorThreshold;
682 \n#endif\n 685 \n#endif\n
686 \n#ifdef DETECT_EDGES1\n
687 layout(location = 2) uniform int g_DoCopy;
688 \n#endif\n
683 689
684 \n#ifdef SUPPORTS_USAMPLER2D\n 690 \n#ifdef SUPPORTS_USAMPLER2D\n
685 \n#define USAMPLER usampler2D\n 691 \n#define USAMPLER usampler2D\n
686 \n#define UVEC4 uvec4\n 692 \n#define UVEC4 uvec4\n
687 \n#define LOAD_UINT(arg) arg\n 693 \n#define LOAD_UINT(arg) arg\n
688 \n#define STORE_UVEC4(arg) arg\n 694 \n#define STORE_UVEC4(arg) arg\n
689 \n#else\n 695 \n#else\n
690 \n#define USAMPLER sampler2D\n 696 \n#define USAMPLER sampler2D\n
691 \n#define UVEC4 vec4\n 697 \n#define UVEC4 vec4\n
692 \n#define LOAD_UINT(arg) uint(arg * 255.0f)\n 698 \n#define LOAD_UINT(arg) uint(arg * 255.0f)\n
693 \n#define STORE_UVEC4(arg) vec4(float(arg.x) / 255.0f, 699 \n#define STORE_UVEC4(arg) vec4(float(arg.x) / 255.0f,
694 float(arg.y) / 255.0f, 700 float(arg.y) / 255.0f,
695 float(arg.z) / 255.0f, 701 float(arg.z) / 255.0f,
696 float(arg.w) / 255.0f)\n 702 float(arg.w) / 255.0f)\n
697 \n#endif\n 703 \n#endif\n
698 704
699 // bind to texture stage 0/1 705 // bind to texture stage 0/1
700 layout(binding = 0) uniform highp sampler2D g_screenTexture; 706 layout(binding = 0) uniform highp sampler2D g_screenTexture;
701 layout(binding = 1) uniform highp sampler2D g_src0TextureFlt; 707 layout(binding = 1) uniform highp sampler2D g_src0TextureFlt;
702 layout(binding = 1) uniform highp USAMPLER g_src0Texture4Uint; 708 layout(binding = 1) uniform highp USAMPLER g_src0Texture4Uint;
703 709
704 // bind to image stage 0/1/2 710 // bind to image stage 0/1/2
705 \n#ifdef GL_ES\n 711 \n#ifdef GL_ES\n
706 layout(binding = 0, EDGE_READ_FORMAT) restrict writeonly uniform highp 712 layout(binding = 0, EDGE_READ_FORMAT) restrict writeonly uniform highp
707 image2D g_resultTexture; 713 image2D g_resultEdgeTexture;
708 layout(binding = 1, rgba8) restrict writeonly uniform highp 714 layout(binding = 1, rgba8) restrict writeonly uniform highp
709 image2D g_resultTextureFlt4Slot1; 715 image2D g_resultRGBATextureSlot1;
710 layout(binding = 2, EDGE_READ_FORMAT) restrict writeonly uniform highp 716 layout(binding = 2, rgba8) restrict writeonly uniform highp
711 image2D g_resultTextureSlot2; 717 image2D g_targetTextureSlot2;
712 \n#else\n 718 \n#else\n
713 layout(EDGE_READ_FORMAT) restrict writeonly uniform highp 719 layout(EDGE_READ_FORMAT) restrict writeonly uniform highp
714 image2D g_resultTexture; 720 image2D g_resultEdgeTexture;
715 layout(rgba8) restrict writeonly uniform highp 721 layout(rgba8) restrict writeonly uniform highp
716 image2D g_resultTextureFlt4Slot1; 722 image2D g_resultRGBATextureSlot1;
717 layout(EDGE_READ_FORMAT) restrict writeonly uniform highp 723 layout(rgba8) restrict writeonly uniform highp
718 image2D g_resultTextureSlot2; 724 image2D g_targetTextureSlot2;
719 \n#endif\n 725 \n#endif\n
720 726
721 // Constants 727 // Constants
722 const vec4 c_lumWeights = vec4(0.2126f, 0.7152f, 0.0722f, 0.0000f); 728 const vec4 c_lumWeights = vec4(0.2126f, 0.7152f, 0.0722f, 0.0000f);
723 729
724 \n#ifdef EDGE_DETECT_THRESHOLD\n 730 \n#ifdef EDGE_DETECT_THRESHOLD\n
725 const float c_ColorThreshold = 1.0f / EDGE_DETECT_THRESHOLD; 731 const float c_ColorThreshold = 1.0f / EDGE_DETECT_THRESHOLD;
726 \n#endif\n 732 \n#endif\n
727 733
728 // Must be even number; Will work with ~16 pretty good too for 734 // Must be even number; Will work with ~16 pretty good too for
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 973
968 float totalLength = float(loopTo - loopFrom) + 1.0 - leftOdd - 974 float totalLength = float(loopTo - loopFrom) + 1.0 - leftOdd -
969 rightOdd; 975 rightOdd;
970 976
971 for (int i = loopFrom; i <= loopTo; i++) { 977 for (int i = loopFrom; i <= loopTo; i++) {
972 highp ivec2 pixelPos = screenPos + stepRight * i; 978 highp ivec2 pixelPos = screenPos + stepRight * i;
973 vec2 pixelPosFlt = vec2(float(pixelPos.x) + 0.5, 979 vec2 pixelPosFlt = vec2(float(pixelPos.x) + 0.5,
974 float(pixelPos.y) + 0.5); 980 float(pixelPos.y) + 0.5);
975 981
976 \n#ifdef DEBUG_OUTPUT_AAINFO\n 982 \n#ifdef DEBUG_OUTPUT_AAINFO\n
977 imageStore(g_resultTextureSlot2, pixelPos, 983 imageStore(g_resultEdgeTexture, pixelPos,
978 PackBlurAAInfo(pixelPos, 1u)); 984 PackBlurAAInfo(pixelPos, 1u));
979 \n#endif\n 985 \n#endif\n
980 986
981 float m = (float(i) + 0.5 - leftOdd - float(loopFrom)) / 987 float m = (float(i) + 0.5 - leftOdd - float(loopFrom)) /
982 totalLength; 988 totalLength;
983 m = saturate(m); 989 m = saturate(m);
984 float k = m - ((i > 0) ? 1.0 : 0.0); 990 float k = m - ((i > 0) ? 1.0 : 0.0);
985 k = (invertedZShape) ? (k) : (-k); 991 k = (invertedZShape) ? (k) : (-k);
986 992
987 vec4 color = textureLod(g_screenTexture, 993 vec4 color = textureLod(g_screenTexture,
988 (pixelPosFlt + blendDir * k) * pixelSize, 994 (pixelPosFlt + blendDir * k) * pixelSize,
989 0.0); 995 0.0);
990 996
991 \n#ifdef IN_GAMMA_CORRECT_MODE\n 997 \n#ifdef IN_GAMMA_CORRECT_MODE\n
992 color.rgb = D3DX_FLOAT3_to_SRGB(color.rgb); 998 color.rgb = D3DX_FLOAT3_to_SRGB(color.rgb);
993 \n#endif\n 999 \n#endif\n
994 imageStore(g_resultTextureFlt4Slot1, pixelPos, color); 1000 imageStore(g_resultRGBATextureSlot1, pixelPos, color);
995 } 1001 }
996 } 1002 }
997 1003
998 vec4 CalcDbgDisplayColor(const vec4 blurMap) { 1004 vec4 CalcDbgDisplayColor(const vec4 blurMap) {
999 vec3 pixelC = vec3(0.0, 0.0, 0.0); 1005 vec3 pixelC = vec3(0.0, 0.0, 0.0);
1000 vec3 pixelL = vec3(0.0, 0.0, 1.0); 1006 vec3 pixelL = vec3(0.0, 0.0, 1.0);
1001 vec3 pixelT = vec3(1.0, 0.0, 0.0); 1007 vec3 pixelT = vec3(1.0, 0.0, 0.0);
1002 vec3 pixelR = vec3(0.0, 1.0, 0.0); 1008 vec3 pixelR = vec3(0.0, 1.0, 0.0);
1003 vec3 pixelB = vec3(0.8, 0.8, 0.0); 1009 vec3 pixelB = vec3(0.8, 0.8, 0.0);
1004 1010
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(0, 1)); 1050 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(0, 1));
1045 vec4 pixel11 = 1051 vec4 pixel11 =
1046 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(1, 1)); 1052 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(1, 1));
1047 vec4 pixel21 = 1053 vec4 pixel21 =
1048 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(2, 1)); 1054 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(2, 1));
1049 vec4 pixel02 = 1055 vec4 pixel02 =
1050 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(0, 2)); 1056 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(0, 2));
1051 vec4 pixel12 = 1057 vec4 pixel12 =
1052 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(1, 2)); 1058 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(1, 2));
1053 1059
1060 if (g_DoCopy == 1) {
1061 imageStore(g_targetTextureSlot2, screenPosI.xy + ivec2(0, 0), pixel00);
1062 imageStore(g_targetTextureSlot2, screenPosI.xy + ivec2(1, 0), pixel10);
1063 imageStore(g_targetTextureSlot2, screenPosI.xy + ivec2(0, 1), pixel01);
1064 imageStore(g_targetTextureSlot2, screenPosI.xy + ivec2(1, 1), pixel11);
1065 }
1066
1054 float storeFlagPixel00 = 0.0; 1067 float storeFlagPixel00 = 0.0;
1055 float storeFlagPixel10 = 0.0; 1068 float storeFlagPixel10 = 0.0;
1056 float storeFlagPixel20 = 0.0; 1069 float storeFlagPixel20 = 0.0;
1057 float storeFlagPixel01 = 0.0; 1070 float storeFlagPixel01 = 0.0;
1058 float storeFlagPixel11 = 0.0; 1071 float storeFlagPixel11 = 0.0;
1059 float storeFlagPixel21 = 0.0; 1072 float storeFlagPixel21 = 0.0;
1060 float storeFlagPixel02 = 0.0; 1073 float storeFlagPixel02 = 0.0;
1061 float storeFlagPixel12 = 0.0; 1074 float storeFlagPixel12 = 0.0;
1062 1075
1063 vec2 et; 1076 vec2 et;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 storeFlagPixel11 += et.x; 1130 storeFlagPixel11 += et.x;
1118 storeFlagPixel11 += et.y; 1131 storeFlagPixel11 += et.y;
1119 storeFlagPixel21 += et.x; 1132 storeFlagPixel21 += et.x;
1120 storeFlagPixel12 += et.y; 1133 storeFlagPixel12 += et.y;
1121 } 1134 }
1122 1135
1123 gl_FragDepth = any(bvec4(outputEdges)) ? 1.0 : 0.0; 1136 gl_FragDepth = any(bvec4(outputEdges)) ? 1.0 : 0.0;
1124 1137
1125 if (gl_FragDepth != 0.0) { 1138 if (gl_FragDepth != 0.0) {
1126 if (storeFlagPixel00 != 0.0) 1139 if (storeFlagPixel00 != 0.0)
1127 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(0, 0), 1140 imageStore(g_resultRGBATextureSlot1, screenPosI.xy + ivec2(0, 0),
1128 pixel00); 1141 pixel00);
1129 if (storeFlagPixel10 != 0.0) 1142 if (storeFlagPixel10 != 0.0)
1130 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(1, 0), 1143 imageStore(g_resultRGBATextureSlot1, screenPosI.xy + ivec2(1, 0),
1131 pixel10); 1144 pixel10);
1132 if (storeFlagPixel20 != 0.0) 1145 if (storeFlagPixel20 != 0.0)
1133 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(2, 0), 1146 imageStore(g_resultRGBATextureSlot1, screenPosI.xy + ivec2(2, 0),
1134 pixel20); 1147 pixel20);
1135 if (storeFlagPixel01 != 0.0) 1148 if (storeFlagPixel01 != 0.0)
1136 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(0, 1), 1149 imageStore(g_resultRGBATextureSlot1, screenPosI.xy + ivec2(0, 1),
1137 pixel01); 1150 pixel01);
1138 if (storeFlagPixel02 != 0.0) 1151 if (storeFlagPixel02 != 0.0)
1139 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(0, 2), 1152 imageStore(g_resultRGBATextureSlot1, screenPosI.xy + ivec2(0, 2),
1140 pixel02); 1153 pixel02);
1141 if (storeFlagPixel11 != 0.0) 1154 if (storeFlagPixel11 != 0.0)
1142 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(1, 1), 1155 imageStore(g_resultRGBATextureSlot1, screenPosI.xy + ivec2(1, 1),
1143 pixel11); 1156 pixel11);
1144 if (storeFlagPixel21 != 0.0) 1157 if (storeFlagPixel21 != 0.0)
1145 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(2, 1), 1158 imageStore(g_resultRGBATextureSlot1, screenPosI.xy + ivec2(2, 1),
1146 pixel21); 1159 pixel21);
1147 if (storeFlagPixel12 != 0.0) 1160 if (storeFlagPixel12 != 0.0)
1148 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(1, 2), 1161 imageStore(g_resultRGBATextureSlot1, screenPosI.xy + ivec2(1, 2),
1149 pixel12); 1162 pixel12);
1150 } 1163 }
1151 outEdges = STORE_UVEC4(outputEdges); 1164 outEdges = STORE_UVEC4(outputEdges);
1152 } 1165 }
1153 \n#endif\n // DETECT_EDGES1 1166 \n#endif\n // DETECT_EDGES1
1154 1167
1155 vec2 UnpackThresholds(uint val) { 1168 vec2 UnpackThresholds(uint val) {
1156 return vec2(val & 0x0Fu, val >> 4u) / 15.0f; 1169 return vec2(val & 0x0Fu, val >> 4u) / 15.0f;
1157 } 1170 }
1158 1171
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 packedVals[(0) * 6 + (2)] = LOAD_UINT(packedQ3.x); 1256 packedVals[(0) * 6 + (2)] = LOAD_UINT(packedQ3.x);
1244 packedVals[(1) * 6 + (2)] = LOAD_UINT(packedQ3.y); 1257 packedVals[(1) * 6 + (2)] = LOAD_UINT(packedQ3.y);
1245 packedVals[(0) * 6 + (3)] = LOAD_UINT(packedQ3.z); 1258 packedVals[(0) * 6 + (3)] = LOAD_UINT(packedQ3.z);
1246 packedVals[(1) * 6 + (3)] = LOAD_UINT(packedQ3.w); 1259 packedVals[(1) * 6 + (3)] = LOAD_UINT(packedQ3.w);
1247 } 1260 }
1248 1261
1249 if (bool(packedVals[(2) * 6 + (2)])) { 1262 if (bool(packedVals[(2) * 6 + (2)])) {
1250 CollectEdges(2, 2, edges, packedVals); 1263 CollectEdges(2, 2, edges, packedVals);
1251 uint pe = PackEdge(PruneNonDominantEdges(edges)); 1264 uint pe = PackEdge(PruneNonDominantEdges(edges));
1252 if (pe != 0u) { 1265 if (pe != 0u) {
1253 imageStore(g_resultTexture, 2 * screenPosI.xy + ivec2(0, 0), 1266 imageStore(g_resultEdgeTexture, 2 * screenPosI.xy + ivec2(0, 0),
1254 vec4(float(0x80u | pe) / 255.0, 0, 0, 0)); 1267 vec4(float(0x80u | pe) / 255.0, 0, 0, 0));
1255 } 1268 }
1256 } 1269 }
1257 1270
1258 if (bool(packedVals[(3) * 6 + (2)]) || 1271 if (bool(packedVals[(3) * 6 + (2)]) ||
1259 bool(packedVals[(3) * 6 + (3)])) { 1272 bool(packedVals[(3) * 6 + (3)])) {
1260 UVEC4 packedQ5 = texelFetchOffset(g_src0Texture4Uint, 1273 UVEC4 packedQ5 = texelFetchOffset(g_src0Texture4Uint,
1261 screenPosI.xy, 0, ivec2(1, 0)); 1274 screenPosI.xy, 0, ivec2(1, 0));
1262 packedVals[(4) * 6 + (2)] = LOAD_UINT(packedQ5.x); 1275 packedVals[(4) * 6 + (2)] = LOAD_UINT(packedQ5.x);
1263 packedVals[(5) * 6 + (2)] = LOAD_UINT(packedQ5.y); 1276 packedVals[(5) * 6 + (2)] = LOAD_UINT(packedQ5.y);
1264 packedVals[(4) * 6 + (3)] = LOAD_UINT(packedQ5.z); 1277 packedVals[(4) * 6 + (3)] = LOAD_UINT(packedQ5.z);
1265 packedVals[(5) * 6 + (3)] = LOAD_UINT(packedQ5.w); 1278 packedVals[(5) * 6 + (3)] = LOAD_UINT(packedQ5.w);
1266 } 1279 }
1267 1280
1268 if (bool(packedVals[(3) * 6 + (2)])) { 1281 if (bool(packedVals[(3) * 6 + (2)])) {
1269 UVEC4 packedQ2 = texelFetchOffset(g_src0Texture4Uint, 1282 UVEC4 packedQ2 = texelFetchOffset(g_src0Texture4Uint,
1270 screenPosI.xy, 0, ivec2(1, -1)); 1283 screenPosI.xy, 0, ivec2(1, -1));
1271 packedVals[(4) * 6 + (0)] = LOAD_UINT(packedQ2.x); 1284 packedVals[(4) * 6 + (0)] = LOAD_UINT(packedQ2.x);
1272 packedVals[(5) * 6 + (0)] = LOAD_UINT(packedQ2.y); 1285 packedVals[(5) * 6 + (0)] = LOAD_UINT(packedQ2.y);
1273 packedVals[(4) * 6 + (1)] = LOAD_UINT(packedQ2.z); 1286 packedVals[(4) * 6 + (1)] = LOAD_UINT(packedQ2.z);
1274 packedVals[(5) * 6 + (1)] = LOAD_UINT(packedQ2.w); 1287 packedVals[(5) * 6 + (1)] = LOAD_UINT(packedQ2.w);
1275 1288
1276 CollectEdges(3, 2, edges, packedVals); 1289 CollectEdges(3, 2, edges, packedVals);
1277 uvec4 dominant_edges = PruneNonDominantEdges(edges); 1290 uvec4 dominant_edges = PruneNonDominantEdges(edges);
1278 // The rightmost edge of the texture is not edge. 1291 // The rightmost edge of the texture is not edge.
1279 // Note: texelFetch() on out of range gives an undefined value. 1292 // Note: texelFetch() on out of range gives an undefined value.
1280 uint pe = PackEdge(dominant_edges * uvec4(notTopRight.x, 1, 1, 1)); 1293 uint pe = PackEdge(dominant_edges * uvec4(notTopRight.x, 1, 1, 1));
1281 if (pe != 0u) { 1294 if (pe != 0u) {
1282 imageStore(g_resultTexture, 2 * screenPosI.xy + ivec2(1, 0), 1295 imageStore(g_resultEdgeTexture, 2 * screenPosI.xy + ivec2(1, 0),
1283 vec4(float(0x80u | pe) / 255.0, 0, 0, 0)); 1296 vec4(float(0x80u | pe) / 255.0, 0, 0, 0));
1284 } 1297 }
1285 } 1298 }
1286 1299
1287 if (bool(packedVals[(2) * 6 + (3)]) || 1300 if (bool(packedVals[(2) * 6 + (3)]) ||
1288 bool(packedVals[(3) * 6 + (3)])) { 1301 bool(packedVals[(3) * 6 + (3)])) {
1289 UVEC4 packedQ7 = texelFetchOffset(g_src0Texture4Uint, 1302 UVEC4 packedQ7 = texelFetchOffset(g_src0Texture4Uint,
1290 screenPosI.xy, 0, ivec2(0, 1)); 1303 screenPosI.xy, 0, ivec2(0, 1));
1291 packedVals[(2) * 6 + (4)] = LOAD_UINT(packedQ7.x); 1304 packedVals[(2) * 6 + (4)] = LOAD_UINT(packedQ7.x);
1292 packedVals[(3) * 6 + (4)] = LOAD_UINT(packedQ7.y); 1305 packedVals[(3) * 6 + (4)] = LOAD_UINT(packedQ7.y);
1293 packedVals[(2) * 6 + (5)] = LOAD_UINT(packedQ7.z); 1306 packedVals[(2) * 6 + (5)] = LOAD_UINT(packedQ7.z);
1294 packedVals[(3) * 6 + (5)] = LOAD_UINT(packedQ7.w); 1307 packedVals[(3) * 6 + (5)] = LOAD_UINT(packedQ7.w);
1295 } 1308 }
1296 1309
1297 if (bool(packedVals[(2) * 6 + (3)])) { 1310 if (bool(packedVals[(2) * 6 + (3)])) {
1298 UVEC4 packedQ6 = texelFetchOffset(g_src0Texture4Uint, 1311 UVEC4 packedQ6 = texelFetchOffset(g_src0Texture4Uint,
1299 screenPosI.xy, 0, ivec2(-1, -1)); 1312 screenPosI.xy, 0, ivec2(-1, -1));
1300 packedVals[(0) * 6 + (4)] = LOAD_UINT(packedQ6.x); 1313 packedVals[(0) * 6 + (4)] = LOAD_UINT(packedQ6.x);
1301 packedVals[(1) * 6 + (4)] = LOAD_UINT(packedQ6.y); 1314 packedVals[(1) * 6 + (4)] = LOAD_UINT(packedQ6.y);
1302 packedVals[(0) * 6 + (5)] = LOAD_UINT(packedQ6.z); 1315 packedVals[(0) * 6 + (5)] = LOAD_UINT(packedQ6.z);
1303 packedVals[(1) * 6 + (5)] = LOAD_UINT(packedQ6.w); 1316 packedVals[(1) * 6 + (5)] = LOAD_UINT(packedQ6.w);
1304 1317
1305 CollectEdges(2, 3, edges, packedVals); 1318 CollectEdges(2, 3, edges, packedVals);
1306 uvec4 dominant_edges = PruneNonDominantEdges(edges); 1319 uvec4 dominant_edges = PruneNonDominantEdges(edges);
1307 uint pe = PackEdge(dominant_edges * uvec4(1, notTopRight.y, 1, 1)); 1320 uint pe = PackEdge(dominant_edges * uvec4(1, notTopRight.y, 1, 1));
1308 if (pe != 0u) { 1321 if (pe != 0u) {
1309 imageStore(g_resultTexture, 2 * screenPosI.xy + ivec2(0, 1), 1322 imageStore(g_resultEdgeTexture, 2 * screenPosI.xy + ivec2(0, 1),
1310 vec4(float(0x80u | pe) / 255.0, 0, 0, 0)); 1323 vec4(float(0x80u | pe) / 255.0, 0, 0, 0));
1311 } 1324 }
1312 } 1325 }
1313 1326
1314 if (bool(packedVals[(3) * 6 + (3)])) { 1327 if (bool(packedVals[(3) * 6 + (3)])) {
1315 CollectEdges(3, 3, edges, packedVals); 1328 CollectEdges(3, 3, edges, packedVals);
1316 uvec4 dominant_edges = PruneNonDominantEdges(edges); 1329 uvec4 dominant_edges = PruneNonDominantEdges(edges);
1317 uint pe = PackEdge(dominant_edges * uvec4(notTopRight, 1, 1)); 1330 uint pe = PackEdge(dominant_edges * uvec4(notTopRight, 1, 1));
1318 if (pe != 0u) { 1331 if (pe != 0u) {
1319 imageStore(g_resultTexture, 2 * screenPosI.xy + ivec2(1, 1), 1332 imageStore(g_resultEdgeTexture, 2 * screenPosI.xy + ivec2(1, 1),
1320 vec4(float(0x80u | pe) / 255.0, 0, 0, 0)); 1333 vec4(float(0x80u | pe) / 255.0, 0, 0, 0));
1321 } 1334 }
1322 } 1335 }
1323 } 1336 }
1324 \n#endif\n // DETECT_EDGES2 1337 \n#endif\n // DETECT_EDGES2
1325 1338
1326 \n#ifdef COMBINE_EDGES\n 1339 \n#ifdef COMBINE_EDGES\n
1327 void CombineEdges() { 1340 void CombineEdges() {
1328 ivec3 screenPosIBase = ivec3(ivec2(gl_FragCoord.xy) * 2, 0); 1341 ivec3 screenPosIBase = ivec3(ivec2(gl_FragCoord.xy) * 2, 0);
1329 vec3 screenPosBase = vec3(screenPosIBase); 1342 vec3 screenPosBase = vec3(screenPosIBase);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 packedEdgesArray[(0 + 1) * 3 + (1 + 1)]); 1380 packedEdgesArray[(0 + 1) * 3 + (1 + 1)]);
1368 uvec4 pixelsU = uvec4(packedEdgesArray[(1 + 0) * 3 + (0 + 0)], 1381 uvec4 pixelsU = uvec4(packedEdgesArray[(1 + 0) * 3 + (0 + 0)],
1369 packedEdgesArray[(1 + 1) * 3 + (0 + 0)], 1382 packedEdgesArray[(1 + 1) * 3 + (0 + 0)],
1370 packedEdgesArray[(1 + 0) * 3 + (0 + 1)], 1383 packedEdgesArray[(1 + 0) * 3 + (0 + 1)],
1371 packedEdgesArray[(1 + 1) * 3 + (0 + 1)]); 1384 packedEdgesArray[(1 + 1) * 3 + (0 + 1)]);
1372 1385
1373 uvec4 outEdge4 = 1386 uvec4 outEdge4 =
1374 pixelsC | ((pixelsL & 0x01u) << 2u) | ((pixelsU & 0x02u) << 2u); 1387 pixelsC | ((pixelsL & 0x01u) << 2u) | ((pixelsU & 0x02u) << 2u);
1375 vec4 outEdge4Flt = vec4(outEdge4) / 255.0; 1388 vec4 outEdge4Flt = vec4(outEdge4) / 255.0;
1376 1389
1377 imageStore(g_resultTextureSlot2, screenPosIBase.xy + ivec2(0, 0), 1390 imageStore(g_resultEdgeTexture, screenPosIBase.xy + ivec2(0, 0),
1378 outEdge4Flt.xxxx); 1391 outEdge4Flt.xxxx);
1379 imageStore(g_resultTextureSlot2, screenPosIBase.xy + ivec2(1, 0), 1392 imageStore(g_resultEdgeTexture, screenPosIBase.xy + ivec2(1, 0),
1380 outEdge4Flt.yyyy); 1393 outEdge4Flt.yyyy);
1381 imageStore(g_resultTextureSlot2, screenPosIBase.xy + ivec2(0, 1), 1394 imageStore(g_resultEdgeTexture, screenPosIBase.xy + ivec2(0, 1),
1382 outEdge4Flt.zzzz); 1395 outEdge4Flt.zzzz);
1383 imageStore(g_resultTextureSlot2, screenPosIBase.xy + ivec2(1, 1), 1396 imageStore(g_resultEdgeTexture, screenPosIBase.xy + ivec2(1, 1),
1384 outEdge4Flt.wwww); 1397 outEdge4Flt.wwww);
1385 1398
1386 // uvec4 numberOfEdges4 = uvec4(bitCount(outEdge4)); 1399 // uvec4 numberOfEdges4 = uvec4(bitCount(outEdge4));
1387 // gl_FragDepth = 1400 // gl_FragDepth =
1388 // any(greaterThan(numberOfEdges4, uvec4(1))) ? 1.0 : 0.0; 1401 // any(greaterThan(numberOfEdges4, uvec4(1))) ? 1.0 : 0.0;
1389 1402
1390 gl_FragDepth = 1403 gl_FragDepth =
1391 any(greaterThan(outEdge4, uvec4(1))) ? 1.0 : 0.0; 1404 any(greaterThan(outEdge4, uvec4(1))) ? 1.0 : 0.0;
1392 } 1405 }
1393 \n#endif\n // COMBINE_EDGES 1406 \n#endif\n // COMBINE_EDGES
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 } 1640 }
1628 1641
1629 color /= fourWeightSum + 0.0001; 1642 color /= fourWeightSum + 0.0001;
1630 1643
1631 color = mix(color, pixelC, centerWeight / allWeightSum); 1644 color = mix(color, pixelC, centerWeight / allWeightSum);
1632 \n#ifdef IN_GAMMA_CORRECT_MODE\n 1645 \n#ifdef IN_GAMMA_CORRECT_MODE\n
1633 color.rgb = D3DX_FLOAT3_to_SRGB(color.rgb); 1646 color.rgb = D3DX_FLOAT3_to_SRGB(color.rgb);
1634 \n#endif\n 1647 \n#endif\n
1635 1648
1636 \n#ifdef DEBUG_OUTPUT_AAINFO\n 1649 \n#ifdef DEBUG_OUTPUT_AAINFO\n
1637 imageStore(g_resultTextureSlot2, screenPosI.xy, 1650 imageStore(g_resultEdgeTexture, screenPosI.xy,
1638 PackBlurAAInfo(screenPosI.xy, numberOfEdges)); 1651 PackBlurAAInfo(screenPosI.xy, numberOfEdges));
1639 \n#endif\n 1652 \n#endif\n
1640 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy, color); 1653 imageStore(g_resultRGBATextureSlot1, screenPosI.xy, color);
1641 1654
1642 if (numberOfEdges == 2u) { 1655 if (numberOfEdges == 2u) {
1643 uint packedEdgesL = packedEdgesArray[(0 + _x) * 4 + (1 + _y)]; 1656 uint packedEdgesL = packedEdgesArray[(0 + _x) * 4 + (1 + _y)];
1644 uint packedEdgesB = packedEdgesArray[(1 + _x) * 4 + (0 + _y)]; 1657 uint packedEdgesB = packedEdgesArray[(1 + _x) * 4 + (0 + _y)];
1645 uint packedEdgesR = packedEdgesArray[(2 + _x) * 4 + (1 + _y)]; 1658 uint packedEdgesR = packedEdgesArray[(2 + _x) * 4 + (1 + _y)];
1646 uint packedEdgesT = packedEdgesArray[(1 + _x) * 4 + (2 + _y)]; 1659 uint packedEdgesT = packedEdgesArray[(1 + _x) * 4 + (2 + _y)];
1647 1660
1648 bool isHorizontalA = ((packedEdgesC) == (0x01u | 0x02u)) && 1661 bool isHorizontalA = ((packedEdgesC) == (0x01u | 0x02u)) &&
1649 ((packedEdgesR & 0x08u) == 0x08u); 1662 ((packedEdgesR & 0x08u) == 0x08u);
1650 bool isHorizontalB = ((packedEdgesC) == (0x01u | 0x08u)) && 1663 bool isHorizontalB = ((packedEdgesC) == (0x01u | 0x08u)) &&
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 \n#endif\n 1857 \n#endif\n
1845 \n#if defined DISPLAY_EDGES\n 1858 \n#if defined DISPLAY_EDGES\n
1846 DisplayEdges(); 1859 DisplayEdges();
1847 \n#endif\n 1860 \n#endif\n
1848 } 1861 }
1849 ); 1862 );
1850 /* clang-format on */ 1863 /* clang-format on */
1851 1864
1852 } // namespace gles2 1865 } // namespace gles2
1853 } // namespace gpu 1866 } // 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