Commit a9d60da8 by Jamie Madill Committed by Commit Bot

D3D11: Fix uploading RGB10A2 data to RGB5A1 textures.

WebGL test: textures/misc/tex-new-formats BUG=angleproject:1407 BUG=chromium:616176 Change-Id: I7b557587c1ea0861bcac327a370480b36f679794 Reviewed-on: https://chromium-review.googlesource.com/351170Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent e40dd76c
...@@ -284,6 +284,11 @@ ...@@ -284,6 +284,11 @@
"loadFunction": "LoadRGB10A2ToRGBA8", "loadFunction": "LoadRGB10A2ToRGBA8",
"dxgiFormat": "DXGI_FORMAT_R8G8B8A8_UNORM", "dxgiFormat": "DXGI_FORMAT_R8G8B8A8_UNORM",
"requiresConversion": "true" "requiresConversion": "true"
},
{
"loadFunction": "LoadRGB10A2ToBGR5A1",
"dxgiFormat": "DXGI_FORMAT_B5G5R5A1_UNORM",
"requiresConversion": "true"
} }
], ],
"GL_UNSIGNED_BYTE": [ "GL_UNSIGNED_BYTE": [
......
...@@ -1548,6 +1548,7 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern ...@@ -1548,6 +1548,7 @@ const std::map<GLenum, LoadImageFunctionInfo> &GetLoadFunctionsMap(GLenum intern
case DXGI_FORMAT_B5G5R5A1_UNORM: case DXGI_FORMAT_B5G5R5A1_UNORM:
{ {
static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = { static const std::map<GLenum, LoadImageFunctionInfo> loadFunctionsMap = {
{ GL_UNSIGNED_INT_2_10_10_10_REV, LoadImageFunctionInfo(LoadRGB10A2ToBGR5A1, true) },
{ GL_UNSIGNED_SHORT_5_5_5_1, LoadImageFunctionInfo(LoadRGB5A1ToA1RGB5, true) }, { GL_UNSIGNED_SHORT_5_5_5_1, LoadImageFunctionInfo(LoadRGB5A1ToA1RGB5, true) },
{ GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadRGBA8ToBGR5A1, true) }, { GL_UNSIGNED_BYTE, LoadImageFunctionInfo(LoadRGBA8ToBGR5A1, true) },
}; };
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "libANGLE/renderer/d3d/loadimage.h" #include "libANGLE/renderer/d3d/loadimage.h"
#include "libANGLE/renderer/imageformats.h"
namespace rx namespace rx
{ {
...@@ -526,6 +528,39 @@ void LoadRGBA8ToBGR5A1(size_t width, ...@@ -526,6 +528,39 @@ void LoadRGBA8ToBGR5A1(size_t width,
} }
} }
void LoadRGB10A2ToBGR5A1(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)
{
for (size_t z = 0; z < depth; z++)
{
for (size_t y = 0; y < height; y++)
{
const R10G10B10A2 *source =
OffsetDataPointer<R10G10B10A2>(input, y, z, inputRowPitch, inputDepthPitch);
uint16_t *dest =
OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
for (size_t x = 0; x < width; x++)
{
R10G10B10A2 rgb10a2 = source[x];
uint16_t r5 = static_cast<uint16_t>(rgb10a2.R >> 5u);
uint16_t g5 = static_cast<uint16_t>(rgb10a2.G >> 5u);
uint16_t b5 = static_cast<uint16_t>(rgb10a2.B >> 5u);
uint16_t a1 = static_cast<uint16_t>(rgb10a2.A >> 1u);
dest[x] = (a1 << 15) | (r5 << 10) | (g5 << 5) | b5;
}
}
}
}
void LoadRGB5A1ToA1RGB5(size_t width, size_t height, size_t depth, void LoadRGB5A1ToA1RGB5(size_t width, size_t height, size_t depth,
const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
......
...@@ -142,6 +142,16 @@ void LoadRGBA8ToBGR5A1(size_t width, ...@@ -142,6 +142,16 @@ void LoadRGBA8ToBGR5A1(size_t width,
size_t outputRowPitch, size_t outputRowPitch,
size_t outputDepthPitch); size_t outputDepthPitch);
void LoadRGB10A2ToBGR5A1(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);
void LoadRGB5A1ToA1RGB5(size_t width, size_t height, size_t depth, void LoadRGB5A1ToA1RGB5(size_t width, size_t height, size_t depth,
const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch); uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch);
......
...@@ -343,6 +343,42 @@ TEST_P(SixteenBppTextureTestES3, RGB5A1UploadRGBA8) ...@@ -343,6 +343,42 @@ TEST_P(SixteenBppTextureTestES3, RGB5A1UploadRGBA8)
simpleValidationBase(tex.get()); simpleValidationBase(tex.get());
} }
// Test uploading RGB10A2 data to RGB5A1 textures.
TEST_P(SixteenBppTextureTestES3, RGB5A1UploadRGB10A2)
{
struct RGB10A2
{
RGB10A2(uint32_t r, uint32_t g, uint32_t b, uint32_t a) : R(r), G(g), B(b), A(a) {}
uint32_t R : 10;
uint32_t G : 10;
uint32_t B : 10;
uint32_t A : 2;
};
uint32_t one10 = (1u << 10u) - 1u;
RGB10A2 red(one10, 0u, 0u, 0x3u);
RGB10A2 green(0u, one10, 0u, 0x3u);
RGB10A2 blue(0u, 0u, one10, 0x3u);
RGB10A2 yellow(one10, one10, 0u, 0x3u);
std::vector<RGB10A2> fourColors;
fourColors.push_back(red);
fourColors.push_back(green);
fourColors.push_back(blue);
fourColors.push_back(yellow);
GLTexture tex;
glBindTexture(GL_TEXTURE_2D, tex.get());
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5_A1, 2, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV,
fourColors.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
ASSERT_GL_NO_ERROR();
simpleValidationBase(tex.get());
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
ANGLE_INSTANTIATE_TEST(SixteenBppTextureTest, ANGLE_INSTANTIATE_TEST(SixteenBppTextureTest,
ES2_D3D9(), ES2_D3D9(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment