1 // Copyright (c) 2018 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "arraysize.h"
6 #include "main.h"
7 #include "testbase.h"
8 #include "utils.h"
9
10 namespace glbench {
11
12 class BufferUploadSubTest : public TestBase {
13 public:
BufferUploadSubTest()14 BufferUploadSubTest()
15 : buffer_size_(1572864),
16 target_(GL_ARRAY_BUFFER),
17 size_(0)
18 {
19 memset(data_, 0, sizeof(data_));
20 }
~BufferUploadSubTest()21 virtual ~BufferUploadSubTest() {}
22 virtual bool TestFunc(uint64_t iterations);
23 virtual bool Run();
Name() const24 virtual const char* Name() const { return "buffer_upload_sub"; }
IsDrawTest() const25 virtual bool IsDrawTest() const { return false; }
Unit() const26 virtual const char* Unit() const { return "mbytes_sec"; }
27
28 private:
29 GLsizeiptr buffer_size_;
30 GLenum target_;
31 GLsizeiptr size_;
32 GLbyte data_[256 * 1024];
33 DISALLOW_COPY_AND_ASSIGN(BufferUploadSubTest);
34 };
35
TestFunc(uint64_t iterations)36 bool BufferUploadSubTest::TestFunc(uint64_t iterations) {
37 GLintptr offset = 0;
38 for (uint64_t i = 0; i < iterations - 1; ++i) {
39 if (offset + size_ > buffer_size_) {
40 offset = 0;
41 }
42 glBufferSubData(target_, offset, size_, data_);
43 offset += size_;
44 }
45 return true;
46 }
47
Run()48 bool BufferUploadSubTest::Run() {
49 const GLenum usages[] = {GL_DYNAMIC_DRAW, GL_STATIC_DRAW};
50 const char * usage_names[] = {"dynamic", "static"};
51 const GLenum targets[] = {GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER};
52 const char * target_names[] = {"array", "element_array"};
53 const int sizes[] = {8, 12, 16, 32, 64, 128, 192, 256, 512, 1024, 2048,
54 4096, 8192, 16384, 32768, 65536, 131072};
55
56 for (unsigned int uidx = 0; uidx < arraysize(usages); uidx++) {
57 GLenum usage = usages[uidx];
58
59 for (unsigned int tidx = 0; tidx < arraysize(targets); tidx++) {
60 target_ = targets[tidx];
61 GLuint buf = ~0;
62 glGenBuffers(1, &buf);
63 glBindBuffer(target_, buf);
64
65 for (unsigned int sidx = 0; sidx < arraysize(sizes); sidx++) {
66 size_ = sizes[sidx];
67 glBufferData(target_, buffer_size_, NULL, usage);
68
69 std::string name = std::string(Name()) + "_" + usage_names[uidx] + "_" +
70 target_names[tidx] + "_" + IntToString(size_);
71 RunTest(this, name.c_str(), sizes[sidx], g_width, g_height, true);
72 CHECK(!glGetError());
73 }
74
75 glDeleteBuffers(1, &buf);
76 }
77 }
78
79 return true;
80 }
81
GetBufferUploadSubTest()82 TestBase* GetBufferUploadSubTest() {
83 return new BufferUploadSubTest;
84 }
85
86 } // namespace glbench
87