Home | History | Annotate | Download | only in src
      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 namespace {
     13 
     14 const int kNumberOfBuffers = 1;
     15 
     16 } // namespace
     17 
     18 class BufferUploadTest : public TestBase {
     19  public:
     20   BufferUploadTest()
     21       : target_(GL_ARRAY_BUFFER),
     22         size_(0),
     23         usage_(GL_DYNAMIC_DRAW)
     24   {
     25     memset(data_, 0, sizeof(data_));
     26   }
     27   virtual ~BufferUploadTest() {}
     28   virtual bool TestFunc(uint64_t iterations);
     29   virtual bool Run();
     30   virtual const char* Name() const { return "buffer_upload"; }
     31   virtual bool IsDrawTest() const { return false; }
     32   virtual const char* Unit() const { return "mbytes_sec"; }
     33 
     34  private:
     35   GLenum target_;
     36   GLsizeiptr size_;
     37   GLenum usage_;
     38   GLbyte data_[256 * 1024];
     39   GLuint buffers_[kNumberOfBuffers];
     40   DISALLOW_COPY_AND_ASSIGN(BufferUploadTest);
     41 };
     42 
     43 bool BufferUploadTest::TestFunc(uint64_t iterations) {
     44   for (uint64_t i = 0; i < iterations - 1; ++i) {
     45     if (kNumberOfBuffers > 1) {
     46       glBindBuffer(target_, buffers_[i % kNumberOfBuffers]);
     47     }
     48     glBufferData(target_, size_, data_, usage_);
     49   }
     50   return true;
     51 }
     52 
     53 bool BufferUploadTest::Run() {
     54   const GLenum usages[] = {GL_DYNAMIC_DRAW, GL_STATIC_DRAW};
     55   const char * usage_names[] = {"dynamic", "static"};
     56   const GLenum targets[] = {GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER};
     57   const char * target_names[] = {"array", "element_array"};
     58   const int sizes[] = {8, 12, 16, 32, 64, 128, 192, 256, 512, 1024, 2048,
     59                        4096, 8192, 16384, 32768, 65536, 131072};
     60 
     61   for (unsigned int uidx = 0; uidx < arraysize(usages); uidx++) {
     62     usage_ = usages[uidx];
     63 
     64     for (unsigned int tidx = 0; tidx < arraysize(targets); tidx++) {
     65       target_ = targets[tidx];
     66       glGenBuffers(kNumberOfBuffers, buffers_);
     67       if (kNumberOfBuffers == 1) {
     68         glBindBuffer(target_, buffers_[0]);
     69       }
     70 
     71       for (unsigned int sidx = 0; sidx < arraysize(sizes); sidx++) {
     72         size_ = sizes[sidx];
     73 
     74         std::string name = std::string(Name()) + "_" + usage_names[uidx] + "_" +
     75                            target_names[tidx] + "_" + IntToString(size_);
     76         RunTest(this, name.c_str(), sizes[sidx], g_width, g_height, true);
     77         CHECK(!glGetError());
     78       }
     79 
     80       glDeleteBuffers(kNumberOfBuffers, buffers_);
     81     }
     82   }
     83 
     84   return true;
     85 }
     86 
     87 TestBase* GetBufferUploadTest() {
     88   return new BufferUploadTest;
     89 }
     90 
     91 } // namespace glbench
     92