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

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