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

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

Issue 2456913002: Revert "gpu, cmaa: copy RGBA8 texture via glCopyTexSubImage2D() instead of imageStore()." (Closed)
Patch Set: Created 4 years, 1 month 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 10 matching lines...) Expand all
21 : initialized_(false), 21 : initialized_(false),
22 textures_initialized_(false), 22 textures_initialized_(false),
23 is_in_gamma_correct_mode_(false), 23 is_in_gamma_correct_mode_(false),
24 supports_usampler_(true), 24 supports_usampler_(true),
25 supports_r8_image_(true), 25 supports_r8_image_(true),
26 supports_r8_read_format_(true), 26 supports_r8_read_format_(true),
27 is_gles31_compatible_(false), 27 is_gles31_compatible_(false),
28 frame_id_(0), 28 frame_id_(0),
29 width_(0), 29 width_(0),
30 height_(0), 30 height_(0),
31 copy_to_framebuffer_shader_(0),
32 copy_to_image_shader_(0),
31 edges0_shader_(0), 33 edges0_shader_(0),
32 edges1_shader_(0), 34 edges1_shader_(0),
33 edges_combine_shader_(0), 35 edges_combine_shader_(0),
34 process_and_apply_shader_(0), 36 process_and_apply_shader_(0),
35 debug_display_edges_shader_(0), 37 debug_display_edges_shader_(0),
36 cmaa_framebuffer_(0), 38 cmaa_framebuffer_(0),
37 copy_framebuffer_(0), 39 copy_framebuffer_(0),
38 rgba8_texture_(0), 40 rgba8_texture_(0),
39 working_color_texture_(0), 41 working_color_texture_(0),
40 edges0_texture_(0), 42 edges0_texture_(0),
41 edges1_texture_(0), 43 edges1_texture_(0),
42 mini4_edge_texture_(0), 44 mini4_edge_texture_(0),
43 mini4_edge_depth_texture_(0), 45 mini4_edge_depth_texture_(0),
44 edges0_shader_result_rgba_texture_slot1_(0), 46 edges1_shader_result_texture_float4_slot1_(0),
45 edges0_shader_target_texture_slot2_(0), 47 edges1_shader_result_texture_(0),
46 edges1_shader_result_edge_texture_(0), 48 edges_combine_shader_result_texture_float4_slot1_(0),
47 process_and_apply_shader_result_rgba_texture_slot1_(0), 49 process_and_apply_shader_result_texture_float4_slot1_(0),
48 edges_combine_shader_result_edge_texture_(0) {} 50 edges_combine_shader_result_texture_slot2_(0),
51 copy_to_image_shader_outTexture_(0) {}
49 52
50 ApplyFramebufferAttachmentCMAAINTELResourceManager:: 53 ApplyFramebufferAttachmentCMAAINTELResourceManager::
51 ~ApplyFramebufferAttachmentCMAAINTELResourceManager() { 54 ~ApplyFramebufferAttachmentCMAAINTELResourceManager() {
52 Destroy(); 55 Destroy();
53 } 56 }
54 57
55 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Initialize( 58 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Initialize(
56 gles2::GLES2Decoder* decoder) { 59 gles2::GLES2Decoder* decoder) {
57 DCHECK(decoder); 60 DCHECK(decoder);
58 is_gles31_compatible_ = 61 is_gles31_compatible_ =
59 decoder->GetGLContext()->GetVersionInfo()->IsAtLeastGLES(3, 1); 62 decoder->GetGLContext()->GetVersionInfo()->IsAtLeastGLES(3, 1);
60 63
64 copy_to_image_shader_ = CreateProgram("", vert_str_, copy_frag_str_);
65 copy_to_framebuffer_shader_ =
66 CreateProgram("#define OUT_FBO 1\n", vert_str_, copy_frag_str_);
67
61 // Check if RGBA8UI is supported as an FBO colour target with depth. 68 // Check if RGBA8UI is supported as an FBO colour target with depth.
62 // If not supported, GLSL needs to convert the data to/from float so there is 69 // If not supported, GLSL needs to convert the data to/from float so there is
63 // a small extra cost. 70 // a small extra cost.
64 { 71 {
65 GLuint rgba8ui_texture = 0, depth_texture = 0; 72 GLuint rgba8ui_texture = 0, depth_texture = 0;
66 glGenTextures(1, &rgba8ui_texture); 73 glGenTextures(1, &rgba8ui_texture);
67 glBindTexture(GL_TEXTURE_2D, rgba8ui_texture); 74 glBindTexture(GL_TEXTURE_2D, rgba8ui_texture);
68 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8UI, 4, 4); 75 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8UI, 4, 4);
69 76
70 glGenTextures(1, &depth_texture); 77 glGenTextures(1, &depth_texture);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 CreateProgram(edge2.str().c_str(), vert_str_, cmaa_frag_c_str); 173 CreateProgram(edge2.str().c_str(), vert_str_, cmaa_frag_c_str);
167 174
168 combineEdges << defines.str() << "#define COMBINE_EDGES\n"; 175 combineEdges << defines.str() << "#define COMBINE_EDGES\n";
169 edges_combine_shader_ = 176 edges_combine_shader_ =
170 CreateProgram(combineEdges.str().c_str(), vert_str_, cmaa_frag_c_str); 177 CreateProgram(combineEdges.str().c_str(), vert_str_, cmaa_frag_c_str);
171 178
172 blur << defines.str() << "#define BLUR_EDGES\n"; 179 blur << defines.str() << "#define BLUR_EDGES\n";
173 process_and_apply_shader_ = 180 process_and_apply_shader_ =
174 CreateProgram(blur.str().c_str(), vert_str_, cmaa_frag_c_str); 181 CreateProgram(blur.str().c_str(), vert_str_, cmaa_frag_c_str);
175 182
176 edges0_shader_result_rgba_texture_slot1_ = 183 edges1_shader_result_texture_float4_slot1_ =
177 glGetUniformLocation(edges0_shader_, "g_resultRGBATextureSlot1"); 184 glGetUniformLocation(edges0_shader_, "g_resultTextureFlt4Slot1");
178 edges0_shader_target_texture_slot2_ = 185 edges1_shader_result_texture_ =
179 glGetUniformLocation(edges0_shader_, "g_targetTextureSlot2"); 186 glGetUniformLocation(edges1_shader_, "g_resultTexture");
180 edges1_shader_result_edge_texture_ = 187 edges_combine_shader_result_texture_float4_slot1_ =
181 glGetUniformLocation(edges1_shader_, "g_resultEdgeTexture"); 188 glGetUniformLocation(edges_combine_shader_, "g_resultTextureFlt4Slot1");
182 edges_combine_shader_result_edge_texture_ = 189 edges_combine_shader_result_texture_slot2_ =
183 glGetUniformLocation(edges_combine_shader_, "g_resultEdgeTexture"); 190 glGetUniformLocation(edges_combine_shader_, "g_resultTextureSlot2");
184 process_and_apply_shader_result_rgba_texture_slot1_ = glGetUniformLocation( 191 process_and_apply_shader_result_texture_float4_slot1_ = glGetUniformLocation(
185 process_and_apply_shader_, "g_resultRGBATextureSlot1"); 192 process_and_apply_shader_, "g_resultTextureFlt4Slot1");
193 copy_to_image_shader_outTexture_ =
194 glGetUniformLocation(copy_to_image_shader_, "outTexture");
186 195
187 initialized_ = true; 196 initialized_ = true;
188 } 197 }
189 198
190 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Destroy() { 199 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Destroy() {
191 if (!initialized_) 200 if (!initialized_)
192 return; 201 return;
193 202
194 ReleaseTextures(); 203 ReleaseTextures();
195 204
205 glDeleteProgram(copy_to_image_shader_);
206 glDeleteProgram(copy_to_framebuffer_shader_);
196 glDeleteProgram(process_and_apply_shader_); 207 glDeleteProgram(process_and_apply_shader_);
197 glDeleteProgram(edges_combine_shader_); 208 glDeleteProgram(edges_combine_shader_);
198 glDeleteProgram(edges1_shader_); 209 glDeleteProgram(edges1_shader_);
199 glDeleteProgram(edges0_shader_); 210 glDeleteProgram(edges0_shader_);
200 glDeleteProgram(debug_display_edges_shader_); 211 glDeleteProgram(debug_display_edges_shader_);
201 212
202 initialized_ = false; 213 initialized_ = false;
203 } 214 }
204 215
205 // Apply CMAA(Conservative Morphological Anti-Aliasing) algorithm to the 216 // Apply CMAA(Conservative Morphological Anti-Aliasing) algorithm to the
206 // color attachments of currently bound draw framebuffer. 217 // color attachments of currently bound draw framebuffer.
207 // Reference GL_INTEL_framebuffer_CMAA for details. 218 // Reference GL_INTEL_framebuffer_CMAA for details.
208 void ApplyFramebufferAttachmentCMAAINTELResourceManager:: 219 void ApplyFramebufferAttachmentCMAAINTELResourceManager::
209 ApplyFramebufferAttachmentCMAAINTEL(gles2::GLES2Decoder* decoder, 220 ApplyFramebufferAttachmentCMAAINTEL(gles2::GLES2Decoder* decoder,
210 gles2::Framebuffer* framebuffer) { 221 gles2::Framebuffer* framebuffer) {
211 DCHECK(decoder); 222 DCHECK(decoder);
212 DCHECK(initialized_); 223 DCHECK(initialized_);
213 if (!framebuffer) 224 if (!framebuffer)
214 return; 225 return;
215 226
216 glDisable(GL_SCISSOR_TEST); 227 GLuint last_framebuffer = framebuffer->service_id();
217 glDisable(GL_STENCIL_TEST);
218 glDisable(GL_CULL_FACE);
219 glDisable(GL_BLEND);
220 228
221 // Process each color attachment of the current draw framebuffer. 229 // Process each color attachment of the current draw framebuffer.
222 uint32_t max_draw_buffers = decoder->GetContextGroup()->max_draw_buffers(); 230 uint32_t max_draw_buffers = decoder->GetContextGroup()->max_draw_buffers();
223 for (uint32_t i = 0; i < max_draw_buffers; i++) { 231 for (uint32_t i = 0; i < max_draw_buffers; i++) {
224 const gles2::Framebuffer::Attachment* attachment = 232 const gles2::Framebuffer::Attachment* attachment =
225 framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0 + i); 233 framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0 + i);
226 if (attachment && attachment->IsTextureAttachment()) { 234 if (attachment && attachment->IsTextureAttachment()) {
227 // Get the texture info. 235 // Get the texture info.
228 GLuint source_texture_client_id = attachment->object_name(); 236 GLuint source_texture_client_id = attachment->object_name();
229 GLuint source_texture = 0; 237 GLuint source_texture = 0;
230 if (!decoder->GetServiceTextureId(source_texture_client_id, 238 if (!decoder->GetServiceTextureId(source_texture_client_id,
231 &source_texture)) 239 &source_texture))
232 continue; 240 continue;
233 GLsizei width = attachment->width(); 241 GLsizei width = attachment->width();
234 GLsizei height = attachment->height(); 242 GLsizei height = attachment->height();
235 GLenum internal_format = attachment->internal_format(); 243 GLenum internal_format = attachment->internal_format();
236 244
237 // Resize internal structures - only if needed. 245 // Resize internal structures - only if needed.
238 OnSize(width, height); 246 OnSize(width, height);
239 247
240 // CMAA internally expects GL_RGBA8 textures. 248 // CMAA internally expects GL_RGBA8 textures.
241 // Process using a GL_RGBA8 copy if this is not the case. 249 // Process using a GL_RGBA8 copy if this is not the case.
242 bool do_copy = internal_format != GL_RGBA8; 250 bool do_copy = internal_format != GL_RGBA8;
243 251
252 // Copy source_texture to rgba8_texture_
253 if (do_copy) {
254 CopyTexture(source_texture, rgba8_texture_, false);
255 }
256
244 // CMAA Effect 257 // CMAA Effect
258 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, last_framebuffer);
245 if (do_copy) { 259 if (do_copy) {
246 ApplyCMAAEffectTexture(source_texture, rgba8_texture_, do_copy); 260 ApplyCMAAEffectTexture(rgba8_texture_, rgba8_texture_);
247 } else { 261 } else {
248 ApplyCMAAEffectTexture(source_texture, source_texture, do_copy); 262 ApplyCMAAEffectTexture(source_texture, source_texture);
249 } 263 }
250 264
251 // Copy rgba8_texture_ to source_texture 265 // Copy rgba8_texture_ to source_texture
252 if (do_copy) { 266 if (do_copy) {
253 // copy_framebuffer_ always binds rgba8_texture_ 267 // Move source_texture to the first color attachment of the copy fbo.
268 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, last_framebuffer);
269 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
270 GL_TEXTURE_2D, 0, 0);
254 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_); 271 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_);
255 CopyTexture(source_texture); 272 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
273 GL_TEXTURE_2D, source_texture, 0);
274
275 CopyTexture(rgba8_texture_, source_texture, true);
276
277 // Restore color attachments
278 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_);
279 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
280 GL_TEXTURE_2D, rgba8_texture_, 0);
281 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, last_framebuffer);
282 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
283 GL_TEXTURE_2D, source_texture, 0);
256 } 284 }
257 decoder->RestoreTextureState(source_texture);
258 } 285 }
259 } 286 }
260 287
261 // Restore state 288 // Restore state
262 decoder->RestoreAllAttributes(); 289 decoder->RestoreAllAttributes();
263 decoder->RestoreTextureUnitBindings(0); 290 decoder->RestoreTextureUnitBindings(0);
264 decoder->RestoreTextureUnitBindings(1); 291 decoder->RestoreTextureUnitBindings(1);
265 decoder->RestoreActiveTexture(); 292 decoder->RestoreActiveTexture();
266 decoder->RestoreProgramBindings(); 293 decoder->RestoreProgramBindings();
267 decoder->RestoreBufferBindings(); 294 decoder->RestoreBufferBindings();
268 decoder->RestoreFramebufferBindings(); 295 decoder->RestoreFramebufferBindings();
269 decoder->RestoreGlobalState(); 296 decoder->RestoreGlobalState();
270 } 297 }
271 298
272 void ApplyFramebufferAttachmentCMAAINTELResourceManager::ApplyCMAAEffectTexture( 299 void ApplyFramebufferAttachmentCMAAINTELResourceManager::ApplyCMAAEffectTexture(
273 GLuint source_texture, 300 GLuint source_texture,
274 GLuint dest_texture, 301 GLuint dest_texture) {
275 bool do_copy) {
276 frame_id_++; 302 frame_id_++;
277 303
278 GLuint edge_texture_a; 304 GLuint edge_texture_a;
279 GLuint edge_texture_b; 305 GLuint edge_texture_b;
280 306
281 // Flip flop - One pass clears the texture that needs clearing for the other 307 // Flip flop - One pass clears the texture that needs clearing for the other
282 // one (actually it's only important that it clears the highest bit) 308 // one (actually it's only important that it clears the highest bit)
283 if ((frame_id_ % 2) == 0) { 309 if ((frame_id_ % 2) == 0) {
284 edge_texture_a = edges0_texture_; 310 edge_texture_a = edges0_texture_;
285 edge_texture_b = edges1_texture_; 311 edge_texture_b = edges1_texture_;
(...skipping 25 matching lines...) Expand all
311 // Detect edges Pass 0 337 // Detect edges Pass 0
312 // - For every pixel detect edges to the right and down and output depth 338 // - For every pixel detect edges to the right and down and output depth
313 // mask where edges detected (1 - far, for detected, 0-near for empty 339 // mask where edges detected (1 - far, for detected, 0-near for empty
314 // pixels) 340 // pixels)
315 341
316 // Inputs 342 // Inputs
317 // g_screenTexture source_texture tex0 343 // g_screenTexture source_texture tex0
318 // Outputs 344 // Outputs
319 // gl_FragDepth mini4_edge_depth_texture_ fbo.depth 345 // gl_FragDepth mini4_edge_depth_texture_ fbo.depth
320 // out uvec4 outEdges mini4_edge_texture_ fbo.col 346 // out uvec4 outEdges mini4_edge_texture_ fbo.col
321 // image2D g_resultRGBATextureSlot1 working_color_texture_ image1 347 // image2D g_resultTextureFlt4Slot1 working_color_texture_ image1
322 GLenum edge_format = supports_r8_image_ ? GL_R8 : GL_R32F; 348 GLenum edge_format = supports_r8_image_ ? GL_R8 : GL_R32F;
323 349
324 { 350 {
325 glUseProgram(edges0_shader_); 351 glUseProgram(edges0_shader_);
326 glUniform2f(0, 1.0f / width_, 1.0f / height_); 352 glUniform2f(0, 1.0f / width_, 1.0f / height_);
327 glDepthMask(GL_TRUE); 353 glDepthMask(GL_TRUE);
328 glDepthFunc(GL_ALWAYS); 354 glDepthFunc(GL_ALWAYS);
329 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 355 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
330 356
331 if (!is_gles31_compatible_) { 357 if (!is_gles31_compatible_) {
332 glUniform1i(edges0_shader_result_rgba_texture_slot1_, 1); 358 glUniform1i(edges1_shader_result_texture_float4_slot1_, 1);
333 glUniform1i(edges0_shader_target_texture_slot2_, 2);
334 } 359 }
335 glBindImageTextureEXT(1, working_color_texture_, 0, GL_FALSE, 0, 360 glBindImageTextureEXT(1, working_color_texture_, 0, GL_FALSE, 0,
336 GL_WRITE_ONLY, GL_RGBA8); 361 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 362
345 glActiveTexture(GL_TEXTURE0); 363 glActiveTexture(GL_TEXTURE0);
346 glBindTexture(GL_TEXTURE_2D, source_texture); 364 glBindTexture(GL_TEXTURE_2D, source_texture);
347 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 365 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
348 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 366 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
349 367
350 glDrawArrays(GL_TRIANGLES, 0, 3); 368 glDrawArrays(GL_TRIANGLES, 0, 3);
351 } 369 }
352 370
353 // Detect edges Pass 1 (finish the previous pass edge processing). 371 // Detect edges Pass 1 (finish the previous pass edge processing).
354 // Do the culling of non-dominant local edges (leave mainly locally dominant 372 // Do the culling of non-dominant local edges (leave mainly locally dominant
355 // edges) and merge Right and Bottom edges into TopRightBottomLeft 373 // edges) and merge Right and Bottom edges into TopRightBottomLeft
356 374
357 // Inputs 375 // Inputs
358 // g_src0Texture4Uint mini4_edge_texture_ tex1 376 // g_src0Texture4Uint mini4_edge_texture_ tex1
359 // Outputs 377 // Outputs
360 // image2D g_resultEdgeTexture edge_texture_b image0 378 // image2D g_resultTexture edge_texture_b image0
361 { 379 {
362 glUseProgram(edges1_shader_); 380 glUseProgram(edges1_shader_);
363 glUniform2f(0, 1.0f / width_, 1.0f / height_); 381 glUniform2f(0, 1.0f / width_, 1.0f / height_);
364 glDepthMask(GL_FALSE); 382 glDepthMask(GL_FALSE);
365 glDepthFunc(GL_LESS); 383 glDepthFunc(GL_LESS);
366 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 384 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
367 385
368 if (!is_gles31_compatible_) { 386 if (!is_gles31_compatible_) {
369 glUniform1i(edges1_shader_result_edge_texture_, 0); 387 glUniform1i(edges1_shader_result_texture_, 0);
370 } 388 }
371 glBindImageTextureEXT(0, edge_texture_b, 0, GL_FALSE, 0, GL_WRITE_ONLY, 389 glBindImageTextureEXT(0, edge_texture_b, 0, GL_FALSE, 0, GL_WRITE_ONLY,
372 edge_format); 390 edge_format);
373 391
374 glActiveTexture(GL_TEXTURE1); 392 glActiveTexture(GL_TEXTURE1);
375 glBindTexture(GL_TEXTURE_2D, mini4_edge_texture_); 393 glBindTexture(GL_TEXTURE_2D, mini4_edge_texture_);
376 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 394 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
377 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 395 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
378 396
379 glDrawArrays(GL_TRIANGLES, 0, 3); 397 glDrawArrays(GL_TRIANGLES, 0, 3);
380 } 398 }
381 399
382 // - Combine RightBottom (.xy) edges from previous pass into 400 // - Combine RightBottom (.xy) edges from previous pass into
383 // RightBottomLeftTop (.xyzw) edges and output it into the mask. 401 // RightBottomLeftTop (.xyzw) edges and output it into the mask.
384 // - On all pixels with any edge, input buffer into a temporary color buffer 402 // - 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 403 // needed for correct blending in the next pass (other pixels not needed
386 // so not copied to avoid bandwidth use). 404 // so not copied to avoid bandwidth use).
387 // - On all pixels with 2 or more edges output positive depth mask for the 405 // - On all pixels with 2 or more edges output positive depth mask for the
388 // next pass. 406 // next pass.
389 407
390 // Inputs 408 // Inputs
391 // g_src0TextureFlt edge_texture_b tex1 //ps 409 // g_src0TextureFlt edge_texture_b tex1 //ps
392 // Outputs 410 // Outputs
393 // image2D g_resultEdgeTexture edge_texture_a image2 411 // image2D g_resultTextureSlot2 edge_texture_a image2
394 // gl_FragDepth mini4_edge_texture_ fbo.depth 412 // gl_FragDepth mini4_edge_texture_ fbo.depth
395 { 413 {
396 // Combine edges: each pixel will now contain info on all (top, right, 414 // 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 415 // 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 416 // and also copy source color data but only on edge pixels
399 glUseProgram(edges_combine_shader_); 417 glUseProgram(edges_combine_shader_);
400 glUniform2f(0, 1.0f / width_, 1.0f / height_); 418 glUniform2f(0, 1.0f / width_, 1.0f / height_);
401 glDepthMask(GL_TRUE); 419 glDepthMask(GL_TRUE);
402 glDepthFunc(GL_LESS); 420 glDepthFunc(GL_LESS);
403 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 421 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
404 422
405 if (!is_gles31_compatible_) { 423 if (!is_gles31_compatible_) {
406 glUniform1i(edges_combine_shader_result_edge_texture_, 0); 424 glUniform1i(edges_combine_shader_result_texture_slot2_, 2);
407 } 425 }
408 glBindImageTextureEXT(0, edge_texture_a, 0, GL_FALSE, 0, GL_WRITE_ONLY, 426 glBindImageTextureEXT(2, edge_texture_a, 0, GL_FALSE, 0, GL_WRITE_ONLY,
409 edge_format); 427 edge_format);
410 428
411 glActiveTexture(GL_TEXTURE1); 429 glActiveTexture(GL_TEXTURE1);
412 glBindTexture(GL_TEXTURE_2D, edge_texture_b); 430 glBindTexture(GL_TEXTURE_2D, edge_texture_b);
413 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 431 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
414 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 432 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
415 433
416 glDrawArrays(GL_TRIANGLES, 0, 3); 434 glDrawArrays(GL_TRIANGLES, 0, 3);
417 } 435 }
418 436
419 // Using depth mask and [earlydepthstencil] to work on pixels with 2, 3, 4 437 // Using depth mask and [earlydepthstencil] to work on pixels with 2, 3, 4
420 // edges: 438 // edges:
421 // - First blend simple blur map for 2,3,4 edge pixels 439 // - First blend simple blur map for 2,3,4 edge pixels
422 // - Then do the lines (line length counter -should- guarantee no overlap 440 // - Then do the lines (line length counter -should- guarantee no overlap
423 // with other pixels - pixels with 1 edge are excluded in the previous 441 // 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 442 // pass and the pixels with 2 parallel edges are excluded in the simple
425 // blur) 443 // blur)
426 444
427 // Inputs 445 // Inputs
428 // g_screenTexture working_color_texture_ tex0 446 // g_screenTexture working_color_texture_ tex0
429 // g_src0TextureFlt edge_texture_a tex1 //ps 447 // g_src0TextureFlt edge_texture_a tex1 //ps
430 // sampled 448 // sampled
431 // Outputs 449 // Outputs
432 // g_resultRGBATextureSlot1 dest_texture image1 450 // g_resultTextureFlt4Slot1 dest_texture image1
433 // gl_FragDepth mini4_edge_texture_ fbo.depth 451 // gl_FragDepth mini4_edge_texture_ fbo.depth
434 { 452 {
435 glUseProgram(process_and_apply_shader_); 453 glUseProgram(process_and_apply_shader_);
436 glUniform2f(0, 1.0f / width_, 1.0f / height_); 454 glUniform2f(0, 1.0f / width_, 1.0f / height_);
437 glDepthMask(GL_FALSE); 455 glDepthMask(GL_FALSE);
438 glDepthFunc(GL_LESS); 456 glDepthFunc(GL_LESS);
439 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 457 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
440 458
441 if (!is_gles31_compatible_) { 459 if (!is_gles31_compatible_) {
442 glUniform1i(process_and_apply_shader_result_rgba_texture_slot1_, 1); 460 glUniform1i(process_and_apply_shader_result_texture_float4_slot1_, 1);
443 } 461 }
444 glBindImageTextureEXT(1, dest_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, 462 glBindImageTextureEXT(1, dest_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY,
445 GL_RGBA8); 463 GL_RGBA8);
446 464
447 glActiveTexture(GL_TEXTURE0); 465 glActiveTexture(GL_TEXTURE0);
448 glBindTexture(GL_TEXTURE_2D, working_color_texture_); 466 glBindTexture(GL_TEXTURE_2D, working_color_texture_);
449 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 467 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
450 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 468 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
451 469
452 glActiveTexture(GL_TEXTURE1); 470 glActiveTexture(GL_TEXTURE1);
(...skipping 17 matching lines...) Expand all
470 488
471 ReleaseTextures(); 489 ReleaseTextures();
472 490
473 height_ = height; 491 height_ = height;
474 width_ = width; 492 width_ = width;
475 493
476 glGenFramebuffersEXT(1, &copy_framebuffer_); 494 glGenFramebuffersEXT(1, &copy_framebuffer_);
477 glGenTextures(1, &rgba8_texture_); 495 glGenTextures(1, &rgba8_texture_);
478 glBindTexture(GL_TEXTURE_2D, rgba8_texture_); 496 glBindTexture(GL_TEXTURE_2D, rgba8_texture_);
479 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, width, height); 497 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);
483 498
484 // Edges texture - R8 499 // Edges texture - R8
485 // OpenGLES has no single component 8/16-bit image support, so needs to be R32 500 // OpenGLES has no single component 8/16-bit image support, so needs to be R32
486 // Although CHT does support R8. 501 // Although CHT does support R8.
487 GLenum edge_format = supports_r8_image_ ? GL_R8 : GL_R32F; 502 GLenum edge_format = supports_r8_image_ ? GL_R8 : GL_R32F;
488 glGenTextures(1, &edges0_texture_); 503 glGenTextures(1, &edges0_texture_);
489 glBindTexture(GL_TEXTURE_2D, edges0_texture_); 504 glBindTexture(GL_TEXTURE_2D, edges0_texture_);
490 glTexStorage2DEXT(GL_TEXTURE_2D, 1, edge_format, width, height); 505 glTexStorage2DEXT(GL_TEXTURE_2D, 1, edge_format, width, height);
491 506
492 glGenTextures(1, &edges1_texture_); 507 glGenTextures(1, &edges1_texture_);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 glDeleteTextures(1, &edges0_texture_); 558 glDeleteTextures(1, &edges0_texture_);
544 glDeleteTextures(1, &edges1_texture_); 559 glDeleteTextures(1, &edges1_texture_);
545 glDeleteTextures(1, &mini4_edge_texture_); 560 glDeleteTextures(1, &mini4_edge_texture_);
546 glDeleteTextures(1, &mini4_edge_depth_texture_); 561 glDeleteTextures(1, &mini4_edge_depth_texture_);
547 glDeleteTextures(1, &working_color_texture_); 562 glDeleteTextures(1, &working_color_texture_);
548 } 563 }
549 textures_initialized_ = false; 564 textures_initialized_ = false;
550 } 565 }
551 566
552 void ApplyFramebufferAttachmentCMAAINTELResourceManager::CopyTexture( 567 void ApplyFramebufferAttachmentCMAAINTELResourceManager::CopyTexture(
553 GLint dest) { 568 GLint source,
569 GLint dest,
570 bool via_fbo) {
571 glViewport(0, 0, width_, height_);
554 glActiveTexture(GL_TEXTURE0); 572 glActiveTexture(GL_TEXTURE0);
555 glBindTexture(GL_TEXTURE_2D, dest); 573 glBindTexture(GL_TEXTURE_2D, source);
556 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
557 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
558 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
559 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
560 574
561 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width_, height_); 575 if (!via_fbo) {
576 glUseProgram(copy_to_image_shader_);
577 if (!is_gles31_compatible_) {
578 glUniform1i(copy_to_image_shader_outTexture_, 0);
579 }
580 glBindImageTextureEXT(0, dest, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
581 } else {
582 glDisable(GL_DEPTH_TEST);
583 glDisable(GL_STENCIL_TEST);
584 glDisable(GL_CULL_FACE);
585 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
586 glDepthMask(GL_FALSE);
587 glDisable(GL_BLEND);
588 glUseProgram(copy_to_framebuffer_shader_);
589 }
590
591 glDrawArrays(GL_TRIANGLES, 0, 3);
592 glUseProgram(0);
593 glBindTexture(GL_TEXTURE_2D, 0);
562 } 594 }
563 595
564 GLuint ApplyFramebufferAttachmentCMAAINTELResourceManager::CreateProgram( 596 GLuint ApplyFramebufferAttachmentCMAAINTELResourceManager::CreateProgram(
565 const char* defines, 597 const char* defines,
566 const char* vs_source, 598 const char* vs_source,
567 const char* fs_source) { 599 const char* fs_source) {
568 GLuint program = glCreateProgram(); 600 GLuint program = glCreateProgram();
569 601
570 GLuint vs = CreateShader(GL_VERTEX_SHADER, defines, vs_source); 602 GLuint vs = CreateShader(GL_VERTEX_SHADER, defines, vs_source);
571 GLuint fs = CreateShader(GL_FRAGMENT_SHADER, defines, fs_source); 603 GLuint fs = CreateShader(GL_FRAGMENT_SHADER, defines, fs_source);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 708
677 \n#define SETTINGS_ALLOW_SHORT_Zs 1\n 709 \n#define SETTINGS_ALLOW_SHORT_Zs 1\n
678 \n#define EDGE_DETECT_THRESHOLD 13.0f\n 710 \n#define EDGE_DETECT_THRESHOLD 13.0f\n
679 \n#define saturate(x) clamp((x), 0.0, 1.0)\n 711 \n#define saturate(x) clamp((x), 0.0, 1.0)\n
680 712
681 // bind to a uniform buffer bind point 0 713 // bind to a uniform buffer bind point 0
682 layout(location = 0) uniform vec2 g_OneOverScreenSize; 714 layout(location = 0) uniform vec2 g_OneOverScreenSize;
683 \n#ifndef EDGE_DETECT_THRESHOLD\n 715 \n#ifndef EDGE_DETECT_THRESHOLD\n
684 layout(location = 1) uniform float g_ColorThreshold; 716 layout(location = 1) uniform float g_ColorThreshold;
685 \n#endif\n 717 \n#endif\n
686 \n#ifdef DETECT_EDGES1\n
687 layout(location = 2) uniform int g_DoCopy;
688 \n#endif\n
689 718
690 \n#ifdef SUPPORTS_USAMPLER2D\n 719 \n#ifdef SUPPORTS_USAMPLER2D\n
691 \n#define USAMPLER usampler2D\n 720 \n#define USAMPLER usampler2D\n
692 \n#define UVEC4 uvec4\n 721 \n#define UVEC4 uvec4\n
693 \n#define LOAD_UINT(arg) arg\n 722 \n#define LOAD_UINT(arg) arg\n
694 \n#define STORE_UVEC4(arg) arg\n 723 \n#define STORE_UVEC4(arg) arg\n
695 \n#else\n 724 \n#else\n
696 \n#define USAMPLER sampler2D\n 725 \n#define USAMPLER sampler2D\n
697 \n#define UVEC4 vec4\n 726 \n#define UVEC4 vec4\n
698 \n#define LOAD_UINT(arg) uint(arg * 255.0f)\n 727 \n#define LOAD_UINT(arg) uint(arg * 255.0f)\n
699 \n#define STORE_UVEC4(arg) vec4(float(arg.x) / 255.0f, 728 \n#define STORE_UVEC4(arg) vec4(float(arg.x) / 255.0f,
700 float(arg.y) / 255.0f, 729 float(arg.y) / 255.0f,
701 float(arg.z) / 255.0f, 730 float(arg.z) / 255.0f,
702 float(arg.w) / 255.0f)\n 731 float(arg.w) / 255.0f)\n
703 \n#endif\n 732 \n#endif\n
704 733
705 // bind to texture stage 0/1 734 // bind to texture stage 0/1
706 layout(binding = 0) uniform highp sampler2D g_screenTexture; 735 layout(binding = 0) uniform highp sampler2D g_screenTexture;
707 layout(binding = 1) uniform highp sampler2D g_src0TextureFlt; 736 layout(binding = 1) uniform highp sampler2D g_src0TextureFlt;
708 layout(binding = 1) uniform highp USAMPLER g_src0Texture4Uint; 737 layout(binding = 1) uniform highp USAMPLER g_src0Texture4Uint;
709 738
710 // bind to image stage 0/1/2 739 // bind to image stage 0/1/2
711 \n#ifdef GL_ES\n 740 \n#ifdef GL_ES\n
712 layout(binding = 0, EDGE_READ_FORMAT) restrict writeonly uniform highp 741 layout(binding = 0, EDGE_READ_FORMAT) restrict writeonly uniform highp
713 image2D g_resultEdgeTexture; 742 image2D g_resultTexture;
714 layout(binding = 1, rgba8) restrict writeonly uniform highp 743 layout(binding = 1, rgba8) restrict writeonly uniform highp
715 image2D g_resultRGBATextureSlot1; 744 image2D g_resultTextureFlt4Slot1;
716 layout(binding = 2, rgba8) restrict writeonly uniform highp 745 layout(binding = 2, EDGE_READ_FORMAT) restrict writeonly uniform highp
717 image2D g_targetTextureSlot2; 746 image2D g_resultTextureSlot2;
718 \n#else\n 747 \n#else\n
719 layout(EDGE_READ_FORMAT) restrict writeonly uniform highp 748 layout(EDGE_READ_FORMAT) restrict writeonly uniform highp
720 image2D g_resultEdgeTexture; 749 image2D g_resultTexture;
721 layout(rgba8) restrict writeonly uniform highp 750 layout(rgba8) restrict writeonly uniform highp
722 image2D g_resultRGBATextureSlot1; 751 image2D g_resultTextureFlt4Slot1;
723 layout(rgba8) restrict writeonly uniform highp 752 layout(EDGE_READ_FORMAT) restrict writeonly uniform highp
724 image2D g_targetTextureSlot2; 753 image2D g_resultTextureSlot2;
725 \n#endif\n 754 \n#endif\n
726 755
727 // Constants 756 // Constants
728 const vec4 c_lumWeights = vec4(0.2126f, 0.7152f, 0.0722f, 0.0000f); 757 const vec4 c_lumWeights = vec4(0.2126f, 0.7152f, 0.0722f, 0.0000f);
729 758
730 \n#ifdef EDGE_DETECT_THRESHOLD\n 759 \n#ifdef EDGE_DETECT_THRESHOLD\n
731 const float c_ColorThreshold = 1.0f / EDGE_DETECT_THRESHOLD; 760 const float c_ColorThreshold = 1.0f / EDGE_DETECT_THRESHOLD;
732 \n#endif\n 761 \n#endif\n
733 762
734 // Must be even number; Will work with ~16 pretty good too for 763 // Must be even number; Will work with ~16 pretty good too for
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 1002
974 float totalLength = float(loopTo - loopFrom) + 1.0 - leftOdd - 1003 float totalLength = float(loopTo - loopFrom) + 1.0 - leftOdd -
975 rightOdd; 1004 rightOdd;
976 1005
977 for (int i = loopFrom; i <= loopTo; i++) { 1006 for (int i = loopFrom; i <= loopTo; i++) {
978 highp ivec2 pixelPos = screenPos + stepRight * i; 1007 highp ivec2 pixelPos = screenPos + stepRight * i;
979 vec2 pixelPosFlt = vec2(float(pixelPos.x) + 0.5, 1008 vec2 pixelPosFlt = vec2(float(pixelPos.x) + 0.5,
980 float(pixelPos.y) + 0.5); 1009 float(pixelPos.y) + 0.5);
981 1010
982 \n#ifdef DEBUG_OUTPUT_AAINFO\n 1011 \n#ifdef DEBUG_OUTPUT_AAINFO\n
983 imageStore(g_resultEdgeTexture, pixelPos, 1012 imageStore(g_resultTextureSlot2, pixelPos,
984 PackBlurAAInfo(pixelPos, 1u)); 1013 PackBlurAAInfo(pixelPos, 1u));
985 \n#endif\n 1014 \n#endif\n
986 1015
987 float m = (float(i) + 0.5 - leftOdd - float(loopFrom)) / 1016 float m = (float(i) + 0.5 - leftOdd - float(loopFrom)) /
988 totalLength; 1017 totalLength;
989 m = saturate(m); 1018 m = saturate(m);
990 float k = m - ((i > 0) ? 1.0 : 0.0); 1019 float k = m - ((i > 0) ? 1.0 : 0.0);
991 k = (invertedZShape) ? (k) : (-k); 1020 k = (invertedZShape) ? (k) : (-k);
992 1021
993 vec4 color = textureLod(g_screenTexture, 1022 vec4 color = textureLod(g_screenTexture,
994 (pixelPosFlt + blendDir * k) * pixelSize, 1023 (pixelPosFlt + blendDir * k) * pixelSize,
995 0.0); 1024 0.0);
996 1025
997 \n#ifdef IN_GAMMA_CORRECT_MODE\n 1026 \n#ifdef IN_GAMMA_CORRECT_MODE\n
998 color.rgb = D3DX_FLOAT3_to_SRGB(color.rgb); 1027 color.rgb = D3DX_FLOAT3_to_SRGB(color.rgb);
999 \n#endif\n 1028 \n#endif\n
1000 imageStore(g_resultRGBATextureSlot1, pixelPos, color); 1029 imageStore(g_resultTextureFlt4Slot1, pixelPos, color);
1001 } 1030 }
1002 } 1031 }
1003 1032
1004 vec4 CalcDbgDisplayColor(const vec4 blurMap) { 1033 vec4 CalcDbgDisplayColor(const vec4 blurMap) {
1005 vec3 pixelC = vec3(0.0, 0.0, 0.0); 1034 vec3 pixelC = vec3(0.0, 0.0, 0.0);
1006 vec3 pixelL = vec3(0.0, 0.0, 1.0); 1035 vec3 pixelL = vec3(0.0, 0.0, 1.0);
1007 vec3 pixelT = vec3(1.0, 0.0, 0.0); 1036 vec3 pixelT = vec3(1.0, 0.0, 0.0);
1008 vec3 pixelR = vec3(0.0, 1.0, 0.0); 1037 vec3 pixelR = vec3(0.0, 1.0, 0.0);
1009 vec3 pixelB = vec3(0.8, 0.8, 0.0); 1038 vec3 pixelB = vec3(0.8, 0.8, 0.0);
1010 1039
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(0, 1)); 1079 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(0, 1));
1051 vec4 pixel11 = 1080 vec4 pixel11 =
1052 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(1, 1)); 1081 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(1, 1));
1053 vec4 pixel21 = 1082 vec4 pixel21 =
1054 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(2, 1)); 1083 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(2, 1));
1055 vec4 pixel02 = 1084 vec4 pixel02 =
1056 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(0, 2)); 1085 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(0, 2));
1057 vec4 pixel12 = 1086 vec4 pixel12 =
1058 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(1, 2)); 1087 texelFetchOffset(g_screenTexture, screenPosI.xy, 0, ivec2(1, 2));
1059 1088
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
1067 float storeFlagPixel00 = 0.0; 1089 float storeFlagPixel00 = 0.0;
1068 float storeFlagPixel10 = 0.0; 1090 float storeFlagPixel10 = 0.0;
1069 float storeFlagPixel20 = 0.0; 1091 float storeFlagPixel20 = 0.0;
1070 float storeFlagPixel01 = 0.0; 1092 float storeFlagPixel01 = 0.0;
1071 float storeFlagPixel11 = 0.0; 1093 float storeFlagPixel11 = 0.0;
1072 float storeFlagPixel21 = 0.0; 1094 float storeFlagPixel21 = 0.0;
1073 float storeFlagPixel02 = 0.0; 1095 float storeFlagPixel02 = 0.0;
1074 float storeFlagPixel12 = 0.0; 1096 float storeFlagPixel12 = 0.0;
1075 1097
1076 vec2 et; 1098 vec2 et;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 storeFlagPixel11 += et.x; 1152 storeFlagPixel11 += et.x;
1131 storeFlagPixel11 += et.y; 1153 storeFlagPixel11 += et.y;
1132 storeFlagPixel21 += et.x; 1154 storeFlagPixel21 += et.x;
1133 storeFlagPixel12 += et.y; 1155 storeFlagPixel12 += et.y;
1134 } 1156 }
1135 1157
1136 gl_FragDepth = any(bvec4(outputEdges)) ? 1.0 : 0.0; 1158 gl_FragDepth = any(bvec4(outputEdges)) ? 1.0 : 0.0;
1137 1159
1138 if (gl_FragDepth != 0.0) { 1160 if (gl_FragDepth != 0.0) {
1139 if (storeFlagPixel00 != 0.0) 1161 if (storeFlagPixel00 != 0.0)
1140 imageStore(g_resultRGBATextureSlot1, screenPosI.xy + ivec2(0, 0), 1162 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(0, 0),
1141 pixel00); 1163 pixel00);
1142 if (storeFlagPixel10 != 0.0) 1164 if (storeFlagPixel10 != 0.0)
1143 imageStore(g_resultRGBATextureSlot1, screenPosI.xy + ivec2(1, 0), 1165 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(1, 0),
1144 pixel10); 1166 pixel10);
1145 if (storeFlagPixel20 != 0.0) 1167 if (storeFlagPixel20 != 0.0)
1146 imageStore(g_resultRGBATextureSlot1, screenPosI.xy + ivec2(2, 0), 1168 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(2, 0),
1147 pixel20); 1169 pixel20);
1148 if (storeFlagPixel01 != 0.0) 1170 if (storeFlagPixel01 != 0.0)
1149 imageStore(g_resultRGBATextureSlot1, screenPosI.xy + ivec2(0, 1), 1171 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(0, 1),
1150 pixel01); 1172 pixel01);
1151 if (storeFlagPixel02 != 0.0) 1173 if (storeFlagPixel02 != 0.0)
1152 imageStore(g_resultRGBATextureSlot1, screenPosI.xy + ivec2(0, 2), 1174 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(0, 2),
1153 pixel02); 1175 pixel02);
1154 if (storeFlagPixel11 != 0.0) 1176 if (storeFlagPixel11 != 0.0)
1155 imageStore(g_resultRGBATextureSlot1, screenPosI.xy + ivec2(1, 1), 1177 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(1, 1),
1156 pixel11); 1178 pixel11);
1157 if (storeFlagPixel21 != 0.0) 1179 if (storeFlagPixel21 != 0.0)
1158 imageStore(g_resultRGBATextureSlot1, screenPosI.xy + ivec2(2, 1), 1180 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(2, 1),
1159 pixel21); 1181 pixel21);
1160 if (storeFlagPixel12 != 0.0) 1182 if (storeFlagPixel12 != 0.0)
1161 imageStore(g_resultRGBATextureSlot1, screenPosI.xy + ivec2(1, 2), 1183 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy + ivec2(1, 2),
1162 pixel12); 1184 pixel12);
1163 } 1185 }
1164 outEdges = STORE_UVEC4(outputEdges); 1186 outEdges = STORE_UVEC4(outputEdges);
1165 } 1187 }
1166 \n#endif\n // DETECT_EDGES1 1188 \n#endif\n // DETECT_EDGES1
1167 1189
1168 vec2 UnpackThresholds(uint val) { 1190 vec2 UnpackThresholds(uint val) {
1169 return vec2(val & 0x0Fu, val >> 4u) / 15.0f; 1191 return vec2(val & 0x0Fu, val >> 4u) / 15.0f;
1170 } 1192 }
1171 1193
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 packedVals[(0) * 6 + (2)] = LOAD_UINT(packedQ3.x); 1278 packedVals[(0) * 6 + (2)] = LOAD_UINT(packedQ3.x);
1257 packedVals[(1) * 6 + (2)] = LOAD_UINT(packedQ3.y); 1279 packedVals[(1) * 6 + (2)] = LOAD_UINT(packedQ3.y);
1258 packedVals[(0) * 6 + (3)] = LOAD_UINT(packedQ3.z); 1280 packedVals[(0) * 6 + (3)] = LOAD_UINT(packedQ3.z);
1259 packedVals[(1) * 6 + (3)] = LOAD_UINT(packedQ3.w); 1281 packedVals[(1) * 6 + (3)] = LOAD_UINT(packedQ3.w);
1260 } 1282 }
1261 1283
1262 if (bool(packedVals[(2) * 6 + (2)])) { 1284 if (bool(packedVals[(2) * 6 + (2)])) {
1263 CollectEdges(2, 2, edges, packedVals); 1285 CollectEdges(2, 2, edges, packedVals);
1264 uint pe = PackEdge(PruneNonDominantEdges(edges)); 1286 uint pe = PackEdge(PruneNonDominantEdges(edges));
1265 if (pe != 0u) { 1287 if (pe != 0u) {
1266 imageStore(g_resultEdgeTexture, 2 * screenPosI.xy + ivec2(0, 0), 1288 imageStore(g_resultTexture, 2 * screenPosI.xy + ivec2(0, 0),
1267 vec4(float(0x80u | pe) / 255.0, 0, 0, 0)); 1289 vec4(float(0x80u | pe) / 255.0, 0, 0, 0));
1268 } 1290 }
1269 } 1291 }
1270 1292
1271 if (bool(packedVals[(3) * 6 + (2)]) || 1293 if (bool(packedVals[(3) * 6 + (2)]) ||
1272 bool(packedVals[(3) * 6 + (3)])) { 1294 bool(packedVals[(3) * 6 + (3)])) {
1273 UVEC4 packedQ5 = texelFetchOffset(g_src0Texture4Uint, 1295 UVEC4 packedQ5 = texelFetchOffset(g_src0Texture4Uint,
1274 screenPosI.xy, 0, ivec2(1, 0)); 1296 screenPosI.xy, 0, ivec2(1, 0));
1275 packedVals[(4) * 6 + (2)] = LOAD_UINT(packedQ5.x); 1297 packedVals[(4) * 6 + (2)] = LOAD_UINT(packedQ5.x);
1276 packedVals[(5) * 6 + (2)] = LOAD_UINT(packedQ5.y); 1298 packedVals[(5) * 6 + (2)] = LOAD_UINT(packedQ5.y);
1277 packedVals[(4) * 6 + (3)] = LOAD_UINT(packedQ5.z); 1299 packedVals[(4) * 6 + (3)] = LOAD_UINT(packedQ5.z);
1278 packedVals[(5) * 6 + (3)] = LOAD_UINT(packedQ5.w); 1300 packedVals[(5) * 6 + (3)] = LOAD_UINT(packedQ5.w);
1279 } 1301 }
1280 1302
1281 if (bool(packedVals[(3) * 6 + (2)])) { 1303 if (bool(packedVals[(3) * 6 + (2)])) {
1282 UVEC4 packedQ2 = texelFetchOffset(g_src0Texture4Uint, 1304 UVEC4 packedQ2 = texelFetchOffset(g_src0Texture4Uint,
1283 screenPosI.xy, 0, ivec2(1, -1)); 1305 screenPosI.xy, 0, ivec2(1, -1));
1284 packedVals[(4) * 6 + (0)] = LOAD_UINT(packedQ2.x); 1306 packedVals[(4) * 6 + (0)] = LOAD_UINT(packedQ2.x);
1285 packedVals[(5) * 6 + (0)] = LOAD_UINT(packedQ2.y); 1307 packedVals[(5) * 6 + (0)] = LOAD_UINT(packedQ2.y);
1286 packedVals[(4) * 6 + (1)] = LOAD_UINT(packedQ2.z); 1308 packedVals[(4) * 6 + (1)] = LOAD_UINT(packedQ2.z);
1287 packedVals[(5) * 6 + (1)] = LOAD_UINT(packedQ2.w); 1309 packedVals[(5) * 6 + (1)] = LOAD_UINT(packedQ2.w);
1288 1310
1289 CollectEdges(3, 2, edges, packedVals); 1311 CollectEdges(3, 2, edges, packedVals);
1290 uvec4 dominant_edges = PruneNonDominantEdges(edges); 1312 uvec4 dominant_edges = PruneNonDominantEdges(edges);
1291 // The rightmost edge of the texture is not edge. 1313 // The rightmost edge of the texture is not edge.
1292 // Note: texelFetch() on out of range gives an undefined value. 1314 // Note: texelFetch() on out of range gives an undefined value.
1293 uint pe = PackEdge(dominant_edges * uvec4(notTopRight.x, 1, 1, 1)); 1315 uint pe = PackEdge(dominant_edges * uvec4(notTopRight.x, 1, 1, 1));
1294 if (pe != 0u) { 1316 if (pe != 0u) {
1295 imageStore(g_resultEdgeTexture, 2 * screenPosI.xy + ivec2(1, 0), 1317 imageStore(g_resultTexture, 2 * screenPosI.xy + ivec2(1, 0),
1296 vec4(float(0x80u | pe) / 255.0, 0, 0, 0)); 1318 vec4(float(0x80u | pe) / 255.0, 0, 0, 0));
1297 } 1319 }
1298 } 1320 }
1299 1321
1300 if (bool(packedVals[(2) * 6 + (3)]) || 1322 if (bool(packedVals[(2) * 6 + (3)]) ||
1301 bool(packedVals[(3) * 6 + (3)])) { 1323 bool(packedVals[(3) * 6 + (3)])) {
1302 UVEC4 packedQ7 = texelFetchOffset(g_src0Texture4Uint, 1324 UVEC4 packedQ7 = texelFetchOffset(g_src0Texture4Uint,
1303 screenPosI.xy, 0, ivec2(0, 1)); 1325 screenPosI.xy, 0, ivec2(0, 1));
1304 packedVals[(2) * 6 + (4)] = LOAD_UINT(packedQ7.x); 1326 packedVals[(2) * 6 + (4)] = LOAD_UINT(packedQ7.x);
1305 packedVals[(3) * 6 + (4)] = LOAD_UINT(packedQ7.y); 1327 packedVals[(3) * 6 + (4)] = LOAD_UINT(packedQ7.y);
1306 packedVals[(2) * 6 + (5)] = LOAD_UINT(packedQ7.z); 1328 packedVals[(2) * 6 + (5)] = LOAD_UINT(packedQ7.z);
1307 packedVals[(3) * 6 + (5)] = LOAD_UINT(packedQ7.w); 1329 packedVals[(3) * 6 + (5)] = LOAD_UINT(packedQ7.w);
1308 } 1330 }
1309 1331
1310 if (bool(packedVals[(2) * 6 + (3)])) { 1332 if (bool(packedVals[(2) * 6 + (3)])) {
1311 UVEC4 packedQ6 = texelFetchOffset(g_src0Texture4Uint, 1333 UVEC4 packedQ6 = texelFetchOffset(g_src0Texture4Uint,
1312 screenPosI.xy, 0, ivec2(-1, -1)); 1334 screenPosI.xy, 0, ivec2(-1, -1));
1313 packedVals[(0) * 6 + (4)] = LOAD_UINT(packedQ6.x); 1335 packedVals[(0) * 6 + (4)] = LOAD_UINT(packedQ6.x);
1314 packedVals[(1) * 6 + (4)] = LOAD_UINT(packedQ6.y); 1336 packedVals[(1) * 6 + (4)] = LOAD_UINT(packedQ6.y);
1315 packedVals[(0) * 6 + (5)] = LOAD_UINT(packedQ6.z); 1337 packedVals[(0) * 6 + (5)] = LOAD_UINT(packedQ6.z);
1316 packedVals[(1) * 6 + (5)] = LOAD_UINT(packedQ6.w); 1338 packedVals[(1) * 6 + (5)] = LOAD_UINT(packedQ6.w);
1317 1339
1318 CollectEdges(2, 3, edges, packedVals); 1340 CollectEdges(2, 3, edges, packedVals);
1319 uvec4 dominant_edges = PruneNonDominantEdges(edges); 1341 uvec4 dominant_edges = PruneNonDominantEdges(edges);
1320 uint pe = PackEdge(dominant_edges * uvec4(1, notTopRight.y, 1, 1)); 1342 uint pe = PackEdge(dominant_edges * uvec4(1, notTopRight.y, 1, 1));
1321 if (pe != 0u) { 1343 if (pe != 0u) {
1322 imageStore(g_resultEdgeTexture, 2 * screenPosI.xy + ivec2(0, 1), 1344 imageStore(g_resultTexture, 2 * screenPosI.xy + ivec2(0, 1),
1323 vec4(float(0x80u | pe) / 255.0, 0, 0, 0)); 1345 vec4(float(0x80u | pe) / 255.0, 0, 0, 0));
1324 } 1346 }
1325 } 1347 }
1326 1348
1327 if (bool(packedVals[(3) * 6 + (3)])) { 1349 if (bool(packedVals[(3) * 6 + (3)])) {
1328 CollectEdges(3, 3, edges, packedVals); 1350 CollectEdges(3, 3, edges, packedVals);
1329 uvec4 dominant_edges = PruneNonDominantEdges(edges); 1351 uvec4 dominant_edges = PruneNonDominantEdges(edges);
1330 uint pe = PackEdge(dominant_edges * uvec4(notTopRight, 1, 1)); 1352 uint pe = PackEdge(dominant_edges * uvec4(notTopRight, 1, 1));
1331 if (pe != 0u) { 1353 if (pe != 0u) {
1332 imageStore(g_resultEdgeTexture, 2 * screenPosI.xy + ivec2(1, 1), 1354 imageStore(g_resultTexture, 2 * screenPosI.xy + ivec2(1, 1),
1333 vec4(float(0x80u | pe) / 255.0, 0, 0, 0)); 1355 vec4(float(0x80u | pe) / 255.0, 0, 0, 0));
1334 } 1356 }
1335 } 1357 }
1336 } 1358 }
1337 \n#endif\n // DETECT_EDGES2 1359 \n#endif\n // DETECT_EDGES2
1338 1360
1339 \n#ifdef COMBINE_EDGES\n 1361 \n#ifdef COMBINE_EDGES\n
1340 void CombineEdges() { 1362 void CombineEdges() {
1341 ivec3 screenPosIBase = ivec3(ivec2(gl_FragCoord.xy) * 2, 0); 1363 ivec3 screenPosIBase = ivec3(ivec2(gl_FragCoord.xy) * 2, 0);
1342 vec3 screenPosBase = vec3(screenPosIBase); 1364 vec3 screenPosBase = vec3(screenPosIBase);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 packedEdgesArray[(0 + 1) * 3 + (1 + 1)]); 1402 packedEdgesArray[(0 + 1) * 3 + (1 + 1)]);
1381 uvec4 pixelsU = uvec4(packedEdgesArray[(1 + 0) * 3 + (0 + 0)], 1403 uvec4 pixelsU = uvec4(packedEdgesArray[(1 + 0) * 3 + (0 + 0)],
1382 packedEdgesArray[(1 + 1) * 3 + (0 + 0)], 1404 packedEdgesArray[(1 + 1) * 3 + (0 + 0)],
1383 packedEdgesArray[(1 + 0) * 3 + (0 + 1)], 1405 packedEdgesArray[(1 + 0) * 3 + (0 + 1)],
1384 packedEdgesArray[(1 + 1) * 3 + (0 + 1)]); 1406 packedEdgesArray[(1 + 1) * 3 + (0 + 1)]);
1385 1407
1386 uvec4 outEdge4 = 1408 uvec4 outEdge4 =
1387 pixelsC | ((pixelsL & 0x01u) << 2u) | ((pixelsU & 0x02u) << 2u); 1409 pixelsC | ((pixelsL & 0x01u) << 2u) | ((pixelsU & 0x02u) << 2u);
1388 vec4 outEdge4Flt = vec4(outEdge4) / 255.0; 1410 vec4 outEdge4Flt = vec4(outEdge4) / 255.0;
1389 1411
1390 imageStore(g_resultEdgeTexture, screenPosIBase.xy + ivec2(0, 0), 1412 imageStore(g_resultTextureSlot2, screenPosIBase.xy + ivec2(0, 0),
1391 outEdge4Flt.xxxx); 1413 outEdge4Flt.xxxx);
1392 imageStore(g_resultEdgeTexture, screenPosIBase.xy + ivec2(1, 0), 1414 imageStore(g_resultTextureSlot2, screenPosIBase.xy + ivec2(1, 0),
1393 outEdge4Flt.yyyy); 1415 outEdge4Flt.yyyy);
1394 imageStore(g_resultEdgeTexture, screenPosIBase.xy + ivec2(0, 1), 1416 imageStore(g_resultTextureSlot2, screenPosIBase.xy + ivec2(0, 1),
1395 outEdge4Flt.zzzz); 1417 outEdge4Flt.zzzz);
1396 imageStore(g_resultEdgeTexture, screenPosIBase.xy + ivec2(1, 1), 1418 imageStore(g_resultTextureSlot2, screenPosIBase.xy + ivec2(1, 1),
1397 outEdge4Flt.wwww); 1419 outEdge4Flt.wwww);
1398 1420
1399 // uvec4 numberOfEdges4 = uvec4(bitCount(outEdge4)); 1421 // uvec4 numberOfEdges4 = uvec4(bitCount(outEdge4));
1400 // gl_FragDepth = 1422 // gl_FragDepth =
1401 // any(greaterThan(numberOfEdges4, uvec4(1))) ? 1.0 : 0.0; 1423 // any(greaterThan(numberOfEdges4, uvec4(1))) ? 1.0 : 0.0;
1402 1424
1403 gl_FragDepth = 1425 gl_FragDepth =
1404 any(greaterThan(outEdge4, uvec4(1))) ? 1.0 : 0.0; 1426 any(greaterThan(outEdge4, uvec4(1))) ? 1.0 : 0.0;
1405 } 1427 }
1406 \n#endif\n // COMBINE_EDGES 1428 \n#endif\n // COMBINE_EDGES
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 } 1662 }
1641 1663
1642 color /= fourWeightSum + 0.0001; 1664 color /= fourWeightSum + 0.0001;
1643 1665
1644 color = mix(color, pixelC, centerWeight / allWeightSum); 1666 color = mix(color, pixelC, centerWeight / allWeightSum);
1645 \n#ifdef IN_GAMMA_CORRECT_MODE\n 1667 \n#ifdef IN_GAMMA_CORRECT_MODE\n
1646 color.rgb = D3DX_FLOAT3_to_SRGB(color.rgb); 1668 color.rgb = D3DX_FLOAT3_to_SRGB(color.rgb);
1647 \n#endif\n 1669 \n#endif\n
1648 1670
1649 \n#ifdef DEBUG_OUTPUT_AAINFO\n 1671 \n#ifdef DEBUG_OUTPUT_AAINFO\n
1650 imageStore(g_resultEdgeTexture, screenPosI.xy, 1672 imageStore(g_resultTextureSlot2, screenPosI.xy,
1651 PackBlurAAInfo(screenPosI.xy, numberOfEdges)); 1673 PackBlurAAInfo(screenPosI.xy, numberOfEdges));
1652 \n#endif\n 1674 \n#endif\n
1653 imageStore(g_resultRGBATextureSlot1, screenPosI.xy, color); 1675 imageStore(g_resultTextureFlt4Slot1, screenPosI.xy, color);
1654 1676
1655 if (numberOfEdges == 2u) { 1677 if (numberOfEdges == 2u) {
1656 uint packedEdgesL = packedEdgesArray[(0 + _x) * 4 + (1 + _y)]; 1678 uint packedEdgesL = packedEdgesArray[(0 + _x) * 4 + (1 + _y)];
1657 uint packedEdgesB = packedEdgesArray[(1 + _x) * 4 + (0 + _y)]; 1679 uint packedEdgesB = packedEdgesArray[(1 + _x) * 4 + (0 + _y)];
1658 uint packedEdgesR = packedEdgesArray[(2 + _x) * 4 + (1 + _y)]; 1680 uint packedEdgesR = packedEdgesArray[(2 + _x) * 4 + (1 + _y)];
1659 uint packedEdgesT = packedEdgesArray[(1 + _x) * 4 + (2 + _y)]; 1681 uint packedEdgesT = packedEdgesArray[(1 + _x) * 4 + (2 + _y)];
1660 1682
1661 bool isHorizontalA = ((packedEdgesC) == (0x01u | 0x02u)) && 1683 bool isHorizontalA = ((packedEdgesC) == (0x01u | 0x02u)) &&
1662 ((packedEdgesR & 0x08u) == 0x08u); 1684 ((packedEdgesR & 0x08u) == 0x08u);
1663 bool isHorizontalB = ((packedEdgesC) == (0x01u | 0x08u)) && 1685 bool isHorizontalB = ((packedEdgesC) == (0x01u | 0x08u)) &&
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1853 CombineEdges(); 1875 CombineEdges();
1854 \n#endif\n 1876 \n#endif\n
1855 \n#if defined BLUR_EDGES\n 1877 \n#if defined BLUR_EDGES\n
1856 BlurEdges(); 1878 BlurEdges();
1857 \n#endif\n 1879 \n#endif\n
1858 \n#if defined DISPLAY_EDGES\n 1880 \n#if defined DISPLAY_EDGES\n
1859 DisplayEdges(); 1881 DisplayEdges();
1860 \n#endif\n 1882 \n#endif\n
1861 } 1883 }
1862 ); 1884 );
1885
1886 const char
1887 ApplyFramebufferAttachmentCMAAINTELResourceManager::copy_frag_str_[] =
1888 SHADER(
1889 precision highp float;
1890 layout(binding = 0) uniform highp sampler2D inTexture;
1891 layout(location = 0) out vec4 outColor;
1892 \n#ifdef GL_ES\n
1893 layout(binding = 0, rgba8) restrict writeonly uniform highp
1894 image2D outTexture;
1895 \n#else\n
1896 layout(rgba8) restrict writeonly uniform highp image2D outTexture;
1897 \n#endif\n
1898
1899 void main() {
1900 ivec2 screenPosI = ivec2( gl_FragCoord.xy );
1901 vec4 pixel = texelFetch(inTexture, screenPosI, 0);
1902 \n#ifdef OUT_FBO\n
1903 outColor = pixel;
1904 \n#else\n
1905 imageStore(outTexture, screenPosI, pixel);
1906 \n#endif\n
1907 }
1908 );
1863 /* clang-format on */ 1909 /* clang-format on */
1864 1910
1865 } // namespace gles2 1911 } // namespace gles2
1866 } // namespace gpu 1912 } // 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