Hash :
716c5d00
Author :
Date :
2023-11-13T10:23:10
Vulkan: Add RGB8-to-RGBA8 ubyte loading function
Currently, to update RGB8 on desktop, ANGLE uses memcpy for each
pixel, which is suboptimal. This CL adds a loading function to improve
the copy time for RGB textures where RGBA is needed on the hardware.
* Added a specialization to LoadToNative3To4() for unsigned bytes
using 0xFF as the fourth component.
* It is optimized for unsigned bytes when converting an RGB format
to its corresponding RGBA format, e.g., RGB8 to RGBA8.
* It uses uint32_t operations to speed up the process.
* Added unit tests for the specialized LoadToNative3To4.
* LoadToNative_unittest.cpp
* Added perf test for RGB8 image allocation and loading.
* RGBImageAllocationBenchmark in RGBImageAllocation.cpp.
* RGBImageAllocationBenchmark shows some improvement in cpu_time
and wall_time on a Linux and a Windows device. (Results below using
aligned source pointer and texture size of 2048):
* On Windows: +~85% cpu_time, +~71% wall_time
* On Linux: +~26% cpu_time, +~27% wall_time
Bug: b/308177124
Change-Id: I421d83f75fdc513b0111dffb0a5d5e74682dd6fb
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4995489
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Charlie Lao <cclao@google.com>
Commit-Queue: Amirali Abdolrashidi <abdolrashidi@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
//
// Copyright 2023 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// RGBImageAllocationBenchmark:
// GL_RGB8 image allocation and loading using GL_UNSIGNED_BYTE.
//
#include "ANGLEPerfTest.h"
#include <iostream>
#include <random>
#include <sstream>
#include "test_utils/gl_raii.h"
#include "util/shader_utils.h"
using namespace angle;
namespace
{
struct RGBImageAllocationParams final : public RenderTestParams
{
RGBImageAllocationParams() { iterationsPerStep = 1; }
std::string story() const override;
// Used to indicate whether the tested source pointer should be 4-byte-aligned.
bool aligned;
size_t textureSize;
};
std::ostream &operator<<(std::ostream &os, const RGBImageAllocationParams ¶ms)
{
return os << params.backendAndStory().substr(1);
}
std::string RGBImageAllocationParams::story() const
{
std::stringstream strstr;
strstr << RenderTestParams::story() << "_size" << textureSize
<< (aligned ? "_4bytealigned_src" : "_non4bytealigned_src");
return strstr.str();
}
struct RGBColor
{
RGBColor() : r(0), g(0), b(0) {}
RGBColor(uint8_t r, uint8_t g, uint8_t b) : r(r), g(g), b(b) {}
uint8_t r;
uint8_t g;
uint8_t b;
};
class RGBImageAllocationBenchmark : public ANGLERenderTest,
public ::testing::WithParamInterface<RGBImageAllocationParams>
{
public:
RGBImageAllocationBenchmark();
void initializeBenchmark() override;
void drawBenchmark() override;
void destroyBenchmark() override;
protected:
std::vector<RGBColor> mColors;
GLuint mTexture;
size_t mOffset;
size_t mTextureSize;
};
RGBImageAllocationBenchmark::RGBImageAllocationBenchmark()
: ANGLERenderTest("RGBImageAllocation", GetParam())
{
mOffset = (GetParam().aligned) ? 0 : 1;
mTextureSize = GetParam().textureSize;
}
void RGBImageAllocationBenchmark::initializeBenchmark()
{
// Initialize texture. The size in this test should be set to a power of two for easier data
// allocation and avoiding alignment issues.
ASSERT(gl::isPow2(mTextureSize));
glGenTextures(1, &mTexture);
glBindTexture(GL_TEXTURE_2D, mTexture);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, mTextureSize, mTextureSize);
// Initialize color data. It is expected for the color data pointer to be 4-byte-aligned. If
// necessary, an extra pixel is allocated in the beginning to test the non-aligned case.
ASSERT(reinterpret_cast<uintptr_t>(mColors.data()) % 4 == 0);
mColors.resize(mOffset + mTextureSize * mTextureSize);
for (size_t i = 0; i < mTextureSize * mTextureSize; i++)
{
mColors[mOffset + i] = RGBColor(1, 2, 3);
}
}
void RGBImageAllocationBenchmark::destroyBenchmark()
{
glDeleteTextures(1, &mTexture);
}
void RGBImageAllocationBenchmark::drawBenchmark()
{
// Copy the next color data.
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mTextureSize, mTextureSize, GL_RGB, GL_UNSIGNED_BYTE,
mColors.data() + mOffset);
glFinish();
ASSERT_GL_NO_ERROR();
}
RGBImageAllocationParams VulkanParams(bool aligned, size_t textureSize)
{
RGBImageAllocationParams params;
params.eglParameters = egl_platform::VULKAN();
params.majorVersion = 3;
params.minorVersion = 0;
params.aligned = aligned;
params.textureSize = textureSize;
return params;
}
RGBImageAllocationParams OpenGLOrGLESParams(bool aligned, size_t textureSize)
{
RGBImageAllocationParams params;
params.eglParameters = egl_platform::OPENGL_OR_GLES();
params.majorVersion = 3;
params.minorVersion = 0;
params.aligned = aligned;
params.textureSize = textureSize;
return params;
}
RGBImageAllocationParams MetalParams(bool aligned, size_t textureSize)
{
RGBImageAllocationParams params;
params.eglParameters = egl_platform::METAL();
params.majorVersion = 3;
params.minorVersion = 0;
params.aligned = aligned;
params.textureSize = textureSize;
return params;
}
RGBImageAllocationParams D3D11Params(bool aligned, size_t textureSize)
{
RGBImageAllocationParams params;
params.eglParameters = egl_platform::D3D11();
params.majorVersion = 3;
params.minorVersion = 0;
params.aligned = aligned;
params.textureSize = textureSize;
return params;
}
} // anonymous namespace
// Runs the test to measure the performance of RGB8 image allocation and loading.
TEST_P(RGBImageAllocationBenchmark, Run)
{
run();
}
using namespace params;
ANGLE_INSTANTIATE_TEST(RGBImageAllocationBenchmark,
VulkanParams(true, 256),
VulkanParams(true, 2048),
VulkanParams(false, 2048),
OpenGLOrGLESParams(true, 256),
OpenGLOrGLESParams(true, 2048),
OpenGLOrGLESParams(false, 2048),
MetalParams(true, 256),
MetalParams(true, 2048),
MetalParams(false, 2048),
D3D11Params(true, 256),
D3D11Params(true, 2048),
D3D11Params(false, 2048));