Commit 31d3deb4 by Jeff Gilbert Committed by Commit Bot

Add `formatType` arg to computeSkipBytes.

Fix texture upload format tests: - Format tests should definitely run on ES3 also. - Also set filters to NEAREST since some formats aren't filterable. - Fix RGB9_E5 test reference encoding and add a test for it. - True int/uint textures require i/usamplers. Bug: angleproject:2576 Change-Id: Ia5bac34cdee6554a88db339de443689a71a0cf70 Reviewed-on: https://chromium-review.googlesource.com/1068142 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 64ac5d9e
...@@ -1139,7 +1139,8 @@ ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(const Extents & ...@@ -1139,7 +1139,8 @@ ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(const Extents &
return bytes.ValueOrDie(); return bytes.ValueOrDie();
} }
ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch, ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLenum formatType,
GLuint rowPitch,
GLuint depthPitch, GLuint depthPitch,
const PixelStoreStateBase &state, const PixelStoreStateBase &state,
bool is3D) const bool is3D) const
...@@ -1149,7 +1150,7 @@ ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch, ...@@ -1149,7 +1150,7 @@ ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages)); CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows)); CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels)); CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes); CheckedNumeric<GLuint> checkedPixelBytes(computePixelBytes(formatType));
auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch; auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
if (!is3D) if (!is3D)
{ {
...@@ -1198,7 +1199,8 @@ ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte( ...@@ -1198,7 +1199,8 @@ ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte(
} }
CheckedNumeric<GLuint> checkedSkipBytes = 0; CheckedNumeric<GLuint> checkedSkipBytes = 0;
ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, depthPitch, state, is3D), checkedSkipBytes); ANGLE_TRY_RESULT(computeSkipBytes(formatType, rowPitch, depthPitch, state, is3D),
checkedSkipBytes);
CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes; CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
......
...@@ -71,7 +71,8 @@ struct InternalFormat ...@@ -71,7 +71,8 @@ struct InternalFormat
ErrorOrResult<GLuint> computeCompressedImageSize(const Extents &size) const; ErrorOrResult<GLuint> computeCompressedImageSize(const Extents &size) const;
ErrorOrResult<GLuint> computeSkipBytes(GLuint rowPitch, ErrorOrResult<GLuint> computeSkipBytes(GLenum formatType,
GLuint rowPitch,
GLuint depthPitch, GLuint depthPitch,
const PixelStoreStateBase &state, const PixelStoreStateBase &state,
bool is3D) const; bool is3D) const;
......
...@@ -264,7 +264,7 @@ gl::Error FramebufferD3D::readPixels(const gl::Context *context, ...@@ -264,7 +264,7 @@ gl::Error FramebufferD3D::readPixels(const gl::Context *context,
packState.rowLength), packState.rowLength),
outputPitch); outputPitch);
GLuint outputSkipBytes = 0; GLuint outputSkipBytes = 0;
ANGLE_TRY_RESULT(sizedFormatInfo.computeSkipBytes(outputPitch, 0, packState, false), ANGLE_TRY_RESULT(sizedFormatInfo.computeSkipBytes(type, outputPitch, 0, packState, false),
outputSkipBytes); outputSkipBytes);
outputSkipBytes += outputSkipBytes +=
(area.x - origArea.x) * sizedFormatInfo.pixelBytes + (area.y - origArea.y) * outputPitch; (area.x - origArea.x) * sizedFormatInfo.pixelBytes + (area.y - origArea.y) * outputPitch;
......
...@@ -291,7 +291,7 @@ gl::Error Image11::loadData(const gl::Context *context, ...@@ -291,7 +291,7 @@ gl::Error Image11::loadData(const gl::Context *context,
inputDepthPitch); inputDepthPitch);
GLuint inputSkipBytes = 0; GLuint inputSkipBytes = 0;
ANGLE_TRY_RESULT( ANGLE_TRY_RESULT(
formatInfo.computeSkipBytes(inputRowPitch, inputDepthPitch, unpack, applySkipImages), formatInfo.computeSkipBytes(type, inputRowPitch, inputDepthPitch, unpack, applySkipImages),
inputSkipBytes); inputSkipBytes);
const d3d11::DXGIFormatSize &dxgiFormatInfo = d3d11::GetDXGIFormatSizeInfo(mDXGIFormat); const d3d11::DXGIFormatSize &dxgiFormatInfo = d3d11::GetDXGIFormatSizeInfo(mDXGIFormat);
......
...@@ -742,8 +742,8 @@ gl::Error TextureStorage11::setData(const gl::Context *context, ...@@ -742,8 +742,8 @@ gl::Error TextureStorage11::setData(const gl::Context *context,
ANGLE_TRY_RESULT(internalFormatInfo.computeDepthPitch(height, unpack.imageHeight, srcRowPitch), ANGLE_TRY_RESULT(internalFormatInfo.computeDepthPitch(height, unpack.imageHeight, srcRowPitch),
srcDepthPitch); srcDepthPitch);
GLuint srcSkipBytes = 0; GLuint srcSkipBytes = 0;
ANGLE_TRY_RESULT( ANGLE_TRY_RESULT(internalFormatInfo.computeSkipBytes(type, srcRowPitch, srcDepthPitch, unpack,
internalFormatInfo.computeSkipBytes(srcRowPitch, srcDepthPitch, unpack, index.usesTex3D()), index.usesTex3D()),
srcSkipBytes); srcSkipBytes);
const d3d11::Format &d3d11Format = const d3d11::Format &d3d11Format =
......
...@@ -883,7 +883,7 @@ gl::Error FramebufferGL::readPixelsRowByRow(const gl::Context *context, ...@@ -883,7 +883,7 @@ gl::Error FramebufferGL::readPixelsRowByRow(const gl::Context *context,
ANGLE_TRY_RESULT(glFormat.computeRowPitch(type, area.width, pack.alignment, pack.rowLength), ANGLE_TRY_RESULT(glFormat.computeRowPitch(type, area.width, pack.alignment, pack.rowLength),
rowBytes); rowBytes);
GLuint skipBytes = 0; GLuint skipBytes = 0;
ANGLE_TRY_RESULT(glFormat.computeSkipBytes(rowBytes, 0, pack, false), skipBytes); ANGLE_TRY_RESULT(glFormat.computeSkipBytes(type, rowBytes, 0, pack, false), skipBytes);
gl::PixelPackState directPack; gl::PixelPackState directPack;
directPack.alignment = 1; directPack.alignment = 1;
...@@ -925,7 +925,7 @@ gl::Error FramebufferGL::readPixelsAllAtOnce(const gl::Context *context, ...@@ -925,7 +925,7 @@ gl::Error FramebufferGL::readPixelsAllAtOnce(const gl::Context *context,
ANGLE_TRY_RESULT(glFormat.computeRowPitch(type, area.width, pack.alignment, pack.rowLength), ANGLE_TRY_RESULT(glFormat.computeRowPitch(type, area.width, pack.alignment, pack.rowLength),
rowBytes); rowBytes);
GLuint skipBytes = 0; GLuint skipBytes = 0;
ANGLE_TRY_RESULT(glFormat.computeSkipBytes(rowBytes, 0, pack, false), skipBytes); ANGLE_TRY_RESULT(glFormat.computeSkipBytes(type, rowBytes, 0, pack, false), skipBytes);
gl::PixelPackState directPack; gl::PixelPackState directPack;
directPack.alignment = 1; directPack.alignment = 1;
......
...@@ -349,7 +349,7 @@ gl::Error TextureGL::setSubImageRowByRowWorkaround(const gl::Context *context, ...@@ -349,7 +349,7 @@ gl::Error TextureGL::setSubImageRowByRowWorkaround(const gl::Context *context,
bool useTexImage3D = nativegl::UseTexImage3D(getType()); bool useTexImage3D = nativegl::UseTexImage3D(getType());
GLuint skipBytes = 0; GLuint skipBytes = 0;
ANGLE_TRY_RESULT(glFormat.computeSkipBytes(rowBytes, imageBytes, unpack, useTexImage3D), ANGLE_TRY_RESULT(glFormat.computeSkipBytes(type, rowBytes, imageBytes, unpack, useTexImage3D),
skipBytes); skipBytes);
const uint8_t *pixelsWithSkip = pixels + skipBytes; const uint8_t *pixelsWithSkip = pixels + skipBytes;
...@@ -404,7 +404,7 @@ gl::Error TextureGL::setSubImagePaddingWorkaround(const gl::Context *context, ...@@ -404,7 +404,7 @@ gl::Error TextureGL::setSubImagePaddingWorkaround(const gl::Context *context,
imageBytes); imageBytes);
bool useTexImage3D = nativegl::UseTexImage3D(getType()); bool useTexImage3D = nativegl::UseTexImage3D(getType());
GLuint skipBytes = 0; GLuint skipBytes = 0;
ANGLE_TRY_RESULT(glFormat.computeSkipBytes(rowBytes, imageBytes, unpack, useTexImage3D), ANGLE_TRY_RESULT(glFormat.computeSkipBytes(type, rowBytes, imageBytes, unpack, useTexImage3D),
skipBytes); skipBytes);
stateManager->setPixelUnpackState(unpack); stateManager->setPixelUnpackState(unpack);
......
...@@ -153,7 +153,7 @@ gl::Error FramebufferNULL::readPixels(const gl::Context *context, ...@@ -153,7 +153,7 @@ gl::Error FramebufferNULL::readPixels(const gl::Context *context,
rowBytes); rowBytes);
GLuint skipBytes = 0; GLuint skipBytes = 0;
ANGLE_TRY_RESULT(glFormat.computeSkipBytes(rowBytes, 0, packState, false), skipBytes); ANGLE_TRY_RESULT(glFormat.computeSkipBytes(type, rowBytes, 0, packState, false), skipBytes);
pixels += skipBytes; pixels += skipBytes;
// Skip OOB region up to first in bounds pixel // Skip OOB region up to first in bounds pixel
......
...@@ -307,7 +307,7 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context, ...@@ -307,7 +307,7 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
sizedFormatInfo.computeRowPitch(type, area.width, packState.alignment, packState.rowLength), sizedFormatInfo.computeRowPitch(type, area.width, packState.alignment, packState.rowLength),
outputPitch); outputPitch);
GLuint outputSkipBytes = 0; GLuint outputSkipBytes = 0;
ANGLE_TRY_RESULT(sizedFormatInfo.computeSkipBytes(outputPitch, 0, packState, false), ANGLE_TRY_RESULT(sizedFormatInfo.computeSkipBytes(type, outputPitch, 0, packState, false),
outputSkipBytes); outputSkipBytes);
outputSkipBytes += (clippedArea.x - area.x) * sizedFormatInfo.pixelBytes + outputSkipBytes += (clippedArea.x - area.x) * sizedFormatInfo.pixelBytes +
......
...@@ -103,7 +103,7 @@ gl::Error PixelBuffer::stageSubresourceUpdate(ContextVk *contextVk, ...@@ -103,7 +103,7 @@ gl::Error PixelBuffer::stageSubresourceUpdate(ContextVk *contextVk,
GLuint inputSkipBytes = 0; GLuint inputSkipBytes = 0;
ANGLE_TRY_RESULT( ANGLE_TRY_RESULT(
formatInfo.computeSkipBytes(inputRowPitch, inputDepthPitch, unpack, applySkipImages), formatInfo.computeSkipBytes(type, inputRowPitch, inputDepthPitch, unpack, applySkipImages),
inputSkipBytes); inputSkipBytes);
RendererVk *renderer = contextVk->getRenderer(); RendererVk *renderer = contextVk->getRenderer();
......
...@@ -163,46 +163,87 @@ struct SizedFloat ...@@ -163,46 +163,87 @@ struct SizedFloat
const auto sVal = static_cast<uint32_t>(v < 0.0f); const auto sVal = static_cast<uint32_t>(v < 0.0f);
return Assemble(sVal, eVal, mVal); return Assemble(sVal, eVal, mVal);
} }
static constexpr float Decode(const uint32_t sVal, const uint32_t eVal, const uint32_t mVal)
{
constexpr int eBias = (1 << (kEBits - 1)) - 1;
constexpr int mDiv = 1 << kMBits;
float ret = powf(-1, sVal) * powf(2, int(eVal) - eBias) * (1.0f + float(mVal) / mDiv);
return ret;
}
}; };
using Float16 = SizedFloat<1, 5, 10>; using Float16 = SizedFloat<1, 5, 10>;
using UFloat11 = SizedFloat<0, 5, 6>; using UFloat11 = SizedFloat<0, 5, 6>;
using UFloat10 = SizedFloat<0, 5, 5>; using UFloat10 = SizedFloat<0, 5, 5>;
uint32_t EncodeRGB9_E5_Rev(const float signedR, const float signedG, const float signedB) struct RGB9_E5 final
{ {
const float r = std::max(0.0f, signedR); // GLES 3.0.5 p129
const float g = std::max(0.0f, signedG); static constexpr int N = 9; // number of mantissa bits per component
const float b = std::max(0.0f, signedB); static constexpr int B = 15; // exponent bias
const int eBits = 5;
const int eBias = (1 << (eBits - 1)) - 1; // 15 static uint32_t Encode(const float red, const float green, const float blue)
const int eMax = (1 << eBits) - 1; {
const int mBits = 9; const auto floori = [](const float x) { return static_cast<int>(floor(x)); };
const uint32_t mMax = (1 << mBits) - 1; // GLES 3.0.5 p129
// Maximize mVal for one channel constexpr int eMax = 31; // max allowed biased exponent value
// => Find the lowest viable exponent
int minViableActualExp = 1 << eBits; const float twoToN = powf(2, N);
const auto fnMinimizeViableActualExponent = [&](const float v) { const float sharedExpMax = (twoToN - 1) / twoToN * powf(2, eMax - B);
const auto cur = static_cast<int>(ceil(log2f(v / mMax)));
if (cur < minViableActualExp) const auto fnClampColor = [&](const float color) {
{ return std::max(0.0f, std::min(color, sharedExpMax));
minViableActualExp = cur;
}
};
fnMinimizeViableActualExponent(r);
fnMinimizeViableActualExponent(g);
fnMinimizeViableActualExponent(b);
const int eVal = std::max(0, std::min(minViableActualExp + eBias + mBits, eMax));
const auto fnM = [&](const float v) {
const auto m = static_cast<uint32_t>(v * powf(2, static_cast<float>(mBits + eBias - eVal)));
return std::min(m, mMax);
}; };
const float redC = fnClampColor(red);
const float greenC = fnClampColor(green);
const float blueC = fnClampColor(blue);
const auto mR = fnM(r); const float maxC = std::max({redC, greenC, blueC});
const auto mG = fnM(g); const int expP = std::max(-B - 1, floori(log2f(maxC))) + 1 + B;
const auto mB = fnM(b);
return (mR << 0) | (mG << 9) | (mB << 18) | (eVal << 27); const auto fnColorS = [&](const float colorC, const float exp) {
} return floori(colorC / powf(2, exp - B - N) + 0.5f);
};
const int maxS = fnColorS(maxC, expP);
const int expS = expP + ((maxS == (1 << N)) ? 1 : 0);
const int redS = fnColorS(redC, expS);
const int greenS = fnColorS(greenC, expS);
const int blueS = fnColorS(blueC, expS);
// Pack as u32 EGBR.
uint32_t ret = expS & 0x1f;
ret <<= 9;
ret |= blueS & 0x1ff;
ret <<= 9;
ret |= greenS & 0x1ff;
ret <<= 9;
ret |= redS & 0x1ff;
return ret;
}
static void Decode(uint32_t packed,
float *const out_red,
float *const out_green,
float *const out_blue)
{
const auto redS = packed & 0x1ff;
packed >>= 9;
const auto greenS = packed & 0x1ff;
packed >>= 9;
const auto blueS = packed & 0x1ff;
packed >>= 9;
const auto expS = packed & 0x1f;
// These are *not* IEEE-like UFloat14s.
// GLES 3.0.5 p165:
// red = redS*pow(2,expS-B-N)
const auto fnToFloat = [&](const uint32_t x) { return x * powf(2, int(expS) - B - N); };
*out_red = fnToFloat(redS);
*out_green = fnToFloat(greenS);
*out_blue = fnToFloat(blueS);
}
};
} // anonymous namespace } // anonymous namespace
...@@ -212,6 +253,9 @@ uint32_t EncodeRGB9_E5_Rev(const float signedR, const float signedG, const float ...@@ -212,6 +253,9 @@ uint32_t EncodeRGB9_E5_Rev(const float signedR, const float signedG, const float
// re-encode by hand. // re-encode by hand.
TEST(TextureUploadFormatTestInternals, Float16Encoding) TEST(TextureUploadFormatTestInternals, Float16Encoding)
{ {
EXPECT_EQ(Float16::Decode(0, 0x0f, 0), 1.0f);
EXPECT_EQ(Float16::Decode(0, 0x0f - 1, 0), 0.5f);
EXPECT_EQ(Float16::Assemble(0, 0x0f, 0), Float16::Encode(1.0)); EXPECT_EQ(Float16::Assemble(0, 0x0f, 0), Float16::Encode(1.0));
EXPECT_EQ(Float16::Assemble(0, 0x0f - 1, 0), Float16::Encode(1.0 / 2)); EXPECT_EQ(Float16::Assemble(0, 0x0f - 1, 0), Float16::Encode(1.0 / 2));
...@@ -221,6 +265,20 @@ TEST(TextureUploadFormatTestInternals, Float16Encoding) ...@@ -221,6 +265,20 @@ TEST(TextureUploadFormatTestInternals, Float16Encoding)
EXPECT_EQ(Float16::Assemble(0, 0x0f - 1, 1 << (Float16::kMBits - 2)), Float16::Encode(5.0 / 8)); EXPECT_EQ(Float16::Assemble(0, 0x0f - 1, 1 << (Float16::kMBits - 2)), Float16::Encode(5.0 / 8));
} }
// Ensure our RGB9_E5 encoding is reasonable, at least for our testcase.
TEST(TextureUploadFormatTestInternals, RGB9E5Encoding)
{
const auto fnTest = [](const float refR, const float refG, const float refB) {
const auto packed = RGB9_E5::Encode(refR, refG, refB);
float testR, testG, testB;
RGB9_E5::Decode(packed, &testR, &testG, &testB);
EXPECT_EQ(testR, refR);
EXPECT_EQ(testG, refG);
EXPECT_EQ(testB, refB);
};
fnTest(0.125f, 0.250f, 0.625f);
}
namespace namespace
{ {
...@@ -247,13 +305,12 @@ TEST_P(TextureUploadFormatTest, All) ...@@ -247,13 +305,12 @@ TEST_P(TextureUploadFormatTest, All)
{ {
ANGLE_SKIP_TEST_IF(IsD3D9() || IsD3D11_FL93()); ANGLE_SKIP_TEST_IF(IsD3D9() || IsD3D11_FL93());
constexpr char kVertShader[] = R"( constexpr char kVertShaderES2[] = R"(
void main() void main()
{ {
gl_PointSize = 1.0; gl_PointSize = 1.0;
gl_Position = vec4(0, 0, 0, 1); gl_Position = vec4(0, 0, 0, 1);
})"; })";
constexpr char kFragShader_Floats[] = R"( constexpr char kFragShader_Floats[] = R"(
precision mediump float; precision mediump float;
uniform sampler2D uTex; uniform sampler2D uTex;
...@@ -262,26 +319,7 @@ TEST_P(TextureUploadFormatTest, All) ...@@ -262,26 +319,7 @@ TEST_P(TextureUploadFormatTest, All)
{ {
gl_FragColor = texture2D(uTex, vec2(0,0)); gl_FragColor = texture2D(uTex, vec2(0,0));
})"; })";
constexpr char kFragShader_Ints[] = R"( ANGLE_GL_PROGRAM(floatsProg, kVertShaderES2, kFragShader_Floats);
precision mediump float;
uniform sampler2D uTex;
void main()
{
gl_FragColor = texture2D(uTex, vec2(0,0)) / 8.0;
})";
ANGLE_GL_PROGRAM(floatsProg, kVertShader, kFragShader_Floats);
ANGLE_GL_PROGRAM(intsProg, kVertShader, kFragShader_Ints);
GLint uTex = glGetUniformLocation(floatsProg, "uTex");
ASSERT_NE(uTex, -1);
glUseProgram(floatsProg);
glUniform1i(uTex, 0);
uTex = glGetUniformLocation(intsProg, "uTex");
ASSERT_NE(uTex, -1);
glUseProgram(intsProg);
glUniform1i(uTex, 0);
glDisable(GL_DITHER); glDisable(GL_DITHER);
...@@ -306,6 +344,9 @@ TEST_P(TextureUploadFormatTest, All) ...@@ -306,6 +344,9 @@ TEST_P(TextureUploadFormatTest, All)
GLTexture testTex; GLTexture testTex;
glBindTexture(GL_TEXTURE_2D, testTex); glBindTexture(GL_TEXTURE_2D, testTex);
// Must be nearest because some texture formats aren't filterable!
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
ASSERT_GL_NO_ERROR(); ASSERT_GL_NO_ERROR();
...@@ -330,7 +371,7 @@ TEST_P(TextureUploadFormatTest, All) ...@@ -330,7 +371,7 @@ TEST_P(TextureUploadFormatTest, All)
glTexImage2D(GL_TEXTURE_2D, 0, format.internalFormat, 1, 1, 0, format.unpackFormat, glTexImage2D(GL_TEXTURE_2D, 0, format.internalFormat, 1, 1, 0, format.unpackFormat,
format.unpackType, data); format.unpackType, data);
const auto uploadErr = glGetError(); const auto uploadErr = glGetError();
if (uploadErr) if (uploadErr) // Format might not be supported. (e.g. on ES2)
return; return;
glClearColor(1, 0, 1, 1); glClearColor(1, 0, 1, 1);
...@@ -533,6 +574,36 @@ TEST_P(TextureUploadFormatTest, All) ...@@ -533,6 +574,36 @@ TEST_P(TextureUploadFormatTest, All)
fnTest({GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, {1, 0, 0, 0}); fnTest({GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, {1, 0, 0, 0});
} }
if (getClientMajorVersion() < 3)
return;
constexpr char kVertShaderES3[] = R"(#version 300 es
void main()
{
gl_PointSize = 1.0;
gl_Position = vec4(0, 0, 0, 1);
})";
constexpr char kFragShader_Ints[] = R"(#version 300 es
precision mediump float;
uniform highp isampler2D uTex;
out vec4 oFragColor;
void main()
{
oFragColor = vec4(texture(uTex, vec2(0,0))) / 8.0;
})";
constexpr char kFragShader_Uints[] = R"(#version 300 es
precision mediump float;
uniform highp usampler2D uTex;
out vec4 oFragColor;
void main()
{
oFragColor = vec4(texture(uTex, vec2(0,0))) / 8.0;
})";
ANGLE_GL_PROGRAM(intsProg, kVertShaderES3, kFragShader_Ints);
ANGLE_GL_PROGRAM(uintsProg, kVertShaderES3, kFragShader_Uints);
// Non-normalized ints // Non-normalized ints
glUseProgram(intsProg); glUseProgram(intsProg);
...@@ -541,11 +612,6 @@ TEST_P(TextureUploadFormatTest, All) ...@@ -541,11 +612,6 @@ TEST_P(TextureUploadFormatTest, All)
constexpr uint8_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]}; constexpr uint8_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
ZeroAndCopy(srcBuffer, src); ZeroAndCopy(srcBuffer, src);
fnTest({GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE}, {1, 1, 1, 1});
fnTest({GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE}, {1, 1, 1, 1});
fnTest({GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE}, {1, 1, 1, 1});
fnTest({GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE}, {1, 1, 1, 1});
fnTest({GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE}, {1, 1, 1, 1}); fnTest({GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE}, {1, 1, 1, 1});
fnTest({GL_RGB8I, GL_RGB_INTEGER, GL_BYTE}, {1, 1, 1, 1}); fnTest({GL_RGB8I, GL_RGB_INTEGER, GL_BYTE}, {1, 1, 1, 1});
fnTest({GL_RG8I, GL_RG_INTEGER, GL_BYTE}, {1, 1, 1, 1}); fnTest({GL_RG8I, GL_RG_INTEGER, GL_BYTE}, {1, 1, 1, 1});
...@@ -557,11 +623,6 @@ TEST_P(TextureUploadFormatTest, All) ...@@ -557,11 +623,6 @@ TEST_P(TextureUploadFormatTest, All)
constexpr uint16_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]}; constexpr uint16_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
ZeroAndCopy(srcBuffer, src); ZeroAndCopy(srcBuffer, src);
fnTest({GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT}, {1, 1, 1, 1});
fnTest({GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT}, {1, 1, 1, 1});
fnTest({GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT}, {1, 1, 1, 1});
fnTest({GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT}, {1, 1, 1, 1});
fnTest({GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT}, {1, 1, 1, 1}); fnTest({GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT}, {1, 1, 1, 1});
fnTest({GL_RGB16I, GL_RGB_INTEGER, GL_SHORT}, {1, 1, 1, 1}); fnTest({GL_RGB16I, GL_RGB_INTEGER, GL_SHORT}, {1, 1, 1, 1});
fnTest({GL_RG16I, GL_RG_INTEGER, GL_SHORT}, {1, 1, 1, 1}); fnTest({GL_RG16I, GL_RG_INTEGER, GL_SHORT}, {1, 1, 1, 1});
...@@ -573,17 +634,48 @@ TEST_P(TextureUploadFormatTest, All) ...@@ -573,17 +634,48 @@ TEST_P(TextureUploadFormatTest, All)
constexpr uint32_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]}; constexpr uint32_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
ZeroAndCopy(srcBuffer, src); ZeroAndCopy(srcBuffer, src);
fnTest({GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT}, {1, 1, 1, 1});
fnTest({GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT}, {1, 1, 1, 1});
fnTest({GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT}, {1, 1, 1, 1});
fnTest({GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT}, {1, 1, 1, 1});
fnTest({GL_RGBA32I, GL_RGBA_INTEGER, GL_INT}, {1, 1, 1, 1}); fnTest({GL_RGBA32I, GL_RGBA_INTEGER, GL_INT}, {1, 1, 1, 1});
fnTest({GL_RGB32I, GL_RGB_INTEGER, GL_INT}, {1, 1, 1, 1}); fnTest({GL_RGB32I, GL_RGB_INTEGER, GL_INT}, {1, 1, 1, 1});
fnTest({GL_RG32I, GL_RG_INTEGER, GL_INT}, {1, 1, 1, 1}); fnTest({GL_RG32I, GL_RG_INTEGER, GL_INT}, {1, 1, 1, 1});
fnTest({GL_R32I, GL_RED_INTEGER, GL_INT}, {1, 1, 1, 1}); fnTest({GL_R32I, GL_RED_INTEGER, GL_INT}, {1, 1, 1, 1});
} }
// Non-normalized uints
glUseProgram(uintsProg);
// RGBA_INTEGER+UNSIGNED_BYTE
{
constexpr uint8_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
ZeroAndCopy(srcBuffer, src);
fnTest({GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE}, {1, 1, 1, 1});
fnTest({GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE}, {1, 1, 1, 1});
fnTest({GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE}, {1, 1, 1, 1});
fnTest({GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE}, {1, 1, 1, 1});
}
// RGBA_INTEGER+UNSIGNED_SHORT
{
constexpr uint16_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
ZeroAndCopy(srcBuffer, src);
fnTest({GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT}, {1, 1, 1, 1});
fnTest({GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT}, {1, 1, 1, 1});
fnTest({GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT}, {1, 1, 1, 1});
fnTest({GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT}, {1, 1, 1, 1});
}
// RGBA_INTEGER+UNSIGNED_INT
{
constexpr uint32_t src[4] = {srcIntVals[0], srcIntVals[1], srcIntVals[2], srcIntVals[3]};
ZeroAndCopy(srcBuffer, src);
fnTest({GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT}, {1, 1, 1, 1});
fnTest({GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT}, {1, 1, 1, 1});
fnTest({GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT}, {1, 1, 1, 1});
fnTest({GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT}, {1, 1, 1, 1});
}
// RGBA_INTEGER+UNSIGNED_INT_2_10_10_10_REV // RGBA_INTEGER+UNSIGNED_INT_2_10_10_10_REV
{ {
constexpr uint32_t src[] = {static_cast<uint32_t>(srcIntVals[0] << 0) | constexpr uint32_t src[] = {static_cast<uint32_t>(srcIntVals[0] << 0) |
...@@ -654,7 +746,7 @@ TEST_P(TextureUploadFormatTest, All) ...@@ -654,7 +746,7 @@ TEST_P(TextureUploadFormatTest, All)
// UNSIGNED_INT_5_9_9_9_REV // UNSIGNED_INT_5_9_9_9_REV
{ {
const uint32_t src[] = {EncodeRGB9_E5_Rev(srcVals[0], srcVals[1], srcVals[2])}; const uint32_t src[] = {RGB9_E5::Encode(srcVals[0], srcVals[1], srcVals[2])};
ZeroAndCopy(srcBuffer, src); ZeroAndCopy(srcBuffer, src);
fnTest({GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV}, {1, 1, 1, 0}); fnTest({GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV}, {1, 1, 1, 0});
...@@ -675,8 +767,10 @@ TEST_P(TextureUploadFormatTest, All) ...@@ -675,8 +767,10 @@ TEST_P(TextureUploadFormatTest, All)
} }
ANGLE_INSTANTIATE_TEST(TextureUploadFormatTest, ANGLE_INSTANTIATE_TEST(TextureUploadFormatTest,
ES2_D3D11(), ES3_D3D11(),
ES2_D3D11_FL9_3(), ES2_D3D11_FL9_3(),
ES2_D3D9(), ES2_D3D9(),
ES2_OPENGL(), ES2_OPENGL(),
ES2_OPENGLES()); ES3_OPENGL(),
ES2_OPENGLES(),
ES3_OPENGLES());
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