Skip to content

Commit

Permalink
Implement EXT_draw_buffers WebGL extention support in command buffer.
Browse files Browse the repository at this point in the history
A few things:
1) I only hooked up with desktop GL backend, i.e., GL_ARB_draw_buffers. Will add GLES support later.
2) Probably we need to do something to enable this for Pepper3D also? If yes, will do so in a seperate CL.
3) I didn't add the wordarounds for Mac/Linux driver bugs. Will do so in a seperate CL.

BUG=180397
TEST=gpu_unittests, webgl conformance tests
Review URL: https://codereview.chromium.org/12545014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188129 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
zmo@chromium.org committed Mar 14, 2013
1 parent 0e2f425 commit 2f143d4
Show file tree
Hide file tree
Showing 39 changed files with 687 additions and 48 deletions.
3 changes: 3 additions & 0 deletions cc/fake_web_graphics_context_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,9 @@ class CC_EXPORT FakeWebGraphicsContext3D :

virtual void loseContextCHROMIUM(WebKit::WGC3Denum current,
WebKit::WGC3Denum other);

virtual void drawBuffersEXT(WebKit::WGC3Dsizei m,
const WebKit::WGC3Denum* bufs) {}
};

} // namespace cc
Expand Down
33 changes: 19 additions & 14 deletions cc/test/test_web_graphics_context_3d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
#include "third_party/khronos/GLES2/gl2ext.h"

using WebKit::WGC3Dboolean;
using WebKit::WGC3Dchar;
using WebKit::WGC3Denum;
using WebKit::WGC3Dint;
using WebKit::WGC3Dsizei;
using WebKit::WGC3Dsizeiptr;
using WebKit::WGC3Duint;
using WebKit::WebGLId;
using WebKit::WebGraphicsContext3D;

Expand Down Expand Up @@ -121,14 +126,14 @@ WebKit::WebString TestWebGraphicsContext3D::getString(WGC3Denum name) {
return WebKit::WebString::fromUTF8(string.c_str());
}

WebKit::WGC3Dint TestWebGraphicsContext3D::getUniformLocation(
WGC3Dint TestWebGraphicsContext3D::getUniformLocation(
WebGLId program,
const WebKit::WGC3Dchar* name) {
const WGC3Dchar* name) {
return 0;
}

WebKit::WGC3Dsizeiptr TestWebGraphicsContext3D::getVertexAttribOffset(
WebKit::WGC3Duint index,
WGC3Dsizeiptr TestWebGraphicsContext3D::getVertexAttribOffset(
WGC3Duint index,
WGC3Denum pname) {
return 0;
}
Expand Down Expand Up @@ -172,39 +177,39 @@ WebGLId TestWebGraphicsContext3D::createBuffer() {
return kBufferId | context_id_ << 16;
}

void TestWebGraphicsContext3D::deleteBuffer(WebKit::WebGLId id) {
void TestWebGraphicsContext3D::deleteBuffer(WebGLId id) {
EXPECT_EQ(kBufferId | context_id_ << 16, id);
}

WebGLId TestWebGraphicsContext3D::createFramebuffer() {
return kFramebufferId | context_id_ << 16;
}

void TestWebGraphicsContext3D::deleteFramebuffer(WebKit::WebGLId id) {
void TestWebGraphicsContext3D::deleteFramebuffer(WebGLId id) {
EXPECT_EQ(kFramebufferId | context_id_ << 16, id);
}

WebGLId TestWebGraphicsContext3D::createProgram() {
return kProgramId | context_id_ << 16;
}

void TestWebGraphicsContext3D::deleteProgram(WebKit::WebGLId id) {
void TestWebGraphicsContext3D::deleteProgram(WebGLId id) {
EXPECT_EQ(kProgramId | context_id_ << 16, id);
}

WebGLId TestWebGraphicsContext3D::createRenderbuffer() {
return kRenderbufferId | context_id_ << 16;
}

void TestWebGraphicsContext3D::deleteRenderbuffer(WebKit::WebGLId id) {
void TestWebGraphicsContext3D::deleteRenderbuffer(WebGLId id) {
EXPECT_EQ(kRenderbufferId | context_id_ << 16, id);
}

WebGLId TestWebGraphicsContext3D::createShader(WGC3Denum) {
return kShaderId | context_id_ << 16;
}

void TestWebGraphicsContext3D::deleteShader(WebKit::WebGLId id) {
void TestWebGraphicsContext3D::deleteShader(WebGLId id) {
EXPECT_EQ(kShaderId | context_id_ << 16, id);
}

Expand Down Expand Up @@ -271,7 +276,7 @@ void TestWebGraphicsContext3D::bindTexture(
used_textures_.insert(texture_id);
}

void TestWebGraphicsContext3D::endQueryEXT(WebKit::WGC3Denum target) {
void TestWebGraphicsContext3D::endQueryEXT(WGC3Denum target) {
if (times_end_query_succeeds_ >= 0) {
if (!times_end_query_succeeds_) {
loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
Expand All @@ -282,9 +287,9 @@ void TestWebGraphicsContext3D::endQueryEXT(WebKit::WGC3Denum target) {
}

void TestWebGraphicsContext3D::getQueryObjectuivEXT(
WebKit::WebGLId query,
WebKit::WGC3Denum pname,
WebKit::WGC3Duint* params) {
WebGLId query,
WGC3Denum pname,
WGC3Duint* params) {
// If the context is lost, behave as if result is available.
if (pname == GL_QUERY_RESULT_AVAILABLE_EXT)
*params = 1;
Expand All @@ -308,7 +313,7 @@ void TestWebGraphicsContext3D::loseContextCHROMIUM(WGC3Denum current,
shared_contexts_.clear();
}

WebKit::WebGLId TestWebGraphicsContext3D::NextTextureId() {
WebGLId TestWebGraphicsContext3D::NextTextureId() {
WebGLId texture_id = next_texture_id_++;
DCHECK(texture_id < (1 << 16));
texture_id |= context_id_ << 16;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,12 @@ void WebGraphicsContext3DCommandBufferImpl::waitAsyncTexImage2DCHROMIUM(
return gl_->WaitAsyncTexImage2DCHROMIUM(target);
}

void WebGraphicsContext3DCommandBufferImpl::drawBuffersEXT(
WGC3Dsizei n,
const WGC3Denum* bufs) {
gl_->DrawBuffersEXT(n, bufs);
}

GrGLInterface* WebGraphicsContext3DCommandBufferImpl::onCreateGrGLInterface() {
return webkit::gpu::CreateCommandBufferSkiaGLBinding();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,11 @@ class WebGraphicsContext3DCommandBufferImpl
const void* pixels);
virtual void waitAsyncTexImage2DCHROMIUM(WGC3Denum target);

// GL_EXT_draw_buffers
virtual void drawBuffersEXT(
WGC3Dsizei n,
const WGC3Denum* bufs);

protected:
virtual GrGLInterface* onCreateGrGLInterface();

Expand Down
1 change: 1 addition & 0 deletions gpu/GLES2/gl2chromium_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
#define glLoseContextCHROMIUM GLES2_GET_FUN(LoseContextCHROMIUM)
#define glInsertSyncPointCHROMIUM GLES2_GET_FUN(InsertSyncPointCHROMIUM)
#define glWaitSyncPointCHROMIUM GLES2_GET_FUN(WaitSyncPointCHROMIUM)
#define glDrawBuffersEXT GLES2_GET_FUN(DrawBuffersEXT)

#endif // GPU_GLES2_GL2CHROMIUM_AUTOGEN_H_

119 changes: 119 additions & 0 deletions gpu/GLES2/gl2extchromium.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,125 @@ typedef void (GL_APIENTRYP PFNGLBLITFRAMEBUFFEREXTPROC) (
GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
#endif /* GL_EXT_framebuffer_blit */

/* GL_EXT_draw_buffers */
#ifndef GL_EXT_draw_buffers
#define GL_EXT_draw_buffers 1

#ifdef GL_GLEXT_PROTOTYPES
GL_APICALL void GL_APIENTRY glDrawBuffersEXT(
GLsizei n, const GLenum* bufs);
#endif
typedef void (GL_APIENTRYP PFNGLDRAWBUFFERSEXTPROC) (
GLsizei n, const GLenum* bufs);

#ifndef GL_COLOR_ATTACHMENT0_EXT
#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
#endif
#ifndef GL_COLOR_ATTACHMENT1_EXT
#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1
#endif
#ifndef GL_COLOR_ATTACHMENT2_EXT
#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2
#endif
#ifndef GL_COLOR_ATTACHMENT3_EXT
#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3
#endif
#ifndef GL_COLOR_ATTACHMENT4_EXT
#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4
#endif
#ifndef GL_COLOR_ATTACHMENT5_EXT
#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5
#endif
#ifndef GL_COLOR_ATTACHMENT6_EXT
#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6
#endif
#ifndef GL_COLOR_ATTACHMENT7_EXT
#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7
#endif
#ifndef GL_COLOR_ATTACHMENT8_EXT
#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8
#endif
#ifndef GL_COLOR_ATTACHMENT9_EXT
#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9
#endif
#ifndef GL_COLOR_ATTACHMENT10_EXT
#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA
#endif
#ifndef GL_COLOR_ATTACHMENT11_EXT
#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB
#endif
#ifndef GL_COLOR_ATTACHMENT12_EXT
#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC
#endif
#ifndef GL_COLOR_ATTACHMENT13_EXT
#define GL_COLOR_ATTACHMENT13_EXT 0x8CED
#endif
#ifndef GL_COLOR_ATTACHMENT14_EXT
#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE
#endif
#ifndef GL_COLOR_ATTACHMENT15_EXT
#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF
#endif

#ifndef GL_DRAW_BUFFER0_EXT
#define GL_DRAW_BUFFER0_EXT 0x8825
#endif
#ifndef GL_DRAW_BUFFER1_EXT
#define GL_DRAW_BUFFER1_EXT 0x8826
#endif
#ifndef GL_DRAW_BUFFER2_EXT
#define GL_DRAW_BUFFER2_EXT 0x8827
#endif
#ifndef GL_DRAW_BUFFER3_EXT
#define GL_DRAW_BUFFER3_EXT 0x8828
#endif
#ifndef GL_DRAW_BUFFER4_EXT
#define GL_DRAW_BUFFER4_EXT 0x8829
#endif
#ifndef GL_DRAW_BUFFER5_EXT
#define GL_DRAW_BUFFER5_EXT 0x882A
#endif
#ifndef GL_DRAW_BUFFER6_EXT
#define GL_DRAW_BUFFER6_EXT 0x882B
#endif
#ifndef GL_DRAW_BUFFER7_EXT
#define GL_DRAW_BUFFER7_EXT 0x882C
#endif
#ifndef GL_DRAW_BUFFER8_EXT
#define GL_DRAW_BUFFER8_EXT 0x882D
#endif
#ifndef GL_DRAW_BUFFER9_EXT
#define GL_DRAW_BUFFER9_EXT 0x882E
#endif
#ifndef GL_DRAW_BUFFER10_EXT
#define GL_DRAW_BUFFER10_EXT 0x882F
#endif
#ifndef GL_DRAW_BUFFER11_EXT
#define GL_DRAW_BUFFER11_EXT 0x8830
#endif
#ifndef GL_DRAW_BUFFER12_EXT
#define GL_DRAW_BUFFER12_EXT 0x8831
#endif
#ifndef GL_DRAW_BUFFER13_EXT
#define GL_DRAW_BUFFER13_EXT 0x8832
#endif
#ifndef GL_DRAW_BUFFER14_EXT
#define GL_DRAW_BUFFER14_EXT 0x8833
#endif
#ifndef GL_DRAW_BUFFER15_EXT
#define GL_DRAW_BUFFER15_EXT 0x8834
#endif

#ifndef GL_MAX_COLOR_ATTACHMENTS_EXT
#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF
#endif

#ifndef GL_MAX_DRAW_BUFFERS_EXT
#define GL_MAX_DRAW_BUFFERS_EXT 0x8824
#endif

#endif /* GL_EXT_draw_buffers */

/* GL_CHROMIUM_resize */
#ifndef GL_CHROMIUM_resize
#define GL_CHROMIUM_resize 1
Expand Down
28 changes: 22 additions & 6 deletions gpu/command_buffer/build_gles2_cmd_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2152,6 +2152,15 @@
'pepper_interface': 'InstancedArrays',
'defer_draws': True,
},
'DrawBuffersEXT': {
'type': 'PUTn',
'decoder_func': 'DoDrawBuffersEXT',
'data_type': 'GLenum',
'count': 1,
'client_test': False,
'unit_test': False,
'extension': True,
},
'DrawElementsInstancedANGLE': {
'type': 'Manual',
'cmd_args': 'GLenumDrawMode mode, GLsizei count, '
Expand Down Expand Up @@ -4927,11 +4936,11 @@ def WriteGLES2ImplementationUnitTest(self, func, file):
TEST_F(GLES2ImplementationTest, %(name)s) {
struct Cmds {
cmds::%(name)sImmediate cmd;
%(type)s data[2][%(count)d];
%(type)s data[%(count_param)d][%(count)d];
};
Cmds expected;
for (int ii = 0; ii < 2; ++ii) {
for (int ii = 0; ii < %(count_param)d; ++ii) {
for (int jj = 0; jj < %(count)d; ++jj) {
expected.data[ii][jj] = static_cast<%(type)s>(ii * %(count)d + jj);
}
Expand All @@ -4945,14 +4954,18 @@ def WriteGLES2ImplementationUnitTest(self, func, file):
for count, arg in enumerate(func.GetCmdArgs()[0:-2]):
cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func, count, 0))
gl_arg_strings = []
count_param = 0
for count, arg in enumerate(func.GetOriginalArgs()[0:-1]):
gl_arg_strings.append(arg.GetValidClientSideArg(func, count, 0))
if arg.name == "count":
count_param = int(arg.GetValidClientSideArg(func, count, 0))
file.Write(code % {
'name': func.name,
'type': func.GetInfo('data_type'),
'count': func.GetInfo('count'),
'args': ", ".join(gl_arg_strings),
'cmd_args': ", ".join(cmd_arg_strings),
'count_param': count_param,
})

def WriteImmediateCmdComputeSize(self, func, file):
Expand Down Expand Up @@ -5028,26 +5041,29 @@ def WriteImmediateCmdHelper(self, func, file):

def WriteImmediateFormatTest(self, func, file):
"""Overrriden from TypeHandler."""
args = func.GetCmdArgs()
count_param = 0
for value, arg in enumerate(args):
if arg.name == "count":
count_param = int(arg.GetValidClientSideArg(func, value, 0))
file.Write("TEST_F(GLES2FormatTest, %s) {\n" % func.name)
file.Write(" const int kSomeBaseValueToTestWith = 51;\n")
file.Write(" static %s data[] = {\n" % func.info.data_type)
for v in range(0, func.info.count * 2):
for v in range(0, func.info.count * count_param):
file.Write(" static_cast<%s>(kSomeBaseValueToTestWith + %d),\n" %
(func.info.data_type, v))
file.Write(" };\n")
file.Write(" cmds::%s& cmd = *GetBufferAs<cmds::%s>();\n" %
(func.name, func.name))
file.Write(" const GLsizei kNumElements = 2;\n")
file.Write(" const GLsizei kNumElements = %d;\n" % count_param)
file.Write(" const size_t kExpectedCmdSize =\n")
file.Write(" sizeof(cmd) + kNumElements * sizeof(%s) * %d;\n" %
(func.info.data_type, func.info.count))
file.Write(" void* next_cmd = cmd.Set(\n")
file.Write(" &cmd")
args = func.GetCmdArgs()
for value, arg in enumerate(args):
file.Write(",\n static_cast<%s>(%d)" % (arg.type, value + 1))
file.Write(",\n data);\n")
args = func.GetCmdArgs()
file.Write(" EXPECT_EQ(static_cast<uint32>(cmds::%s::kCmdId),\n" %
func.name)
file.Write(" cmd.header.command);\n")
Expand Down
5 changes: 5 additions & 0 deletions gpu/command_buffer/client/gles2_c_lib_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,9 @@ GLuint GLES2InsertSyncPointCHROMIUM() {
void GLES2WaitSyncPointCHROMIUM(GLuint sync_point) {
gles2::GetGLContext()->WaitSyncPointCHROMIUM(sync_point);
}
void GLES2DrawBuffersEXT(GLsizei count, const GLenum* bufs) {
gles2::GetGLContext()->DrawBuffersEXT(count, bufs);
}

namespace gles2 {

Expand Down Expand Up @@ -1069,6 +1072,8 @@ NameToFunc g_gles2_function_table[] = {
glInsertSyncPointCHROMIUM), },
{ "glWaitSyncPointCHROMIUM", reinterpret_cast<GLES2FunctionPointer>(
glWaitSyncPointCHROMIUM), },
{ "glDrawBuffersEXT", reinterpret_cast<GLES2FunctionPointer>(
glDrawBuffersEXT), },
{ NULL, NULL, },
};

Expand Down
Loading

0 comments on commit 2f143d4

Please sign in to comment.