Index: gpu/command_buffer/service/gles2_cmd_apply_framebuffer_attachment_cmaa_intel.cc |
diff --git a/gpu/command_buffer/service/gles2_cmd_apply_framebuffer_attachment_cmaa_intel.cc b/gpu/command_buffer/service/gles2_cmd_apply_framebuffer_attachment_cmaa_intel.cc |
index ab7965ae849f0052f7919c96b9450e69c70b5abd..4b9d7e437bde796ed1b568e30b64fe439dd21b5b 100644 |
--- a/gpu/command_buffer/service/gles2_cmd_apply_framebuffer_attachment_cmaa_intel.cc |
+++ b/gpu/command_buffer/service/gles2_cmd_apply_framebuffer_attachment_cmaa_intel.cc |
@@ -25,6 +25,7 @@ |
is_in_gamma_correct_mode_(false), |
supports_usampler_(true), |
supports_r8_image_(true), |
+ supports_r8_read_format_(true), |
is_gles31_compatible_(false), |
frame_id_(0), |
width_(0), |
@@ -58,55 +59,67 @@ |
is_gles31_compatible_ = |
decoder->GetGLContext()->GetVersionInfo()->IsAtLeastGLES(3, 1); |
- if (is_gles31_compatible_) { |
- supports_r8_image_ = |
- decoder->GetGLContext()->HasExtension("GL_NV_image_formats"); |
- |
- // ES 3.0 requires GL_RGBA8UI is color renderable. |
- supports_usampler_ = true; |
- } else { |
- // CMAA requires GL_ARB_shader_image_load_store for GL, and it requires r8 |
- // image texture. |
- DCHECK(decoder->GetGLContext()->HasExtension( |
- "GL_ARB_shader_image_load_store")); |
- supports_r8_image_ = true; |
- |
- // Check if RGBA8UI is supported as an FBO colour target with depth. |
- // If not supported, GLSL needs to convert the data to/from float so there |
- // is a small extra cost. |
- { |
- glActiveTexture(GL_TEXTURE0); |
- |
- GLuint rgba8ui_texture = 0, depth_texture = 0; |
- glGenTextures(1, &rgba8ui_texture); |
- glBindTexture(GL_TEXTURE_2D, rgba8ui_texture); |
- glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8UI, 4, 4); |
- |
- glGenTextures(1, &depth_texture); |
- glBindTexture(GL_TEXTURE_2D, depth_texture); |
- glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT16, 4, 4); |
- |
- // Create the FBO |
- GLuint rgba8ui_framebuffer = 0; |
- glGenFramebuffersEXT(1, &rgba8ui_framebuffer); |
- glBindFramebufferEXT(GL_FRAMEBUFFER, rgba8ui_framebuffer); |
- |
- // Bind to the FBO to test support |
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
- GL_TEXTURE_2D, rgba8ui_texture, 0); |
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, |
- GL_TEXTURE_2D, depth_texture, 0); |
- GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
- |
- supports_usampler_ = (status == GL_FRAMEBUFFER_COMPLETE); |
- |
- glDeleteFramebuffersEXT(1, &rgba8ui_framebuffer); |
- glDeleteTextures(1, &rgba8ui_texture); |
- glDeleteTextures(1, &depth_texture); |
- |
- decoder->RestoreTextureUnitBindings(0); |
- decoder->RestoreActiveTexture(); |
- decoder->RestoreFramebufferBindings(); |
+ // Check if RGBA8UI is supported as an FBO colour target with depth. |
+ // If not supported, GLSL needs to convert the data to/from float so there is |
+ // a small extra cost. |
+ { |
+ GLuint rgba8ui_texture = 0, depth_texture = 0; |
+ glGenTextures(1, &rgba8ui_texture); |
+ glBindTexture(GL_TEXTURE_2D, rgba8ui_texture); |
+ glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8UI, 4, 4); |
+ |
+ glGenTextures(1, &depth_texture); |
+ glBindTexture(GL_TEXTURE_2D, depth_texture); |
+ glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT16, 4, 4); |
+ |
+ // Create the FBO |
+ GLuint rgba8ui_framebuffer = 0; |
+ glGenFramebuffersEXT(1, &rgba8ui_framebuffer); |
+ glBindFramebufferEXT(GL_FRAMEBUFFER, rgba8ui_framebuffer); |
+ |
+ // Bind to the FBO to test support |
+ glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
+ GL_TEXTURE_2D, rgba8ui_texture, 0); |
+ glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, |
+ GL_TEXTURE_2D, depth_texture, 0); |
+ GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
+ |
+ supports_usampler_ = (status == GL_FRAMEBUFFER_COMPLETE); |
+ |
+ glDeleteFramebuffersEXT(1, &rgba8ui_framebuffer); |
+ glDeleteTextures(1, &rgba8ui_texture); |
+ glDeleteTextures(1, &depth_texture); |
+ } |
+ |
+ // Check to see if R8 images are supported |
+ // If not supported, images are bound as R32F for write targets, not R8. |
+ { |
+ GLuint r8_texture = 0; |
+ glGenTextures(1, &r8_texture); |
+ glBindTexture(GL_TEXTURE_2D, r8_texture); |
+ glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_R8, 4, 4); |
+ |
+ glGetError(); // reset all previous errors |
+ glBindImageTextureEXT(0, r8_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R8); |
+ if (glGetError() != GL_NO_ERROR) |
+ supports_r8_image_ = false; |
+ |
+ glDeleteTextures(1, &r8_texture); |
+ } |
+ |
+ // Check if R8 GLSL read formats are supported. |
+ // If not supported, r32f is used instead. |
+ { |
+ const char shader_source[] = |
+ SHADER(layout(r8) restrict writeonly uniform highp image2D g_r8Image; |
+ void main() { |
+ imageStore(g_r8Image, ivec2(0, 0), vec4(1.0, 0.0, 0.0, 0.0)); |
+ }); |
+ |
+ GLuint shader = CreateShader(GL_FRAGMENT_SHADER, "", shader_source); |
+ supports_r8_read_format_ = (shader != 0); |
+ if (shader != 0) { |
+ glDeleteShader(shader); |
} |
} |
@@ -115,6 +128,9 @@ |
VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: " |
<< "Supports R8 Images is " |
<< (supports_r8_image_ ? "true" : "false"); |
+ VLOG(1) << "ApplyFramebufferAttachmentCMAAINTEL: " |
+ << "Supports R8 Read Format is " |
+ << (supports_r8_read_format_ ? "true" : "false"); |
// Create the shaders |
std::ostringstream defines, edge1, edge2, combineEdges, blur, displayEdges, |
@@ -132,7 +148,7 @@ |
defines << "#define IN_GAMMA_CORRECT_MODE\n"; |
} |
- if (supports_r8_image_) { |
+ if (supports_r8_read_format_) { |
defines << "#define EDGE_READ_FORMAT r8\n"; |
} else { |
defines << "#define EDGE_READ_FORMAT r32f\n"; |
@@ -613,7 +629,7 @@ |
const char header_es31[] = |
"#version 310 es \n"; |
- const char header_gl130[] = |
+ const char header_gl30[] = |
"#version 130 \n" |
"#extension GL_ARB_shading_language_420pack : require \n" |
"#extension GL_ARB_texture_gather : require \n" |
@@ -621,16 +637,14 @@ |
"#extension GL_ARB_explicit_attrib_location : require \n" |
"#extension GL_ARB_shader_image_load_store : require \n"; |
- std::ostringstream header; |
+ const char* header = NULL; |
if (is_gles31_compatible_) { |
- header << header_es31; |
- if (supports_r8_image_) |
- header << "#extension GL_NV_image_formats : require\n"; |
+ header = header_es31; |
} else { |
- header << header_gl130; |
+ header = header_gl30; |
} |
- const char* source_array[4] = {header.str().c_str(), defines, "\n", source}; |
+ const char* source_array[4] = {header, defines, "\n", source}; |
glShaderSource(shader, 4, source_array, NULL); |
glCompileShader(shader); |