Hash :
877cd04c
Author :
Date :
2023-03-02T10:24:14
Reland "Add vulkan format image fallback for R16G16B16" Suppressed misbehaving trace test in https://crrev.com/c/4317088 This is a reland of commit 71f6d54c8d3662693283281651e57c994a10cf08 Original change's description: > Add vulkan format image fallback for R16G16B16 > > This change adds a vulkan format image mapping fallback from R16G16B16 > to R16G16B16A16, R32G32B32_FLOAT and R32G32B32A32_FLOAT for both > UNORM and SNORM variants. > > This is done because in Chrome we want to use R16/RG16 formats which > are exposed to Skia over the EXT_texture_norm16. Currently, > EXT_texture_norm16 requires RGB16_EXT which if not present is not > supported even if R16_EXT and RG16_EXT are supported. This fallback > helps us support R16/RG16 as well over RGBA16. > > It also updates validationES checks for GL_RGBA signed and unsigned > normalized checking if type is GL_SHORT or GL_UNSIGNED_SHORT. > > It adds a method LoadToFloat that allows a type (GLushort or GLshort) > to be loaded into float format types. This is then used as part of > fallbacks for load_functions_data.json. > > Bug: None > Change-Id: I5c6879cd2ed5dd6e3440877f4891f269d96d88a1 > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4294694 > Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org> > Reviewed-by: Geoff Lang <geofflang@chromium.org> > Commit-Queue: Geoff Lang <geofflang@chromium.org> Bug: None Change-Id: I101dd9e8c62e6794692c9f89c4944297e195f710 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4317089 Reviewed-by: Cody Northrop <cnorthrop@google.com> Auto-Submit: Roman Lavrov <romanl@google.com> Commit-Queue: Cody Northrop <cnorthrop@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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
//
// Copyright 2014 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.
//
#include "common/mathutil.h"
#include <string.h>
namespace angle
{
namespace priv
{
template <typename T>
inline T *OffsetDataPointer(uint8_t *data, size_t y, size_t z, size_t rowPitch, size_t depthPitch)
{
return reinterpret_cast<T*>(data + (y * rowPitch) + (z * depthPitch));
}
template <typename T>
inline const T *OffsetDataPointer(const uint8_t *data, size_t y, size_t z, size_t rowPitch, size_t depthPitch)
{
return reinterpret_cast<const T*>(data + (y * rowPitch) + (z * depthPitch));
}
} // namespace priv
template <typename type, size_t componentCount>
inline void LoadToNative(const ImageLoadContext &context, size_t width, size_t height, size_t depth,
const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
{
const size_t rowSize = width * sizeof(type) * componentCount;
const size_t layerSize = rowSize * height;
const size_t imageSize = layerSize * depth;
if (layerSize == inputDepthPitch && layerSize == outputDepthPitch)
{
ASSERT(rowSize == inputRowPitch && rowSize == outputRowPitch);
memcpy(output, input, imageSize);
}
else if (rowSize == inputRowPitch && rowSize == outputRowPitch)
{
for (size_t z = 0; z < depth; z++)
{
const type *source = priv::OffsetDataPointer<type>(input, 0, z, inputRowPitch, inputDepthPitch);
type *dest = priv::OffsetDataPointer<type>(output, 0, z, outputRowPitch, outputDepthPitch);
memcpy(dest, source, layerSize);
}
}
else
{
for (size_t z = 0; z < depth; z++)
{
for (size_t y = 0; y < height; y++)
{
const type *source = priv::OffsetDataPointer<type>(input, y, z, inputRowPitch, inputDepthPitch);
type *dest = priv::OffsetDataPointer<type>(output, y, z, outputRowPitch, outputDepthPitch);
memcpy(dest, source, width * sizeof(type) * componentCount);
}
}
}
}
template <typename type, uint32_t fourthComponentBits>
inline void LoadToNative3To4(const ImageLoadContext &context, size_t width, size_t height,
size_t depth, const uint8_t *input, size_t inputRowPitch,
size_t inputDepthPitch, uint8_t *output, size_t outputRowPitch,
size_t outputDepthPitch)
{
const type fourthValue = gl::bitCast<type>(fourthComponentBits);
for (size_t z = 0; z < depth; z++)
{
for (size_t y = 0; y < height; y++)
{
const type *source = priv::OffsetDataPointer<type>(input, y, z, inputRowPitch, inputDepthPitch);
type *dest = priv::OffsetDataPointer<type>(output, y, z, outputRowPitch, outputDepthPitch);
for (size_t x = 0; x < width; x++)
{
memcpy(&dest[x * 4], &source[x * 3], sizeof(type) * 3);
dest[x * 4 + 3] = fourthValue;
}
}
}
}
template <size_t componentCount>
inline void Load32FTo16F(const ImageLoadContext &context, size_t width, size_t height, size_t depth,
const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
{
const size_t elementWidth = componentCount * width;
for (size_t z = 0; z < depth; z++)
{
for (size_t y = 0; y < height; y++)
{
const float *source = priv::OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
uint16_t *dest = priv::OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
for (size_t x = 0; x < elementWidth; x++)
{
dest[x] = gl::float32ToFloat16(source[x]);
}
}
}
}
template <typename type,
size_t inputComponentCount,
size_t outputComponentCount,
bool normalized>
inline void LoadToFloat(const ImageLoadContext &context, size_t width, size_t height, size_t depth,
const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) {
typedef std::numeric_limits<type> NL;
for (size_t z = 0; z < depth; z++)
{
for (size_t y = 0; y < height; y++)
{
const type *source_line = priv::OffsetDataPointer<type>(input, y, z, inputRowPitch, inputDepthPitch);
float *dest_line = priv::OffsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
for (size_t x = 0; x < width; x++)
{
const type *source_pixel = source_line + x * inputComponentCount;
float *dest_pixel = dest_line + x * outputComponentCount;
for (size_t i = 0; i < inputComponentCount; i++)
{
float result = 0;
if (normalized)
{
if (NL::is_signed)
{
result = static_cast<float>(source_pixel[i]) / static_cast<float>(NL::max());
result = result >= -1.0f ? result : -1.0f;
}
else
{
result = static_cast<float>(source_pixel[i]) / static_cast<float>(NL::max());
}
}
else
{
result = static_cast<float>(source_pixel[i]);
}
dest_pixel[i] = result;
}
for (size_t j = inputComponentCount; j < outputComponentCount; j++)
{
dest_pixel[j] = j == 3 ? 1.0f : 0.0f;
}
}
}
}
}
template <size_t blockWidth, size_t blockHeight, size_t blockDepth, size_t blockSize>
inline void LoadCompressedToNative(const ImageLoadContext &context, size_t width, size_t height,
size_t depth, const uint8_t *input, size_t inputRowPitch,
size_t inputDepthPitch, uint8_t *output, size_t outputRowPitch,
size_t outputDepthPitch)
{
const size_t columns = (width + (blockWidth - 1)) / blockWidth;
const size_t rows = (height + (blockHeight - 1)) / blockHeight;
const size_t layers = (depth + (blockDepth - 1)) / blockDepth;
for (size_t z = 0; z < layers; ++z)
{
for (size_t y = 0; y < rows; ++y)
{
const uint8_t *source = priv::OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch);
uint8_t *dest = priv::OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
memcpy(dest, source, columns * blockSize);
}
}
}
template <typename type, uint32_t firstBits, uint32_t secondBits, uint32_t thirdBits, uint32_t fourthBits>
inline void Initialize4ComponentData(size_t width, size_t height, size_t depth,
uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
{
type writeValues[4] =
{
gl::bitCast<type>(firstBits),
gl::bitCast<type>(secondBits),
gl::bitCast<type>(thirdBits),
gl::bitCast<type>(fourthBits),
};
for (size_t z = 0; z < depth; z++)
{
for (size_t y = 0; y < height; y++)
{
type *destRow = priv::OffsetDataPointer<type>(output, y, z, outputRowPitch, outputDepthPitch);
for (size_t x = 0; x < width; x++)
{
type* destPixel = destRow + x * 4;
// This could potentially be optimized by generating an entire row of initialization
// data and copying row by row instead of pixel by pixel.
memcpy(destPixel, writeValues, sizeof(type) * 4);
}
}
}
}
template <size_t blockWidth, size_t blockHeight>
inline void LoadASTCToRGBA8(const ImageLoadContext &context,
size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
LoadASTCToRGBA8Inner(context, width, height, depth, blockWidth, blockHeight, input, inputRowPitch,
inputDepthPitch, output, outputRowPitch, outputDepthPitch);
}
template <uint32_t indexBits, uint32_t redBlueBits, uint32_t greenBits, uint32_t alphaBits>
inline void LoadPalettedToRGBA8(const ImageLoadContext &context,
size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
static_assert(indexBits == 4 || indexBits == 8);
static_assert(redBlueBits == 4 || redBlueBits == 5 || redBlueBits == 8);
static_assert(greenBits == 4 || greenBits == 5 || greenBits == 6 || greenBits == 8);
static_assert(alphaBits == 0 || alphaBits == 1 || alphaBits == 4 || alphaBits == 8);
constexpr uint32_t colorBits = 2 * redBlueBits + greenBits + alphaBits;
static_assert(colorBits == 16 || colorBits == 24 || colorBits == 32);
LoadPalettedToRGBA8Impl(context, width, height, depth,
indexBits, redBlueBits, greenBits, alphaBits,
input, inputRowPitch, inputDepthPitch,
output, outputRowPitch, outputDepthPitch);
}
// Temporary overload functions; need to have no-context overloads of the following functions used
// by Chromium. A Chromium change will switch to the with-context overloads, and then these can be
// removed.
inline void LoadEACR11ToR8(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
LoadEACR11ToR8({}, width, height, depth, input, inputRowPitch, inputDepthPitch, output,
outputRowPitch, outputDepthPitch);
}
inline void LoadEACR11SToR8(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
LoadEACR11SToR8({}, width, height, depth, input, inputRowPitch, inputDepthPitch, output,
outputRowPitch, outputDepthPitch);
}
inline void LoadEACRG11ToRG8(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
LoadEACRG11ToRG8({}, width, height, depth, input, inputRowPitch, inputDepthPitch, output,
outputRowPitch, outputDepthPitch);
}
inline void LoadEACRG11SToRG8(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
LoadEACRG11SToRG8({}, width, height, depth, input, inputRowPitch, inputDepthPitch, output,
outputRowPitch, outputDepthPitch);
}
inline void LoadETC2RGB8ToRGBA8(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
LoadETC2RGB8ToRGBA8({}, width, height, depth, input, inputRowPitch, inputDepthPitch, output,
outputRowPitch, outputDepthPitch);
}
inline void LoadETC2SRGB8ToRGBA8(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
LoadETC2SRGB8ToRGBA8({}, width, height, depth, input, inputRowPitch, inputDepthPitch, output,
outputRowPitch, outputDepthPitch);
}
inline void LoadETC2RGBA8ToRGBA8(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
LoadETC2RGBA8ToRGBA8({}, width, height, depth, input, inputRowPitch, inputDepthPitch, output,
outputRowPitch, outputDepthPitch);
}
inline void LoadETC2RGB8A1ToRGBA8(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
LoadETC2RGB8A1ToRGBA8({}, width, height, depth, input, inputRowPitch, inputDepthPitch, output,
outputRowPitch, outputDepthPitch);
}
inline void LoadETC2SRGBA8ToSRGBA8(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
LoadETC2SRGBA8ToSRGBA8({}, width, height, depth, input, inputRowPitch, inputDepthPitch, output,
outputRowPitch, outputDepthPitch);
}
inline void LoadETC2SRGB8A1ToRGBA8(size_t width,
size_t height,
size_t depth,
const uint8_t *input,
size_t inputRowPitch,
size_t inputDepthPitch,
uint8_t *output,
size_t outputRowPitch,
size_t outputDepthPitch)
{
LoadETC2SRGB8A1ToRGBA8({}, width, height, depth, input, inputRowPitch, inputDepthPitch, output,
outputRowPitch, outputDepthPitch);
}
} // namespace angle