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

Side by Side Diff: gpu/command_buffer/client/gles2_implementation_unittest.cc

Issue 7633060: Add option to not generate resources on bind in OpenGL ES (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nacl fix Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Tests for the Command Buffer Helper. 5 // Tests for the Command Buffer Helper.
6 6
7 #include "gpu/command_buffer/client/gles2_implementation.h" 7 #include "gpu/command_buffer/client/gles2_implementation.h"
8 8
9 #include <GLES2/gl2ext.h> 9 #include <GLES2/gl2ext.h>
10 #include "gpu/command_buffer/common/command_buffer.h" 10 #include "gpu/command_buffer/common/command_buffer.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 MOCK_METHOD1(OnFlush, void(void* result)); 123 MOCK_METHOD1(OnFlush, void(void* result));
124 }; 124 };
125 125
126 // GCC requires these declarations, but MSVC requires they not be present 126 // GCC requires these declarations, but MSVC requires they not be present
127 #ifndef _MSC_VER 127 #ifndef _MSC_VER
128 const int32 GLES2MockCommandBufferHelper::kTransferBufferId; 128 const int32 GLES2MockCommandBufferHelper::kTransferBufferId;
129 #endif 129 #endif
130 130
131 namespace gles2 { 131 namespace gles2 {
132 132
133 using testing::_;
134 using testing::DoAll;
135 using testing::InSequence;
136 using testing::Invoke;
137 using testing::Mock;
138 using testing::Sequence;
139 using testing::Truly;
133 using testing::Return; 140 using testing::Return;
134 using testing::Mock;
135 using testing::Truly;
136 using testing::Sequence;
137 using testing::DoAll;
138 using testing::Invoke;
139 using testing::_;
140 141
141 ACTION_P(SetMemory, obj) { 142 ACTION_P(SetMemory, obj) {
142 memcpy(arg0, &obj, sizeof(obj)); 143 memcpy(arg0, &obj, sizeof(obj));
143 } 144 }
144 145
145 ACTION_P2(SetMemoryAtOffset, offset, obj) { 146 ACTION_P2(SetMemoryAtOffset, offset, obj) {
146 memcpy(static_cast<char*>(arg0) + offset, &obj, sizeof(obj)); 147 memcpy(static_cast<char*>(arg0) + offset, &obj, sizeof(obj));
147 } 148 }
148 149
149 ACTION_P3(SetMemoryAtOffsetFromArray, offset, array, size) { 150 ACTION_P3(SetMemoryAtOffsetFromArray, offset, array, size) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 static const GLint kMaxFragmentUniformVectors = 16; 202 static const GLint kMaxFragmentUniformVectors = 16;
202 static const GLint kMaxRenderbufferSize = 64; 203 static const GLint kMaxRenderbufferSize = 64;
203 static const GLint kMaxTextureImageUnits = 8; 204 static const GLint kMaxTextureImageUnits = 8;
204 static const GLint kMaxTextureSize = 128; 205 static const GLint kMaxTextureSize = 128;
205 static const GLint kMaxVaryingVectors = 8; 206 static const GLint kMaxVaryingVectors = 8;
206 static const GLint kMaxVertexAttribs = 8; 207 static const GLint kMaxVertexAttribs = 8;
207 static const GLint kMaxVertexTextureImageUnits = 0; 208 static const GLint kMaxVertexTextureImageUnits = 0;
208 static const GLint kMaxVertexUniformVectors = 128; 209 static const GLint kMaxVertexUniformVectors = 128;
209 static const GLint kNumCompressedTextureFormats = 0; 210 static const GLint kNumCompressedTextureFormats = 0;
210 static const GLint kNumShaderBinaryFormats = 0; 211 static const GLint kNumShaderBinaryFormats = 0;
212 static const GLuint kStartId = 1024;
211 213
212 GLES2ImplementationTest() 214 GLES2ImplementationTest()
213 : commands_(NULL), 215 : commands_(NULL),
214 token_(0), 216 token_(0),
215 offset_(0) { 217 offset_(0) {
216 } 218 }
217 219
218 virtual void SetUp() { 220 virtual void SetUp() {
221 Initialize(false, true);
222 }
223
224 virtual void TearDown() {
225 }
226
227 void Initialize(bool shared_resources, bool bind_generates_resource) {
219 offset_ = GLES2Implementation::kStartingOffset; 228 offset_ = GLES2Implementation::kStartingOffset;
220 229
221 command_buffer_.reset(new MockGLES2CommandBuffer()); 230 command_buffer_.reset(new MockGLES2CommandBuffer());
222 command_buffer_->Initialize(kCommandBufferSizeBytes); 231 command_buffer_->Initialize(kCommandBufferSizeBytes);
223 232
224 EXPECT_EQ(kTransferBufferId, 233 EXPECT_EQ(kTransferBufferId,
225 command_buffer_->CreateTransferBuffer(kTransferBufferSize, -1)); 234 command_buffer_->CreateTransferBuffer(kTransferBufferSize, -1));
226 transfer_buffer_ = command_buffer_->GetTransferBuffer(kTransferBufferId); 235 transfer_buffer_ = command_buffer_->GetTransferBuffer(kTransferBufferId);
227 ClearTransferBuffer(); 236 ClearTransferBuffer();
228 237
(...skipping 13 matching lines...) Expand all
242 state.max_vertex_uniform_vectors = kMaxVertexUniformVectors; 251 state.max_vertex_uniform_vectors = kMaxVertexUniformVectors;
243 state.num_compressed_texture_formats = kNumCompressedTextureFormats; 252 state.num_compressed_texture_formats = kNumCompressedTextureFormats;
244 state.num_shader_binary_formats = kNumShaderBinaryFormats; 253 state.num_shader_binary_formats = kNumShaderBinaryFormats;
245 254
246 // This just happens to work for now because GLState has 1 GLint per 255 // This just happens to work for now because GLState has 1 GLint per
247 // state. If GLState gets more complicated this code will need to get 256 // state. If GLState gets more complicated this code will need to get
248 // more complicated. 257 // more complicated.
249 AllocateTransferBuffer(sizeof(state)); // in 258 AllocateTransferBuffer(sizeof(state)); // in
250 uint32 offset = AllocateTransferBuffer(sizeof(state)); // out 259 uint32 offset = AllocateTransferBuffer(sizeof(state)); // out
251 260
252 EXPECT_CALL(*command_buffer_, OnFlush(_)) 261 {
253 .WillOnce(SetMemoryAtOffset(offset, state)) 262 InSequence sequence;
254 .RetiresOnSaturation();
255 GetNextToken(); // eat the token that starting up will use.
256 263
257 gl_.reset(new GLES2Implementation( 264 EXPECT_CALL(*command_buffer_, OnFlush(_))
258 helper_.get(), 265 .WillOnce(SetMemoryAtOffset(offset, state))
259 kTransferBufferSize, 266 .RetiresOnSaturation();
260 transfer_buffer_.ptr, 267 GetNextToken(); // eat the token that starting up will use.
261 kTransferBufferId, 268
262 false)); 269 // Must match StrictSharedIdHandler::kNumIdsToGet.
270 GLuint num_ids = 2048;
271 scoped_array<GLuint> all_ids(new GLuint[num_ids]);
272 if (shared_resources) {
273 if (!bind_generates_resource) {
274 GLuint start = kStartId;
275 GLuint max_num_per = MaxTransferBufferSize() / sizeof(GLuint);
276 GLuint* ids = all_ids.get();
277 for (GLuint ii = 0; ii < num_ids; ++ii) {
278 ids[ii] = start + ii;
279 }
280 while (num_ids) {
281 GLuint num = std::min(num_ids, max_num_per);
282 size_t size = num * sizeof(ids[0]);
283 uint32 offset = AllocateTransferBuffer(size);
284 EXPECT_CALL(*command_buffer_, OnFlush(_))
285 .WillOnce(SetMemoryAtOffsetFromArray(offset, ids, size))
286 .RetiresOnSaturation();
287 GetNextToken();
288 start += num;
289 ids += num;
290 num_ids -= num;
291 }
292 }
293 }
294
295 gl_.reset(new GLES2Implementation(
296 helper_.get(),
297 kTransferBufferSize,
298 transfer_buffer_.ptr,
299 kTransferBufferId,
300 shared_resources,
301 bind_generates_resource));
302 }
263 303
264 EXPECT_CALL(*command_buffer_, OnFlush(_)) 304 EXPECT_CALL(*command_buffer_, OnFlush(_))
265 .Times(1) 305 .Times(1)
266 .RetiresOnSaturation(); 306 .RetiresOnSaturation();
267 helper_->CommandBufferHelper::Finish(); 307 helper_->CommandBufferHelper::Finish();
268 Buffer ring_buffer = command_buffer_->GetRingBuffer(); 308 Buffer ring_buffer = command_buffer_->GetRingBuffer();
269 commands_ = static_cast<CommandBufferEntry*>(ring_buffer.ptr) + 309 commands_ = static_cast<CommandBufferEntry*>(ring_buffer.ptr) +
270 command_buffer_->GetState().put_offset; 310 command_buffer_->GetState().put_offset;
271 ClearCommands(); 311 ClearCommands();
272 } 312 }
273 313
274 virtual void TearDown() {
275 }
276
277 const void* GetPut() { 314 const void* GetPut() {
278 return helper_->GetSpace(0); 315 return helper_->GetSpace(0);
279 } 316 }
280 317
281 size_t MaxTransferBufferSize() { 318 size_t MaxTransferBufferSize() {
282 return kTransferBufferSize - GLES2Implementation::kStartingOffset; 319 return kTransferBufferSize - GLES2Implementation::kStartingOffset;
283 } 320 }
284 321
285 void ClearCommands() { 322 void ClearCommands() {
286 Buffer ring_buffer = command_buffer_->GetRingBuffer(); 323 Buffer ring_buffer = command_buffer_->GetRingBuffer();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 Buffer transfer_buffer_; 364 Buffer transfer_buffer_;
328 CommandBufferEntry* commands_; 365 CommandBufferEntry* commands_;
329 scoped_ptr<MockGLES2CommandBuffer> command_buffer_; 366 scoped_ptr<MockGLES2CommandBuffer> command_buffer_;
330 scoped_ptr<GLES2CmdHelper> helper_; 367 scoped_ptr<GLES2CmdHelper> helper_;
331 Sequence sequence_; 368 Sequence sequence_;
332 scoped_ptr<GLES2Implementation> gl_; 369 scoped_ptr<GLES2Implementation> gl_;
333 int token_; 370 int token_;
334 uint32 offset_; 371 uint32 offset_;
335 }; 372 };
336 373
374 class GLES2ImplementationStrictSharedTest : public GLES2ImplementationTest {
375 protected:
376 virtual void SetUp() {
377 Initialize(true, false);
378 }
379 };
380
337 // GCC requires these declarations, but MSVC requires they not be present 381 // GCC requires these declarations, but MSVC requires they not be present
338 #ifndef _MSC_VER 382 #ifndef _MSC_VER
339 const int32 GLES2ImplementationTest::kTransferBufferId; 383 const int32 GLES2ImplementationTest::kTransferBufferId;
340 #endif 384 #endif
341 385
342 386
343 TEST_F(GLES2ImplementationTest, ShaderSource) { 387 TEST_F(GLES2ImplementationTest, ShaderSource) {
344 const uint32 kBucketId = 1; // This id is hardcoded into GLES2Implemenation 388 const uint32 kBucketId = 1; // This id is hardcoded into GLES2Implemenation
345 const GLuint kShaderId = 456; 389 const GLuint kShaderId = 456;
346 const char* kString1 = "foobar"; 390 const char* kString1 = "foobar";
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 gl_->TexImage2D( 1723 gl_->TexImage2D(
1680 kTarget, kLevel, kFormat, kWidth, kHeight, kBorder, kFormat, kType, 1724 kTarget, kLevel, kFormat, kWidth, kHeight, kBorder, kFormat, kType,
1681 pixels.get()); 1725 pixels.get());
1682 EXPECT_EQ(0, memcmp(&expected, commands2, sizeof(expected))); 1726 EXPECT_EQ(0, memcmp(&expected, commands2, sizeof(expected)));
1683 EXPECT_TRUE(CheckRect( 1727 EXPECT_TRUE(CheckRect(
1684 kWidth / 2, 1, kFormat, kType, kPixelStoreUnpackAlignment, false, 1728 kWidth / 2, 1, kFormat, kType, kPixelStoreUnpackAlignment, false,
1685 pixels.get() + padded_row_size + part_size, 1729 pixels.get() + padded_row_size + part_size,
1686 GetTransferAddressFromOffsetAs<uint8>(offset4, part_size))); 1730 GetTransferAddressFromOffsetAs<uint8>(offset4, part_size)));
1687 } 1731 }
1688 1732
1733 // Test that GenBuffer does not call GenSharedIds.
1734 // This is because with client side arrays on we know the StrictSharedIdHandler
1735 // for buffers has already gotten a set of ids
1736 TEST_F(GLES2ImplementationStrictSharedTest, GenBuffer) {
1737 // Starts at + 2 because client side arrays take first 2 ids.
1738 GLuint ids[3] = { kStartId + 2, kStartId + 3, kStartId + 4 };
1739 struct Cmds {
1740 GenBuffersImmediate gen;
1741 GLuint data[3];
1742 };
1743 Cmds expected;
1744 expected.gen.Init(arraysize(ids), &ids[0]);
1745 gl_->GenBuffers(arraysize(ids), &ids[0]);
1746 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
1747 EXPECT_NE(0u, ids[0]);
1748 EXPECT_NE(0u, ids[1]);
1749 EXPECT_NE(0u, ids[2]);
1750 }
1751
1752 // Binds can not be cached with bind_generates_resource = false because
1753 // our id might not be valid.
1754 TEST_F(GLES2ImplementationStrictSharedTest, BindsNotCached) {
1755 struct PNameValue {
1756 GLenum pname;
1757 GLint expected;
1758 };
1759 const PNameValue pairs[] = {
1760 { GL_TEXTURE_BINDING_2D, 1, },
1761 { GL_TEXTURE_BINDING_CUBE_MAP, 2, },
1762 { GL_FRAMEBUFFER_BINDING, 3, },
1763 { GL_RENDERBUFFER_BINDING, 4, },
1764 { GL_ARRAY_BUFFER_BINDING, 5, },
1765 { GL_ELEMENT_ARRAY_BUFFER_BINDING, 6, },
1766 };
1767 size_t num_pairs = sizeof(pairs) / sizeof(pairs[0]);
1768 for (size_t ii = 0; ii < num_pairs; ++ii) {
1769 const PNameValue& pv = pairs[ii];
1770 GLint v = -1;
1771 EXPECT_CALL(*command_buffer_, OnFlush(_))
1772 .WillOnce(SetMemory(SizedResultHelper<GLuint>(pv.expected)))
1773 .RetiresOnSaturation();
1774 gl_->GetIntegerv(pv.pname, &v);
1775 EXPECT_EQ(pv.expected, v);
1776 }
1777 }
1778
1779 TEST_F(GLES2ImplementationStrictSharedTest, CanNotDeleteIdsWeDidNotCreate) {
1780 GLuint id = 0x12345678;
1781
1782 EXPECT_CALL(*command_buffer_, OnFlush(_))
1783 .WillOnce(SetMemory(GLuint(GL_NO_ERROR)))
1784 .WillOnce(SetMemory(GLuint(GL_NO_ERROR)))
1785 .WillOnce(SetMemory(GLuint(GL_NO_ERROR)))
1786 .WillOnce(SetMemory(GLuint(GL_NO_ERROR)))
1787 .WillOnce(SetMemory(GLuint(GL_NO_ERROR)))
1788 .WillOnce(SetMemory(GLuint(GL_NO_ERROR)))
1789 .RetiresOnSaturation();
1790
1791 gl_->DeleteBuffers(1, &id);
1792 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
1793 gl_->DeleteFramebuffers(1, &id);
1794 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
1795 gl_->DeleteRenderbuffers(1, &id);
1796 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
1797 gl_->DeleteTextures(1, &id);
1798 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
1799 gl_->DeleteProgram(id);
1800 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
1801 gl_->DeleteShader(id);
1802 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError());
1803 }
1804
1689 } // namespace gles2 1805 } // namespace gles2
1690 } // namespace gpu 1806 } // namespace gpu
1691 1807
1692 1808
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation_autogen.h ('k') | gpu/command_buffer/common/id_allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698